Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions project/accounts/factory.py
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=[False, False])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also allow True?

Suggested change
is_verified = factory.fuzzy.FuzzyChoice(choices=[False, False])
is_verified = factory.fuzzy.FuzzyChoice(choices=[True, False])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not so sure. Because the field had False as a default value. But I will make the changes @brylie

profile_image = factory.Faker("image_url")
profile_image_thumb = factory.Faker("image_url")

@factory.post_generation
def categories(self, create, extracted, **kwargs):
if not create:
return
if extracted:
for category in extracted:
self.categories.add(category)

# @factory.post_generation
# def tags(self, create, extracted, **kwargs):
# if not create:
# return
# if extracted:
# for tag in extracted:
# self.tags.add(tag)

# @factory.post_generation
# def following(self, create, extracted, **kwargs):
# if not create:
# return
# if extracted:
# for follower in extracted:
# self.following.add(follower)
10 changes: 10 additions & 0 deletions project/categories/factory.py
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")
17 changes: 17 additions & 0 deletions project/notification/factory.py
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, True, True, False])
68 changes: 68 additions & 0 deletions project/threads/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import factory
import factory.fuzzy
from categories.factory import CategoryFactory
from django.contrib.auth.models import User

from .models import Civi, Fact, Thread


class FactFactory(factory.django.DjangoModelFactory):
class Meta:
model = Fact

body = factory.Sequence(lambda n: "Fact #%s" % n)


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, True, True, True])
num_views = 0
num_civis = 0
num_solutions = 0

@factory.post_generation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 9 locations. Consider refactoring.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 5 locations. Consider refactoring.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 6 locations. Consider refactoring.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

Choose a reason for hiding this comment

The 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
# def tags(self, create, extracted, **kwargs):
# if not create:
# return
# if extracted:
# for tag in extracted:
# self.tags.add(tag)

# @factory.post_generation
# def objects(self, create, extracted, **kwargs):
# 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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ipython = "^8.5.0"
django-debug-toolbar = "^3.7.0"
django-linear-migrations = "^2.5.1"
pre-commit = "^2.20.0"
factory-boy = "^3.2.1"

[tool.isort]
profile = "black"
Expand Down