chore: use factory-boy 3.3 (#6269)

This commit is contained in:
Robert Sparks 2023-09-05 09:54:30 -05:00 committed by GitHub
parent f54f04460f
commit 3c1fc3c0f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 32 additions and 2 deletions

View file

@ -581,6 +581,7 @@ class CustomApiTests(TestCase):
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)

View file

@ -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)
@ -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):
@ -378,6 +380,7 @@ class NewRevisionDocEventFactory(DocEventFactory):
class StateDocEventFactory(DocEventFactory):
class Meta:
model = StateDocEvent
skip_postgeneration_save = True
type = 'changed_state'
state_type_id = 'draft-iesg'
@ -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')
@ -465,10 +469,12 @@ class BofreqEditorDocEventFactory(DocEventFactory):
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')
@ -483,7 +489,8 @@ class BofreqResponsibleDocEventFactory(DocEventFactory):
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'

View file

@ -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)
@ -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')
@ -138,6 +140,7 @@ class AppealFactory(factory.django.DjangoModelFactory):
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")
@ -158,4 +161,5 @@ class AppealArtifactFactory(factory.django.DjangoModelFactory):
if isinstance(using, str):
using = using.encode("utf-8")
obj.bits = memoryview(using)
obj.save()

View file

@ -14,6 +14,7 @@ from ietf.person.factories import UserFactory, PersonFactory
class OidClientRecordFactory(factory.django.DjangoModelFactory):
class Meta:
model = OidClientRecord
skip_postgeneration_save = True
name = factory.Faker('company')
owner = factory.SubFactory(UserFactory)

View file

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

View file

@ -6,6 +6,7 @@ from ietf.liaisons.models import LiaisonStatement, LiaisonStatementEvent, Liaiso
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')

View file

@ -23,6 +23,7 @@ from ietf.utils.text import xslugify
class MeetingFactory(factory.django.DjangoModelFactory):
class Meta:
model = Meeting
skip_postgeneration_save = True
type_id = factory.Iterator(['ietf','interim'])
@ -103,6 +104,7 @@ class MeetingFactory(factory.django.DjangoModelFactory):
class SessionFactory(factory.django.DjangoModelFactory):
class Meta:
model = Session
skip_postgeneration_save = True
meeting = factory.SubFactory(MeetingFactory)
purpose_id = 'regular'
@ -156,6 +158,7 @@ class ScheduleFactory(factory.django.DjangoModelFactory):
class RoomFactory(factory.django.DjangoModelFactory):
class Meta:
model = Room
skip_postgeneration_save = True
meeting = factory.SubFactory(MeetingFactory)
name = factory.Faker('name')
@ -172,6 +175,7 @@ class RoomFactory(factory.django.DjangoModelFactory):
class TimeSlotFactory(factory.django.DjangoModelFactory):
class Meta:
model = TimeSlot
skip_postgeneration_save = True
meeting = factory.SubFactory(MeetingFactory)
type_id = 'regular'
@ -225,6 +229,7 @@ class FloorPlanFactory(factory.django.DjangoModelFactory):
class SlideSubmissionFactory(factory.django.DjangoModelFactory):
class Meta:
model = SlideSubmission
skip_postgeneration_save = True
session = factory.SubFactory(SessionFactory)
title = factory.Faker('sentence')
@ -238,6 +243,7 @@ class SlideSubmissionFactory(factory.django.DjangoModelFactory):
class ConstraintFactory(factory.django.DjangoModelFactory):
class Meta:
model = Constraint
skip_postgeneration_save = True
meeting = factory.SubFactory(MeetingFactory)
source = factory.SubFactory(GroupFactory)

View file

@ -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')
@ -167,6 +168,7 @@ class NomineePositionFactory(factory.django.DjangoModelFactory):
class FeedbackFactory(factory.django.DjangoModelFactory):
class Meta:
model = Feedback
skip_postgeneration_save = True
nomcom = factory.SubFactory(NomComFactory)
subject = factory.Faker('sentence')
@ -176,6 +178,7 @@ class FeedbackFactory(factory.django.DjangoModelFactory):
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:

View file

@ -46,6 +46,7 @@ class UserFactory(factory.django.DjangoModelFactory):
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
@ -55,13 +56,16 @@ class UserFactory(factory.django.DjangoModelFactory):
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)))
@ -106,6 +110,7 @@ class PersonFactory(factory.django.DjangoModelFactory):
def delete_file(file):
os.unlink(file)
atexit.register(delete_file, photodst)
obj.save()
class AliasFactory(factory.django.DjangoModelFactory):
class Meta:

View file

@ -11,6 +11,7 @@ from ietf.name.models import ReviewTypeName, ReviewResultName
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'

View file

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