-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create factories and tests for the entities #538
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,137 @@ | ||
import datetime | ||
import random | ||
|
||
import factory | ||
|
||
from .models import Organization, OrganizationApplication, OrganizationApplicationStatus, OrganizationEvent, OrganizationMember, OrganizationResource, Group, OrganizationTask, OrganizationTopic, GroupEvent, GroupMember, GroupResource, GroupTopic | ||
|
||
class OrganizationFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model: Organization | ||
|
||
name = factory.Faker("word") | ||
tagline = factory.Faker("word") | ||
location = factory.Faker("address") | ||
status = factory.Faker("word") | ||
description = factory.Faker("paragraph") | ||
members = factory.List([factory.Faker("name") for _ in range(10)]) | ||
supporters = factory.List([factory.Faker("name") for _ in range(10)]) | ||
images_url = factory.List([factory.Faker("word") for _ in range(10)]) | ||
topics = factory.List([factory.Faker("word") for _ in range(10)]) | ||
social_accounts = factory.List([factory.Faker("word") for _ in range(10)]) | ||
total_flags = random.randint(1, 100) | ||
created_by = factory.SubFactory("authentication.UserFactory") | ||
high_risk = random.choice([True, False]) | ||
creation_date = factory.LazyFunction(datetime.datetime.now) | ||
deletion_date = factory.LazyFunction(datetime.datetime.now) | ||
|
||
|
||
class OrganizationApplicationStatusFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationApplicationStatus | ||
|
||
status_name = factory.Faker("word") | ||
|
||
|
||
class OrganizationApplicationFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationApplication | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
status = factory.SubFactory(OrganizationApplicationStatusFactory) | ||
orgs_in_favor = factory.List([factory.Faker("word") for _ in range(10)]) # orgs_in_favor | ||
orgs_against = factory.List([factory.Faker("word") for _ in range(10)]) # orgs_against | ||
creation_date = factory.LazyFunction(datetime.datetime.now) | ||
status_update = factory.LazyFunction(datetime.datetime.now) | ||
|
||
|
||
class OrganizationEventFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationEvent | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
event_id = factory.SubFactory("events.EventFactory") | ||
|
||
|
||
class OrganizationMemberFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationMember | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
user_id = factory.SubFactory("authentication.UserFactory") | ||
is_owner = random.choice([True, False]) | ||
is_admin = random.choice([True, False]) | ||
is_comms = random.choice([True, False]) | ||
|
||
|
||
class OrganizationResourceFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationResource | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
resource_id = factory.SubFactory("content.ResourceFactory") | ||
|
||
|
||
class GroupFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Group | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
name = factory.Faker("word") | ||
tagline = factory.Faker("word") | ||
description = factory.Faker("paragraph") | ||
social_accounts = factory.List([factory.Faker("word") for _ in range(10)]) | ||
total_flags = random.randint(1, 100) | ||
creation_by = factory.SubFactory("authentication.UserFactory") | ||
creation_date = factory.LazyFunction(datetime.datetime.now) | ||
deletion_date = factory.LazyFunction(datetime.datetime.now) | ||
|
||
|
||
class OrganizationTaskFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationTask | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
task_id = factory.SubFactory("content.TaskFactory") | ||
group_id = factory.SubFactory(GroupFactory) | ||
|
||
|
||
class OrganizationTopicFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = OrganizationTopic | ||
|
||
org_id = factory.SubFactory(OrganizationFactory) | ||
topic_id = factory.SubFactory("content.TopicFactory") | ||
|
||
|
||
class GroupEventFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GroupEvent | ||
|
||
group_id = factory.SubFactory(GroupFactory) | ||
event_id = factory.SubFactory("events.EventFactory") | ||
|
||
|
||
class GroupMemberFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GroupMember | ||
|
||
group_id = factory.SubFactory(GroupFactory) | ||
user_id = factory.SubFactory("authentication.UserFactory") | ||
is_admin = random.choice([True, False]) | ||
|
||
|
||
class GroupResourceFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GroupResource | ||
|
||
group_id = factory.SubFactory(GroupFactory) | ||
resource_id = factory.SubFactory("content.ResourceFactory") | ||
|
||
|
||
class GroupTopicFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GroupTopic | ||
|
||
group_id = factory.SubFactory(GroupFactory) | ||
topic_id = factory.SubFactory("content.Topic") |
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,33 @@ | ||
from django.test import TestCase | ||
from .factory import OrganizationFactory, OrganizationApplicationFactory, OrganizationApplicationStatusFactory, OrganizationEventFactory, OrganizationMemberFactory, OrganizationResourceFactory, GroupFactory, OrganizationTaskFactory, OrganizationTopicFactory, GroupEventFactory, GroupMemberFactory, GroupResourceFactory, GroupTopic | ||
import pytest | ||
|
||
# Create your tests here. | ||
@pytest.mark.django_db | ||
def test_str_methods() -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you use the |
||
organization = OrganizationFactory.build() | ||
organization_application = OrganizationApplicationFactory.build() | ||
organization_application_status = OrganizationApplicationStatusFactory.build() | ||
organization_event = OrganizationEventFactory.build() | ||
organization_member = OrganizationMemberFactory.build() | ||
organization_resource = OrganizationResourceFactory.build() | ||
organization_task = OrganizationTaskFactory.build() | ||
organization_topic = OrganizationTopicFactory.build() | ||
group = GroupFactory.build() | ||
group_event = GroupEventFactory.build() | ||
group_member = GroupMemberFactory.build() | ||
group_resource = GroupResourceFactory.build() | ||
group_topic = GroupTopic.build() | ||
|
||
assert str(organization) == organization.name | ||
assert str(organization_application) == str(organization_application.id) | ||
assert str(organization_application_status) == str(organization_application_status.id) | ||
assert str(organization_event) == str(organization_event.id) | ||
assert str(organization_member) == str(organization_member.id) | ||
assert str(organization_resource) == str(organization_resource.id) | ||
assert str(organization_task) == str(organization_task.id) | ||
assert str(organization_topic) == str(organization_topic.id) | ||
assert str(group) == group.name | ||
assert str(group_event) == str(group_event.id) | ||
assert str(group_member) == str(group_member.id) | ||
assert str(group_resource) == str(group_resource.id) | ||
assert str(group_topic) == str(group_topic.id) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcosquadross saw a typo here, model should be assigned to Organization. Generally I would recommand you to test your implementation. When you run pytest, you would see that it fails.
You can also use the django shell (
python manage.py shell
) to test your factories.