Skip to content

Automatically drop models from config. #6

@adriaanwm

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('_')])

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