Contribute — fantastico 0.1.1-b87 documentation

### Navigation

- index
- next |
- previous |
- fantastico 0.1.1-b87 documentation »
- Getting started »

# Contribute

Fantastico framework is open source so every contribution is welcome. For the moment we are looking for more developers willing to contribute.

## Code contribution

If you want to contribute with code to fantastico framework there are a simple set of rules that you must follow:

> - Write unit tests (for the code / feature you are contributing).
> - Write integration tests (for the code / feature you are contributing).
> - Make sure your code is rated above 9.5 by pylint tool.
> - In addition integration tests and unit tests must cover 95% of your code.

In order for each build to remain stable the following hard limits are imposed:

> 1. Unit tests must cover >= 95% of the code.
> 2. Integration tests must cover >= 95% of the code.
> 3. Code must be rated above 9.5 by pylint.
> 4. Everything must pass.

When you push on master a set of jobs are cascaded executed:

> 1. Run all unit tests job.
> 2. Run all integration tests job (only if unit tests succeeds).
> 3. Generate documentation and publish it (only if integration tests job succeeds).

You can follow the above build process by visiting Jenkins build. Login with your github account and everything should work smoothly.

In the end do not forget that in Fantastico framework we love to develop against a stable base. We really think code will have high quality and zero bugs.

### Writing unit tests

For better understanding how to write unit tests see the documentation below:

class `fantastico.tests.base_case.` `FantasticoUnitTestsCase`(methodName='runTest')

  This is the base class that must be inherited by each unit test written for fantastico.

      class SimpleUnitTest(FantasticoUnitTestsCase):
          def init(self):
              self._msg = "Hello world"

          def test_simple_flow_ok(self):
              self.assertEqual("Hello world", self._msg)

  `_get_class_root_folder`()

    This methods determines the root folder under which the test is executed.

  `_get_root_folder`()

    This method determines the root folder under which core is executed.

  classmethod `setup_once`()

    This method is overriden in order to correctly mock some dependencies:

    - `fantastico.mvc.controller_decorators.Controller`

### Writing integration tests

For better understanding how to write integration tests see the documentation below:

class `fantastico.tests.base_case.` `FantasticoIntegrationTestCase`(methodName='runTest')

  This is the base class that must be inherited by each integration test written for fantastico.

      class SimpleIntegration(FantasticoIntegrationTestCase):
          def init(self):
              self.simple_class = {}

          def cleanup(self):
              self.simple_class = None

          def test_simple_ok(self):
              def do_stuff(env, env_cls):
                  self.assertEqual(simple_class[env], env_cls)

              self._run_test_all_envs(do_stuff)

  If you used this class you don’t have to mind about restoring call methods from each middleware once they are wrapped by fantastico app. This is a must because otherwise you will crash other tests.

  `_envs`

    Private property that holds the environments against which we run the integration tests.

  `_restore_call_methods`()

    This method restore original call methods to all affected middlewares.

  `_run_test_all_envs`(callable_obj)

    This method is used to execute a callable block of code on all environments. This is extremely useful for avoid boiler plate code duplication and executing test logic against all environments.

  `_save_call_methods`(middlewares)

    This method save all call methods for each listed middleware so that later on they can be restored.

  `fantastico_cfg_os_key`

    This property holds the name of os environment variable used for setting up active fantastico configuration.

class `fantastico.server.tests.itest_dev_server.` `DevServerIntegration`(methodName='runTest')

  This class provides the foundation for writing integration tests that do http requests against a fantastico server.

      class DummyLoaderIntegration(DevServerIntegration):
          def init(self):
              self._exception = None

          def test_server_runs_ok(self):
              def request_logic(server):
                  request = Request(self._get_server_base_url(server, DummyRouteLoader.DUMMY_ROUTE))
                  with self.assertRaises(HTTPError) as cm:
                      urllib.request.urlopen(request)

                  self._exception = cm.exception

              def assert_logic(server):
                  self.assertEqual(400, self._exception.code)
                  self.assertEqual("Hello world.", self._exception.read().decode())

              self._run_test_all_envs(lambda env, settings_cls: self._run_test_against_dev_server(request_logic, assert_logic))

              # you can also pass only request logic without assert logic
              # self._run_test_all_envs(lambda env, settings_cls: self._run_test_against_dev_server(request_logic))

  As you can see from above listed code, when you write a new integration test against Fantastico server you only need to provide the request logic and assert logic functions. Request logic is executed while the server is up and running. Assert logic is executed after the server has stopped.

  `_check_server_started`(server)

    This method holds the sanity checks to ensure a server is started correctly.

  `_get_server_base_url`(server, route)

    This method returns the absolute url for a given relative url (route).

  `_run_test_against_dev_server`(request_logic, assert_logic=None)

    This method provides a template for writing integration tests that requires a development server being active. It accepts a request logic (code that actually do the http request) and an assert logic for making sure code is correct.

### Navigation

- index
- next |
- previous |
- fantastico 0.1.1-b87 documentation »
- Getting started »