Skip to content

Commit

Permalink
Update factory-boy
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Alvin Villar committed Aug 7, 2017
1 parent 00d3f16 commit 216fbfa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 11 additions & 4 deletions cadasta/accounts/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 4 additions & 8 deletions cadasta/resources/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 216fbfa

Please sign in to comment.