Skip to content

Commit

Permalink
chore: use factory-boy 3.3 (#6269)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Sep 5, 2023
1 parent f54f044 commit 3c1fc3c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions ietf/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def test_person_export(self):
url = urlreverse('ietf.api.views.PersonalInformationExportView')
login_testing_unauthorized(self, person.user.username, url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
jsondata = r.json()
data = jsondata['person.person'][str(person.id)]
self.assertEqual(data['name'], person.name)
Expand Down
9 changes: 8 additions & 1 deletion ietf/doc/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def draft_name_generator(type_id,group,n):
class BaseDocumentFactory(factory.django.DjangoModelFactory):
class Meta:
model = Document
skip_postgeneration_save = True

title = factory.Faker('sentence',nb_words=5)
abstract = factory.Faker('paragraph', nb_sentences=5)
Expand Down Expand Up @@ -329,6 +330,7 @@ class ReviewFactory(BaseDocumentFactory):
class DocAliasFactory(factory.django.DjangoModelFactory):
class Meta:
model = DocAlias
skip_postgeneration_save = True

@factory.post_generation
def document(self, create, extracted, **kwargs):
Expand Down Expand Up @@ -378,6 +380,7 @@ def desc(self):
class StateDocEventFactory(DocEventFactory):
class Meta:
model = StateDocEvent
skip_postgeneration_save = True

type = 'changed_state'
state_type_id = 'draft-iesg'
Expand Down Expand Up @@ -451,6 +454,7 @@ class WgDocumentAuthorFactory(DocumentAuthorFactory):
class BofreqEditorDocEventFactory(DocEventFactory):
class Meta:
model = BofreqEditorDocEvent
skip_postgeneration_save = True

type = "changed_editors"
doc = factory.SubFactory('ietf.doc.factories.BofreqFactory')
Expand All @@ -465,10 +469,12 @@ def editors(obj, create, extracted, **kwargs):
else:
obj.editors.set(PersonFactory.create_batch(3))
obj.desc = f'Changed editors to {", ".join(obj.editors.values_list("name",flat=True)) or "(None)"}'
obj.save()

class BofreqResponsibleDocEventFactory(DocEventFactory):
class Meta:
model = BofreqResponsibleDocEvent
skip_postgeneration_save = True

type = "changed_responsible"
doc = factory.SubFactory('ietf.doc.factories.BofreqFactory')
Expand All @@ -483,7 +489,8 @@ def responsible(obj, create, extracted, **kwargs):
else:
ad = RoleFactory(group__type_id='area',name_id='ad').person
obj.responsible.set([ad])
obj.desc = f'Changed responsible leadership to {", ".join(obj.responsible.values_list("name",flat=True)) or "(None)"}'
obj.desc = f'Changed responsible leadership to {", ".join(obj.responsible.values_list("name",flat=True)) or "(None)"}'
obj.save()

class BofreqFactory(BaseDocumentFactory):
type_id = 'bofreq'
Expand Down
4 changes: 4 additions & 0 deletions ietf/group/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class GroupFactory(factory.django.DjangoModelFactory):
class Meta:
model = Group
django_get_or_create = ('acronym',)
skip_postgeneration_save = True

name = factory.Faker('sentence',nb_words=6)
acronym = factory.Sequence(lambda n: 'acronym%d' %n)
Expand Down Expand Up @@ -87,6 +88,7 @@ class DatelessGroupMilestoneFactory(BaseGroupMilestoneFactory):
class GroupHistoryFactory(factory.django.DjangoModelFactory):
class Meta:
model=GroupHistory
skip_postgeneration_save = True

time = lambda: timezone.now()
group = factory.SubFactory(GroupFactory, state_id='active')
Expand Down Expand Up @@ -138,6 +140,7 @@ class Meta:
class AppealArtifactFactory(factory.django.DjangoModelFactory):
class Meta:
model=AppealArtifact
skip_postgeneration_save = True

appeal = factory.SubFactory(AppealFactory)
artifact_type = factory.SubFactory("ietf.name.factories.AppealArtifactTypeNameFactory", slug="appeal")
Expand All @@ -158,4 +161,5 @@ def set_bits(obj, create, extracted, **kwargs):
if isinstance(using, str):
using = using.encode("utf-8")
obj.bits = memoryview(using)
obj.save()

1 change: 1 addition & 0 deletions ietf/ietfauth/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class OidClientRecordFactory(factory.django.DjangoModelFactory):
class Meta:
model = OidClientRecord
skip_postgeneration_save = True

name = factory.Faker('company')
owner = factory.SubFactory(UserFactory)
Expand Down
1 change: 1 addition & 0 deletions ietf/ipr/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def _fake_patent_info():
class IprDisclosureBaseFactory(factory.django.DjangoModelFactory):
class Meta:
model = IprDisclosureBase
skip_postgeneration_save = True

by = factory.SubFactory('ietf.person.factories.PersonFactory')
compliant = True
Expand Down
1 change: 1 addition & 0 deletions ietf/liaisons/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class LiaisonStatementFactory(factory.django.DjangoModelFactory):
class Meta:
model = LiaisonStatement
skip_postgeneration_save = True

title = factory.Faker('sentence')
from_contact = factory.SubFactory('ietf.person.factories.EmailFactory')
Expand Down
6 changes: 6 additions & 0 deletions ietf/meeting/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class MeetingFactory(factory.django.DjangoModelFactory):
class Meta:
model = Meeting
skip_postgeneration_save = True

type_id = factory.Iterator(['ietf','interim'])

Expand Down Expand Up @@ -103,6 +104,7 @@ def group_conflicts(obj, create, extracted, **kwargs): # pulint: disable=no-sel
class SessionFactory(factory.django.DjangoModelFactory):
class Meta:
model = Session
skip_postgeneration_save = True

meeting = factory.SubFactory(MeetingFactory)
purpose_id = 'regular'
Expand Down Expand Up @@ -156,6 +158,7 @@ class Meta:
class RoomFactory(factory.django.DjangoModelFactory):
class Meta:
model = Room
skip_postgeneration_save = True

meeting = factory.SubFactory(MeetingFactory)
name = factory.Faker('name')
Expand All @@ -172,6 +175,7 @@ def session_types(obj, create, extracted, **kwargs): # pylint: disable=no-self-a
class TimeSlotFactory(factory.django.DjangoModelFactory):
class Meta:
model = TimeSlot
skip_postgeneration_save = True

meeting = factory.SubFactory(MeetingFactory)
type_id = 'regular'
Expand Down Expand Up @@ -225,6 +229,7 @@ class Meta:
class SlideSubmissionFactory(factory.django.DjangoModelFactory):
class Meta:
model = SlideSubmission
skip_postgeneration_save = True

session = factory.SubFactory(SessionFactory)
title = factory.Faker('sentence')
Expand All @@ -238,6 +243,7 @@ class Meta:
class ConstraintFactory(factory.django.DjangoModelFactory):
class Meta:
model = Constraint
skip_postgeneration_save = True

meeting = factory.SubFactory(MeetingFactory)
source = factory.SubFactory(GroupFactory)
Expand Down
3 changes: 3 additions & 0 deletions ietf/nomcom/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def nomcom_kwargs_for_year(year=None, *args, **kwargs):
class NomComFactory(factory.django.DjangoModelFactory):
class Meta:
model = NomCom
skip_postgeneration_save = True

group = factory.SubFactory(GroupFactory,type_id='nomcom')

Expand Down Expand Up @@ -167,6 +168,7 @@ class Meta:
class FeedbackFactory(factory.django.DjangoModelFactory):
class Meta:
model = Feedback
skip_postgeneration_save = True

nomcom = factory.SubFactory(NomComFactory)
subject = factory.Faker('sentence')
Expand All @@ -176,6 +178,7 @@ class Meta:
def comments(obj, create, extracted, **kwargs):
comment_text = Faker().paragraph()
obj.comments = obj.nomcom.encrypt(comment_text)
obj.save()

class TopicFactory(factory.django.DjangoModelFactory):
class Meta:
Expand Down
5 changes: 5 additions & 0 deletions ietf/person/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Meta:
model = User
django_get_or_create = ('username',)
exclude = ['faker', ]
skip_postgeneration_save = True

faker = factory.LazyFunction(random_faker)
# normalize these i18n Unicode strings in the same way the database does
Expand All @@ -55,13 +56,16 @@ class Meta:
slugify(unidecode(u.last_name)), n, fake.domain_name())) # type: ignore
username = factory.LazyAttribute(lambda u: u.email)

# Consider using PostGenerationMethodCall instead
@factory.post_generation
def set_password(obj, create, extracted, **kwargs): # pylint: disable=no-self-argument
obj.set_password( '%s+password' % obj.username ) # pylint: disable=no-value-for-parameter
obj.save()

class PersonFactory(factory.django.DjangoModelFactory):
class Meta:
model = Person
skip_postgeneration_save = True

user = factory.SubFactory(UserFactory)
name = factory.LazyAttribute(lambda p: normalize_name('%s %s'%(p.user.first_name, p.user.last_name)))
Expand Down Expand Up @@ -106,6 +110,7 @@ def default_photo(obj, create, extracted, **kwargs): # pylint: disable=no-self-a
def delete_file(file):
os.unlink(file)
atexit.register(delete_file, photodst)
obj.save()

class AliasFactory(factory.django.DjangoModelFactory):
class Meta:
Expand Down
1 change: 1 addition & 0 deletions ietf/review/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class ReviewTeamSettingsFactory(factory.django.DjangoModelFactory):
class Meta:
model = ReviewTeamSettings
skip_postgeneration_save = True

group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='review')
reviewer_queue_policy_id = 'RotateAlphabetically'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ django-widget-tweaks>=1.4.12
djlint>=1.0.0 # To auto-indent templates via "djlint --profile django --reformat"
docutils>=0.18.1 # Used only by dbtemplates for RestructuredText
types-docutils>=0.18.1
factory-boy>=3.2.1,<3.3
factory-boy>=3.3
github3.py>=3.2.0
gunicorn>=20.1.0
hashids>=1.3.1
Expand Down

0 comments on commit 3c1fc3c

Please sign in to comment.