-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76fa803
commit 718214b
Showing
24 changed files
with
586 additions
and
54 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ config.json | |
.env | ||
.envrc | ||
.venv/ | ||
.pdm-python | ||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
Release 1.7 | ||
----------- | ||
* removed UNICEFAzureADB2COAuth2 | ||
|
||
|
||
Release 1.6.3 | ||
------------- | ||
* admin tweaks for users | ||
|
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 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,37 @@ | ||
import importlib | ||
import pkgutil | ||
from pathlib import Path | ||
|
||
from pytest_factoryboy import register | ||
|
||
from factory.django import DjangoModelFactory | ||
|
||
from .base import AutoRegisterModelFactory, factories_registry, TAutoRegisterModelFactory | ||
from .social import SocialAuthUserFactory # noqa | ||
from .user import GroupFactory, SuperUserFactory, 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,23 @@ | ||
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,13 @@ | ||
from django.contrib.auth.models import Permission | ||
|
||
import factory | ||
|
||
from .base import AutoRegisterModelFactory | ||
from .contenttypes import ContentTypeFactory | ||
|
||
|
||
class PermissionFactory(AutoRegisterModelFactory): | ||
content_type = factory.SubFactory(ContentTypeFactory) | ||
|
||
class Meta: | ||
model = Permission |
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,11 @@ | ||
from django.contrib.admin.models import LogEntry | ||
|
||
from .base import AutoRegisterModelFactory | ||
|
||
|
||
class LogEntryFactory(AutoRegisterModelFactory): | ||
level = "INFO" | ||
message = "Message for {{ event.name }} on channel {{channel.name}}" | ||
|
||
class Meta: | ||
model = LogEntry |
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,13 @@ | ||
from uuid import uuid4 | ||
|
||
from social_django.models import UserSocialAuth | ||
|
||
import factory | ||
|
||
from .user import UserFactory | ||
|
||
|
||
class SocialAuthUserFactory(UserFactory): | ||
@factory.post_generation | ||
def sso(obj, create, extracted, **kwargs): | ||
UserSocialAuth.objects.get_or_create(user=obj, provider="test", uid=uuid4()) |
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,62 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Group | ||
from django.db.models import signals | ||
|
||
import factory.fuzzy | ||
|
||
from .base import AutoRegisterModelFactory | ||
|
||
|
||
@factory.django.mute_signals(signals.post_save) | ||
class UserFactory(AutoRegisterModelFactory): | ||
_password = "password" | ||
username = factory.Sequence(lambda n: "m%[email protected]" % n) | ||
password = factory.django.Password(_password) | ||
email = factory.Sequence(lambda n: "m%[email protected]" % n) | ||
last_name = factory.Faker("last_name") | ||
first_name = factory.Faker("first_name") | ||
is_superuser = False | ||
is_active = True | ||
|
||
class Meta: | ||
model = get_user_model() | ||
django_get_or_create = ("username",) | ||
|
||
@classmethod | ||
def _create(cls, model_class, *args, **kwargs): | ||
ret = super()._create(model_class, *args, **kwargs) | ||
ret._password = cls._password | ||
return ret | ||
|
||
|
||
class AdminFactory(UserFactory): | ||
is_superuser = True | ||
|
||
|
||
class AnonUserFactory(UserFactory): | ||
username = "anonymous" | ||
|
||
|
||
class SuperUserFactory(UserFactory): | ||
username = factory.Sequence(lambda n: "superuser%[email protected]" % n) | ||
email = factory.Sequence(lambda n: "superuser%[email protected]" % n) | ||
is_superuser = True | ||
is_staff = True | ||
is_active = True | ||
|
||
|
||
class GroupFactory(factory.django.DjangoModelFactory): | ||
name = factory.Sequence(lambda n: "name%03d" % n) | ||
|
||
@factory.post_generation | ||
def permissions(self, create, extracted, **kwargs): | ||
if not create: | ||
return # Simple build, do nothing. | ||
|
||
if extracted: | ||
for permission in extracted: # A list of groups were passed in, use them | ||
self.permissions.add(permission) | ||
|
||
class Meta: | ||
model = Group | ||
django_get_or_create = ("name",) |
Oops, something went wrong.