-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): create tests and factories for authentication
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# authentication/factories.py | ||
import factory | ||
from .models import SupportEntityType, Support, User, UserResource, UserTask, UserTopic | ||
|
||
class SupportEntityTypeFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = SupportEntityType | ||
|
||
name = factory.Faker('word') | ||
|
||
class SupportFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Support | ||
|
||
supporter_type = factory.SubFactory(SupportEntityTypeFactory) | ||
supporter_entity = factory.Faker('random_int', min=1, max=100) | ||
supported_type = factory.SubFactory(SupportEntityTypeFactory) | ||
supported_entity = factory.Faker('random_int', min=1, max=100) | ||
|
||
class UserFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = User | ||
|
||
user_name = factory.Faker('user_name') | ||
name = factory.Faker('name') | ||
password = factory.Faker('password') | ||
location = factory.Faker('city') | ||
description = factory.Faker('text', max_nb_chars=500) | ||
verified = factory.Faker('boolean') | ||
verification_method = factory.Faker('word') | ||
verification_partner = factory.SubFactory("content.UserFactory") | ||
social_accounts = [factory.Faker('user_name') for _ in range(3)] | ||
private = factory.Faker('boolean') | ||
high_risk = factory.Faker('boolean') | ||
total_flags = factory.Faker('random_int', min=0, max=100) | ||
creation_date = factory.Faker('date_time_this_decade', before_now=True) | ||
deletion_date = factory.Faker('date_time_this_decade', before_now=False) | ||
|
||
class UserResourceFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = UserResource | ||
|
||
user_id = factory.SubFactory(UserFactory) | ||
resource_id = factory.SubFactory("content.ResourceFactory") | ||
|
||
class UserTaskFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = UserTask | ||
|
||
user_id = factory.SubFactory(UserFactory) | ||
task_id = factory.SubFactory("content.TaskFactory") | ||
|
||
class UserTopicFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = UserTopic | ||
|
||
user_id = factory.SubFactory(UserFactory) | ||
topic_id = factory.SubFactory("content.TopicFactory") |
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,18 @@ | ||
from django.test import TestCase | ||
import pytest | ||
from .factories import SupportEntityTypeFactory, SupportFactory, UserFactory, UserResourceFactory, UserTaskFactory, UserTopicFactory | ||
|
||
# Create your tests here. | ||
@pytest.mark.django_db | ||
def test_str_methods() -> None: | ||
support_entity_type = SupportEntityTypeFactory.build() | ||
support = SupportFactory.build() | ||
user = UserFactory.build() | ||
user_resource = UserResourceFactory.build() | ||
user_task = UserTaskFactory.build() | ||
user_topic = UserTopicFactory.build() | ||
|
||
assert str(support_entity_type) == support_entity_type.name | ||
assert str(support) == str(support.id) | ||
assert str(user) == user.username | ||
assert str(user_resource) == str(user_resource.id) | ||
assert str(user_task) == str(user_task.id) | ||
assert str(user_topic) == str(user_topic.id) |
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