-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅(dashboard) update tests with factory boy
- Add factory-boy to Pipfile - add factories for apps: auth, content, core - Update tests with new factories
- Loading branch information
Showing
8 changed files
with
157 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Dashboard auth factories.""" | ||
|
||
import factory | ||
from django.contrib.auth import get_user_model | ||
|
||
|
||
class UserFactory(factory.django.DjangoModelFactory): | ||
"""Factory class for creating a “standard” user.""" | ||
|
||
username = factory.Faker("user_name") | ||
password = factory.django.Password("foo") | ||
|
||
class Meta: # noqa: D106 | ||
model = get_user_model() | ||
|
||
|
||
class AdminUserFactory(UserFactory): | ||
"""Factory class for creating a superuser.""" | ||
|
||
@classmethod | ||
def _create(cls, model_class, *args, **kwargs): | ||
"""Override the default ``_create`` with ``create_superuser``.""" | ||
manager = cls._get_manager(model_class) | ||
# The default would use ``manager.create(*args, **kwargs)`` | ||
return manager.create_superuser(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Dashboard consent factories.""" | ||
|
||
from datetime import timedelta | ||
|
||
import factory | ||
from django.utils import timezone | ||
from factory import fuzzy | ||
|
||
from apps.auth.factories import UserFactory | ||
from apps.core.factories import DeliveryPointFactory | ||
|
||
from .models import Consent | ||
|
||
|
||
class ConsentFactory(factory.django.DjangoModelFactory): | ||
"""Factory class for creating instances of the Consent model.""" | ||
|
||
delivery_point = factory.SubFactory(DeliveryPointFactory) | ||
created_by = factory.SubFactory(UserFactory) | ||
start = fuzzy.FuzzyDateTime(timezone.now()) | ||
end = factory.LazyAttribute(lambda o: o.start + timedelta(days=90)) | ||
|
||
class Meta: # noqa: D106 | ||
model = Consent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Dashboard core factories.""" | ||
|
||
import factory | ||
|
||
from .models import DeliveryPoint, Entity | ||
|
||
|
||
class EntityFactory(factory.django.DjangoModelFactory): | ||
"""Factory class for creating instances of the Entity model.""" | ||
|
||
name = factory.Faker("company") | ||
|
||
class Meta: # noqa: D106 | ||
model = Entity | ||
|
||
@factory.post_generation | ||
def users(self, create, extracted, **kwargs): | ||
"""Method to add users after the entity is created.""" | ||
if not create or not extracted: | ||
# Simple build, or nothing to add, do nothing. | ||
return | ||
|
||
# Add the iterable of groups using bulk addition | ||
self.users.add(*extracted) | ||
|
||
|
||
class DeliveryPointFactory(factory.django.DjangoModelFactory): | ||
"""Factory class for creating instances of the DeliveryPoint model.""" | ||
|
||
class Meta: # noqa: D106 | ||
model = DeliveryPoint | ||
|
||
provider_id = factory.Sequence(lambda n: "provider_%d" % n) | ||
|
||
@factory.post_generation | ||
def entities(self, create, extracted, **kwargs): | ||
"""Method to add entities after the delivery point is created.""" | ||
if not create or not extracted: | ||
# Simple build, or nothing to add, do nothing. | ||
return | ||
|
||
# Add the iterable of groups using bulk addition | ||
self.entities.add(*extracted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters