Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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=[True, False])
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

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.

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, False])
163 changes: 163 additions & 0 deletions project/threads/factory.py
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

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

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 6 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

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 6 locations. Consider refactoring.

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

@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 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

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.

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

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.

def objects(self, create, extracted, **kwargs):
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
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