-
Notifications
You must be signed in to change notification settings - Fork 351
Added a factory file for the Category Model #1496
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
Changes from all commits
0f02e6f
017a49c
b1d54c0
40a43d1
6630449
a2b5eeb
762f44a
1345209
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import factory | ||
| import factory.fuzzy | ||
| from django.contrib.auth.models import User | ||
|
|
||
| from .modes import Profile | ||
|
|
||
|
|
||
| class UserFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = User | ||
|
|
||
| username = factory.Faker("sentence", nb_words=20) | ||
|
|
||
|
|
||
| class ProfileFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Profile | ||
|
|
||
| user = factory.SubFactory("app.factories.UserFactory") | ||
| first_name = factory.Faker("lorem") | ||
| last_name = factory.Faker("lorem") | ||
| about_me = factory.Faker("lorem") | ||
| is_verified = factory.fuzzy.FuzzyChoice(choices=[True, False]) | ||
| profile_image = factory.Faker("image_url") | ||
| profile_image_thumb = factory.Faker("image_url") | ||
|
|
||
| @factory.post_generation | ||
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def categories(self, create, extracted, **kwargs): | ||
| if not create: | ||
| return | ||
| if extracted: | ||
| for category in extracted: | ||
| self.categories.add(category) | ||
|
|
||
| @factory.post_generation | ||
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
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. Similar blocks of code found in 6 locations. Consider refactoring.
brylie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def tags(self, create, extracted, **kwargs): | ||
| if not create: | ||
| return | ||
| if extracted: | ||
| for tag in extracted: | ||
| self.tags.add(tag) | ||
|
|
||
| @factory.post_generation | ||
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
brylie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def following(self, create, extracted, **kwargs): | ||
| if not create: | ||
| return | ||
| if extracted: | ||
| for follower in extracted: | ||
| self.following.add(follower) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import factory | ||
|
|
||
| from .models import Category | ||
|
|
||
|
|
||
| class CategoryFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Category | ||
|
|
||
| name = factory.Faker("lorem") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import factory | ||
| import factory.fuzzy | ||
| from account.factory import ProfileFactory | ||
| from threads.factory import CiviFactory, ThreadFactory | ||
|
|
||
| from .models import Notification | ||
|
|
||
|
|
||
| class NotificationFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Notification | ||
|
|
||
| account = factory.SubFactory(ProfileFactory) | ||
| thread = factory.SubFactory(ThreadFactory) | ||
| civi = factory.SubFactory(CiviFactory) | ||
| activity_type = factory.Faker("lorem") | ||
| read = factory.fuzzy.FuzzyChoice(choices=[True, False]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import factory | ||
| import factory.fuzzy | ||
| from categories.factory import CategoryFactory | ||
| from django.contrib.auth.models import User | ||
|
|
||
| from .models import ( | ||
| Activity, | ||
| Civi, | ||
| CiviImage, | ||
| Fact, | ||
| Rationale, | ||
| Rebuttal, | ||
| Response, | ||
| Thread, | ||
| ) | ||
|
|
||
|
|
||
| class FactFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Fact | ||
|
|
||
| body = factory.Faker("lorem") | ||
|
|
||
|
|
||
| class ThreadFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Thread | ||
|
|
||
| author = User.objects.get_or_create(username="admin") | ||
| category = factory.SubFactory(CategoryFactory) | ||
| title = factory.Faker("lorem") | ||
| summary = factory.Faker("lorem") | ||
| image = factory.Faker("image_url") | ||
| is_draft = factory.fuzzy.FuzzyChoice(choices=[True, False]) | ||
| num_views = 0 | ||
| num_civis = 0 | ||
| num_solutions = 0 | ||
|
|
||
| @factory.post_generation | ||
|
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. Similar blocks of code found in 9 locations. Consider refactoring. 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. Similar blocks of code found in 5 locations. Consider refactoring. 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. Similar blocks of code found in 6 locations. Consider refactoring. 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. Similar blocks of code found in 4 locations. Consider refactoring. 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. Similar blocks of code found in 2 locations. Consider refactoring. |
||
| def facts(self, create, extracted, **kwargs): | ||
| if not create: | ||
| return | ||
| if extracted: | ||
| for fact in extracted: | ||
| self.facts.add(fact) | ||
|
|
||
| @factory.post_generation | ||
|
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. Similar blocks of code found in 9 locations. Consider refactoring. 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. Similar blocks of code found in 6 locations. Consider refactoring. |
||
| def tags(self, create, extracted, **kwargs): | ||
brylie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not create: | ||
| return | ||
| if extracted: | ||
| for tag in extracted: | ||
| self.tags.add(tag) | ||
|
|
||
| @factory.post_generation | ||
|
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. Similar blocks of code found in 9 locations. Consider refactoring. 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. Similar blocks of code found in 6 locations. Consider refactoring. |
||
| def objects(self, create, extracted, **kwargs): | ||
brylie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not create: | ||
| return | ||
| if extracted: | ||
| for obje in extracted: | ||
| self.objects.add(obje) | ||
|
|
||
|
|
||
| class CiviFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Civi | ||
|
|
||
| author = User.objects.get_or_create(username="admin") | ||
| thread = factory.SubFactory(ThreadFactory) | ||
| title = factory.Faker("lorem") | ||
| body = factory.Faker("lorem") | ||
| c_type = factory.Faker("lorem") | ||
| votes_vneg = 0 | ||
| votes_neg = 0 | ||
| votes_neutral = 0 | ||
| votes_pos = 0 | ||
| votes_vpos = 0 | ||
|
|
||
| @factory.post_generation | ||
Nehemiah60 marked this conversation as resolved.
Show resolved
Hide resolved
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. Similar blocks of code found in 5 locations. Consider refactoring. |
||
| def tags(self, create, extracted, **kwargs): | ||
| if not create: | ||
| return | ||
| if extracted: | ||
| for tag in extracted: | ||
| self.tags.add(tag) | ||
|
|
||
| @factory.post_generation | ||
|
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. Similar blocks of code found in 9 locations. Consider refactoring. |
||
| def objects(self, create, extracted, **kwargs): | ||
| if not create: | ||
| return | ||
| if extracted: | ||
| for obje in extracted: | ||
| self.objects.add(obje) | ||
|
|
||
|
|
||
| class ResponseFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Response | ||
|
|
||
| author = User.objects.get_or_create(username="admin") | ||
| civi = factory.SubFactory(CiviFactory) | ||
| title = factory.Faker("lorem") | ||
| body = factory.Faker("lorem") | ||
| votes_vneg = 0 | ||
| votes_neg = 0 | ||
| votes_neutral = 0 | ||
| votes_pos = 0 | ||
| votes_vpos = 0 | ||
|
|
||
|
|
||
| class CiviImageFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = CiviImage | ||
|
|
||
| civi = factory.SubFactory(CiviFactory) | ||
| title = factory.Faker("lorem") | ||
| image = factory.Faker("image_url") | ||
|
|
||
| @factory.post_generation | ||
|
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. Similar blocks of code found in 9 locations. Consider refactoring. |
||
| def objects(self, create, extracted, **kwargs): | ||
brylie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not create: | ||
| return | ||
| if extracted: | ||
| for obje in extracted: | ||
| self.objects.add(obje) | ||
|
|
||
|
|
||
| class ActivityFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Activity | ||
|
|
||
| user = factory.SubFactory("app.factories.UserFactory") | ||
| thread = factory.SubFactory(ThreadFactory) | ||
| civi = factory.SubFactory(CiviFactory) | ||
| activity_type = factory.Faker("lorem") | ||
| read = factory.fuzzy.FuzzyChoice(choices=[True, False]) | ||
|
|
||
|
|
||
| class RebuttalFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Rebuttal | ||
|
|
||
| author = User.objects.get_or_create(username="admin") | ||
| response = factory.SubFactory(ResponseFactory) | ||
| body = factory.Faker("lorem") | ||
| votes_vneg = 0 | ||
| votes_neg = 0 | ||
| votes_neutral = 0 | ||
| votes_pos = 0 | ||
| votes_vpos = 0 | ||
|
|
||
|
|
||
| class RationaleFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = Rationale | ||
|
|
||
| title = factory.Faker("lorem") | ||
| body = factory.Faker("lorem") | ||
| votes_vneg = 0 | ||
| votes_neg = 0 | ||
| votes_neutral = 0 | ||
| votes_pos = 0 | ||
| votes_vpos = 0 | ||
Uh oh!
There was an error while loading. Please reload this page.