From 216fbfa6f8dbb386de757f58c2b42ca75447743a Mon Sep 17 00:00:00 2001 From: Eugene Alvin Villar Date: Mon, 7 Aug 2017 20:52:10 +0800 Subject: [PATCH] Update factory-boy --- cadasta/accounts/tests/factories.py | 15 +++++++++++---- cadasta/resources/tests/factories.py | 12 ++++-------- requirements/dev.txt | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cadasta/accounts/tests/factories.py b/cadasta/accounts/tests/factories.py index 652513c83..80bf5cd03 100644 --- a/cadasta/accounts/tests/factories.py +++ b/cadasta/accounts/tests/factories.py @@ -13,11 +13,18 @@ class Meta: password = '' @classmethod - def _prepare(cls, create, **kwargs): + def _build(cls, model_class, *args, **kwargs): password = kwargs.pop('password', None) - user = super(UserFactory, cls)._prepare(create, **kwargs) + user = super()._build(model_class, *args, **kwargs) if password: user.set_password(password) - if create: - user.save() + return user + + @classmethod + def _create(cls, model_class, *args, **kwargs): + password = kwargs.pop('password', None) + user = super()._create(model_class, *args, **kwargs) + if password: + user.set_password(password) + user.save() return user diff --git a/cadasta/resources/tests/factories.py b/cadasta/resources/tests/factories.py index 913373e86..2c119ea21 100644 --- a/cadasta/resources/tests/factories.py +++ b/cadasta/resources/tests/factories.py @@ -25,20 +25,16 @@ class Meta: project = factory.SubFactory(ProjectFactory) @classmethod - def _prepare(cls, create, **kwargs): - resource = super()._prepare(create, **kwargs) - - if not resource.file.url: + def _after_postgeneration(cls, obj, create, results=None): + if not obj.file.url: storage = FakeS3Storage() file = open(path + '/resources/tests/files/image.jpg', 'rb') file_name = storage.save('resources/image.jpg', file.read()) file.close() - resource.file = file_name + obj.file = file_name if create: - resource.save() - - return resource + obj.save() class SpatialResourceFactory(ExtendedFactory): diff --git a/requirements/dev.txt b/requirements/dev.txt index 5ee5b6346..df8d98832 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,6 +1,6 @@ -r common.txt pytest-django==3.1.2 -factory_boy==2.8.1 +factory-boy==2.9.2 pytest-cov==2.5.1 selenium==3.4.3 transifex-client==0.12.4