Skip to content
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

Add development fixtures for #1350 & Add django-browser-reload #1346 #1401

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion poetry.lock

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

70 changes: 70 additions & 0 deletions project/accounts/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from turtle import color
import factory
from . import models
from categories.factory import CategoryFactory

class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.User


class ProfileFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Profile

profile = factory.RelatedFactory(UserFactory, factory_related_name="profile")
first_name = factory.Faker('first_name')
last_name = factory.Faker('last_name')
about_me = factory.Faker('sentence', nb_words=20)

@factory.post_generation
def categories(self, create, extracted, **kwargs):
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return

# Add the iterable of categores using bulk addition
self.categories.add(*extracted)

@factory.post_generation
def tags(self, create, extracted, **kwargs):
self.tags.add(u'abc, cde', u'xzy')

@factory.post_generation
def followers(self, create, extracted, **kwargs):
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return

# Add the iterable of following using bulk addition
self.followers.add(*extracted)

@factory.post_generation
def following(self, create, extracted, **kwargs):
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return

# Add the iterable of following using bulk addition
self.following.add(*extracted)

is_verified = factory.Faker().pybool()
full_profile = factory.Faker().pybool()
profile_image = factory.django.ImageField(color='blue')
profile_image_thumb = factory.django.ImageField(color='blue')

#defining the ProfileManager for the objects field
@classmethod
def _create(cls, model_class, *args, **kwargs):
"""Override the default ``_create`` with our custom call."""
manager = cls._get_manager(model_class)
# The default would use ``manager.create(*args, **kwargs)``
return manager.summarize(*args, **kwargs)








11 changes: 11 additions & 0 deletions project/categories/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import factory
from . import models
from shared_factory.shared_factory import FreezeTimeModelFactory

class CategoryFactory(FreezeTimeModelFactory):
class Meta:
model = models.Category

name = factory.Iterator(["Politics","Voting","Referendum"])


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
from . import models
from shared_factory.shared_factory import FreezeTimeModelFactory
from accounts.factory import ProfileFactory
from threads.factory import ThreadFactory, CiviFactory

class NotificationFactory(FreezeTimeModelFactory):
class Meta:
model = models.Notification

account = factory.SubFactory(ProfileFactory)
thread = factory.SubFactory(ThreadFactory)
civi = factory.SubFactory(CiviFactory)
activity_type = factory.fuzzy.FuzzyChoice(models.Notification.activity_CHOICES, getter=lambda c: c[0])
read = factory.Faker().pybool()


Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

164 changes: 164 additions & 0 deletions project/threads/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
from turtle import title
import factory
from . import models
from shared_factory.shared_factory import FreezeTimeModelFactory
from accounts.factory import UserFactory
from categories.factory import CategoryFactory
from core.constants import CIVI_TYPES

class FactFactory(FreezeTimeModelFactory):
class Meta:
model = models.Fact

body = factory.Faker('sentence', nb_words=100)


class ThreadFactory(FreezeTimeModelFactory):
class Meta:
model = models.Thread

author = factory.SubFactory(UserFactory)
category = factory.SubFactory(CategoryFactory)

@factory.post_generation
def facts(self, create, extracted, **kwargs):
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return
# Add the iterable of categores using bulk addition
self.facts.add(*extracted)

@factory.post_generation
def tags(self, create, extracted, **kwargs):
self.tags.add(u'abc, cde', u'xzy')

title = factory.Faker('sentence', nb_words= 4)
summary = factory.Faker('sentence', nb_words= 30)
image = factory.django.ImageField(color='blue')
is_draft = factory.Faker().pybool()
num_views = factory.fuzzy.FuzzyInteger(0, 30)
num_civis = factory.fuzzy.FuzzyInteger(0, 30)
num_solutions = factory.fuzzy.FuzzyInteger(0, 30)

#defining the ThreadManager for the objects field
@classmethod
def _create(cls, model_class, *args, **kwargs):
"""Override the default ``_create`` with our custom call."""
manager = cls._get_manager(model_class)
# The default would use ``manager.create(*args, **kwargs)``
return manager.summarize(*args, **kwargs)


class CiviFactory(FreezeTimeModelFactory):
class Meta:
model = models.Civi

authors = factory.SubFactory(UserFactory)
thread = factory.SubFactory(ThreadFactory)

@factory.post_generation
def tags(self, create, extracted, **kwargs):
self.tags.add(u'abc, cde', u'xzy')

@factory.post_generation
def linked_civis(self, create, extracted, **kwargs):
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return
# Add the iterable of following using bulk addition
self.linked_civis.add(*extracted)

title = factory.Faker('sentence', nb_words= 4)
body = factory.Faker('sentence', nb_words= 100)
c_type = factory.fuzzy.FuzzyChoice(CIVI_TYPES, getter=lambda c: c[0])
votes_vneg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neutral = factory.fuzzy.FuzzyInteger(0, 30)
votes_pos = factory.fuzzy.FuzzyInteger(0, 30)
votes_vpos = factory.fuzzy.FuzzyInteger(0, 30)

#Please verify if this is the right implementation for votes = property(_get_votes)
@classmethod
def _create(cls, model_class, *args, **kwargs):
votes = model_class(*args, **kwargs)
return votes._get_votes()

#defining the CiViManager for the objects field
@classmethod
def _create(cls, model_class, *args, **kwargs):
"""Override the default ``_create`` with our custom call."""
manager = cls._get_manager(model_class)
# The default would use ``manager.create(*args, **kwargs)``
return manager.summarize(*args, **kwargs)


class ResponseFactory(factory.Factory):
class Meta:
model = models.Response

author = factory.SubFactory(UserFactory)
civi = factory.SubFactory(CiviFactory)
title = factory.Faker('sentence', nb_words= 4)
body = factory.Faker('sentence', nb_words= 100)
votes_vneg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neutral = factory.fuzzy.FuzzyInteger(0, 30)
votes_pos = factory.fuzzy.FuzzyInteger(0, 30)
votes_vpos = factory.fuzzy.FuzzyInteger(0, 30)


class CiviImageFactory(FreezeTimeModelFactory):
class Meta:
model = models.CiviImage

civi = factory.SubFactory(CiviFactory)
title = factory.Faker('sentence', nb_words= 4)
image = factory.django.ImageField(color='blue')


#defining the CiViManager for the objects field
@classmethod
def _create(cls, model_class, *args, **kwargs):
"""Override the default ``_create`` with our custom call."""
manager = cls._get_manager(model_class)
# The default would use ``manager.create(*args, **kwargs)``
return manager.get_images(*args, **kwargs)


class ActivityFactory(FreezeTimeModelFactory):
class Meta:
model = models.Activity

user = factory.SubFactory(UserFactory)
thread = factory.SubFactory(ThreadFactory)
civi = factory.SubFactory(CiviFactory)
activity_type = factory.fuzzy.FuzzyChoice(models.Activity.activity_CHOICES)
read = factory.Faker().pybool()


class RebuttalFactory(FreezeTimeModelFactory):
class Meta:
model = models.Rebuttal

author = factory.SubFactory(UserFactory)
response = factory.SubFactory(ResponseFactory)
body = factory.Faker('sentence', nb_words= 100)
votes_vneg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neutral = factory.fuzzy.FuzzyInteger(0, 30)
votes_pos = factory.fuzzy.FuzzyInteger(0, 30)
votes_vpos = factory.fuzzy.FuzzyInteger(0, 30)


class RationaleFactory(FreezeTimeModelFactory):
class Meta:
model = models.Rationale

title = factory.Faker('sentence', nb_words= 4)
body = factory.Faker('sentence', nb_words= 100)
votes_vneg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neg = factory.fuzzy.FuzzyInteger(0, 30)
votes_neutral = factory.fuzzy.FuzzyInteger(0, 30)
votes_pos = factory.fuzzy.FuzzyInteger(0, 30)
votes_vpos = factory.fuzzy.FuzzyInteger(0, 30)

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ django-stubs = "^1.12.0"
django-debug-toolbar = "^3.7.0"
django-linear-migrations = "^2.5.1"
pre-commit = "^2.20.0"
django-browser-reload = "^1.6.0"
Walexero marked this conversation as resolved.
Show resolved Hide resolved

[tool.mypy]
plugins = ["mypy_django_plugin.main"]
Expand Down