-
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.
Merge pull request #90 from unicef/test-admin-smoke
Test admin smoke
- Loading branch information
Showing
16 changed files
with
571 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
Key: {obj.key} | ||
Grants: {obj.grants} | ||
Expires: {expire} | ||
Business Areas: {areas} | ||
Regards | ||
|
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
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
This file was deleted.
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,33 @@ | ||
import importlib | ||
import pkgutil | ||
from pathlib import Path | ||
|
||
from factory.django import DjangoModelFactory | ||
from pytest_factoryboy import register | ||
|
||
from .base import AutoRegisterModelFactory, TAutoRegisterModelFactory, factories_registry | ||
from .payment import * # noqa | ||
from .social import SocialAuthUserFactory # noqa | ||
from .user import GroupFactory, SuperUserFactory, SystemFactory, User, UserFactory # noqa | ||
|
||
for _, name, _ in pkgutil.iter_modules([str(Path(__file__).parent)]): | ||
importlib.import_module(f".{name}", __package__) | ||
|
||
|
||
django_model_factories = {factory._meta.model: factory for factory in DjangoModelFactory.__subclasses__()} | ||
|
||
|
||
def get_factory_for_model( | ||
_model, | ||
) -> type[TAutoRegisterModelFactory] | type[DjangoModelFactory]: | ||
class Meta: | ||
model = _model | ||
|
||
bases = (AutoRegisterModelFactory,) | ||
if _model in factories_registry: | ||
return factories_registry[_model] # noqa | ||
|
||
if _model in django_model_factories: | ||
return django_model_factories[_model] | ||
|
||
return register(type(f"{_model._meta.model_name}AutoCreatedFactory", bases, {"Meta": Meta})) # noqa |
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,19 @@ | ||
import typing | ||
|
||
import factory | ||
from factory.base import FactoryMetaClass | ||
|
||
TAutoRegisterModelFactory = typing.TypeVar("TAutoRegisterModelFactory", bound="AutoRegisterModelFactory") | ||
|
||
factories_registry: dict[str, TAutoRegisterModelFactory] = {} | ||
|
||
|
||
class AutoRegisterFactoryMetaClass(FactoryMetaClass): | ||
def __new__(mcs, class_name, bases, attrs): | ||
new_class = super().__new__(mcs, class_name, bases, attrs) | ||
factories_registry[new_class._meta.model] = new_class | ||
return new_class | ||
|
||
|
||
class AutoRegisterModelFactory(factory.django.DjangoModelFactory, metaclass=AutoRegisterFactoryMetaClass): | ||
pass |
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,12 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from .base import AutoRegisterModelFactory | ||
|
||
|
||
class ContentTypeFactory(AutoRegisterModelFactory): | ||
app_label = "auth" | ||
model = "user" | ||
|
||
class Meta: | ||
model = ContentType | ||
django_get_or_create = ("app_label", "model") |
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,32 @@ | ||
from django.contrib.auth.models import Group, Permission | ||
|
||
import factory | ||
|
||
from .base import AutoRegisterModelFactory | ||
from .contenttypes import ContentTypeFactory | ||
|
||
|
||
class PermissionFactory(AutoRegisterModelFactory): | ||
content_type = factory.SubFactory(ContentTypeFactory) | ||
|
||
class Meta: | ||
model = Permission | ||
|
||
|
||
# class GroupFactory(AutoRegisterModelFactory): | ||
# name = factory.Sequence(lambda n: "group %s" % n) | ||
# | ||
# class Meta: | ||
# model = Group | ||
# django_get_or_create = ("name",) | ||
# | ||
# @factory.post_generation | ||
# def permissions(self, create, extracted, **kwargs): | ||
# if not create: | ||
# # Simple build, do nothing. | ||
# return | ||
# | ||
# if extracted: | ||
# # A list of groups were passed in, use them | ||
# for perm in extracted: | ||
# self.permissions.add(perm) |
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,31 @@ | ||
from django.utils import timezone | ||
|
||
from django_celery_beat.models import SOLAR_SCHEDULES, ClockedSchedule, IntervalSchedule, SolarSchedule | ||
from factory.fuzzy import FuzzyChoice | ||
|
||
from .base import AutoRegisterModelFactory | ||
|
||
|
||
class IntervalScheduleFactory(AutoRegisterModelFactory): | ||
every = 1 | ||
period = IntervalSchedule.HOURS | ||
|
||
class Meta: | ||
model = IntervalSchedule | ||
|
||
|
||
class SolarScheduleFactory(AutoRegisterModelFactory): | ||
event = FuzzyChoice([x[0] for x in SOLAR_SCHEDULES]) | ||
|
||
latitude = 10.1 | ||
longitude = 10.1 | ||
|
||
class Meta: | ||
model = SolarSchedule | ||
|
||
|
||
class ClockedScheduleFactory(AutoRegisterModelFactory): | ||
clocked_time = timezone.now() | ||
|
||
class Meta: | ||
model = ClockedSchedule |
Oops, something went wrong.