Skip to content

Automatically drop models from config. #6

Description

@adriaanwm

Instead of manually adding each model used in tests in the tests/init.py file, drop collections from config list.

eg.


class BaseTestCase(TestCase):
    ...

    def tearDown(self):
        self.__teardown_models()

    def __teardown_models(self):
        for model in config.MODELS:
            module = importlib.import_module(
                'app.models.{0}'.format(model)
            )
            try:
                getattr(module, to_camel_case(model)).drop_collection()
            except AttributeError:  # EmbeddedDocuments don't have drop_collection
                pass


def to_camel_case(snake):
    return ''.join([x.title() for x in snake.split('_')])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions