class BaseReportsFactory(BaseFactory): committee_id = factory.LazyAttribute( lambda o: CommitteeFactory().committee_id)
class RiskAssessmentFactory(TitledFactory): class Meta: model = all_models.RiskAssessment status = "Draft" program = factory.LazyAttribute(lambda _: ProgramFactory())
class UserFactory(factory.django.DjangoModelFactory): class Meta: model = User username = factory.Sequence(lambda n: "user%d" % n) email = factory.LazyAttribute(lambda obj: "*****@*****.**" % obj.username)
class StandardFactory(TitledFactory): """Standard factory class""" class Meta: model = all_models.Standard description = factory.LazyAttribute(lambda _: random_str(length=100))
class ReviewFactory(ModelFactory): class Meta: model = all_models.Review reviewable = factory.LazyAttribute(lambda _: ControlFactory()) notification_type = all_models.Review.NotificationTypes.EMAIL_TYPE
class IssueTrackerIssueFactory(TitledFactory): class Meta: model = all_models.IssuetrackerIssue issue_tracked_obj = factory.LazyAttribute(lambda m: AssessmentFactory()) issue_id = factory.LazyAttribute(lambda _: random.randint(1, 1000))
class ProgramFactory(TitledFactory): class Meta: model = all_models.Program context = factory.LazyAttribute(lambda _: ContextFactory())
class InventoryFactory(factory.django.DjangoModelFactory): made_at = factory.LazyAttribute(lambda o: datetime.datetime.utcnow()) class Meta: model = Inventory
class StripeCustomerFactory(ModelFactory): class Meta: model = StripeCustomer stripe_customer_id = factory.LazyAttribute(lambda _: f"cus_{fake.uuid4()}")
class GeoLevelFactory(MongoEngineFactory): class Meta: model = GeoLevel id = factory.LazyAttribute(lambda o: unique_string()) name = factory.Faker('name')
class FileFactory(factory.django.DjangoModelFactory): file = factory.LazyAttribute(lambda x: choice(File.PATHS)[0]) class Meta: model = File django_get_or_create = ('file', )
class SpatialCoverageFactory(MongoEngineFactory): class Meta: model = SpatialCoverage geom = factory.Faker('multipolygon') granularity = factory.LazyAttribute(random_spatial_granularity)
class ArticleFactory(factory.django.DjangoModelFactory): class Meta: model = Article django_get_or_create = ('title', 'path') path = factory.Sequence( lambda n: u'00010{}'.format(n)) # Article sequence starts from 0001020 depth = 2 numchild = 0 title = "Article Page" slug = factory.LazyAttribute(lambda obj: slugify(obj.title)) live = True has_unpublished_changes = False seo_title = " " show_in_menus = False search_description = " " go_live_at = '2011-10-24 12:43' expire_at = '2050-12-31 12:43' expired = False content_type = factory.SubFactory(ContentTypeFactory, app_label="article", model="article") locked = False latest_revision_created_at = '2011-10-24 12:43' first_published_at = '2011-10-24 12:43' strap = "Article strap" content = "<p> Article Content ok </p>" show_modular_content = False modular_content = '[{"type": "paragraph", "value": {"content": "<p>This is a test</p>", "align_content": "default"}}, {"type": "n_column_paragraph", "value": {"paragraph": [{"content": "<p>A test that make test</p>", "align_content": "default"}]}}, {"type": "n_column_paragraph", "id": "f9908f13-68ad-4eb5-9943-5e1cd92a944a", "value": {"paragraph": [{"content": "<p>A test that make test</p>", "align_content": "default"}]}}]' language = "en" @classmethod def _setup_next_sequence(cls): return getattr(cls, 'starting_seq_num', 20) @factory.post_generation def featured_image(self, create, extracted, **kwargs): if not create: return if extracted: self.featured_image = extracted @factory.post_generation def authors(self, create, extracted, **kwargs): if not create: return if extracted: for author in extracted: self.authors.add(author) @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 locations(self, create, extracted, **kwargs): if not create: return if extracted: for location in extracted: self.locations.add(location)
class CustomImageFactory(factory.DjangoModelFactory): title = factory.sequence(lambda x: "extended-image-{0}".format([x])) file = factory.LazyAttribute(lambda x: get_test_image_file()) class Meta: model = CustomImage
class GeoLevelFactory(MongoEngineFactory): class Meta: model = models.GeoLevel id = factory.LazyAttribute(lambda o: unique_string()) name = factory.LazyAttribute(lambda o: faker.name())
class PollFactory(factory.DjangoModelFactory): class Meta: model = models.Poll question = factory.Faker("sentence") pub_date = factory.LazyAttribute(lambda __: timezone.now())
class ControlFactory(TitledFactory): class Meta: model = all_models.Control directive = factory.LazyAttribute(lambda m: RegulationFactory()) recipients = ""
class HumanFactory(factory.Factory): class Meta: model = Human name = factory.LazyAttribute(lambda x: faker.name())
class AssessmentFactory(TitledFactory): class Meta: model = all_models.Assessment audit = factory.LazyAttribute(lambda m: AuditFactory())
class DatasetDiscussionFactory(MongoEngineFactory): class Meta: model = models.DatasetDiscussion title = factory.LazyAttribute(lambda o: faker.sentence())
class PersonFactory(ModelFactory): class Meta: model = all_models.Person email = factory.LazyAttribute( lambda _: random_str(chars=string.ascii_letters) + "@example.com")
class OrganizationFactory(MongoEngineFactory): class Meta: model = models.Organization name = factory.LazyAttribute(lambda o: faker.sentence()) description = factory.LazyAttribute(lambda o: faker.text())
class ProposalFactory(ModelFactory): class Meta: model = all_models.Proposal proposed_by = factory.LazyAttribute(lambda _: PersonFactory()) content = None
class LicenseFactory(MongoEngineFactory): class Meta: model = models.License id = factory.LazyAttribute(lambda o: faker.word()) title = factory.LazyAttribute(lambda o: faker.sentence())
class TitledFactory(ModelFactory): title = factory.LazyAttribute(lambda m: random_str(prefix='title '))
class SpatialCoverageFactory(MongoEngineFactory): class Meta: model = models.SpatialCoverage geom = factory.LazyAttribute(lambda o: faker.multipolygon()) granularity = factory.LazyAttribute(random_spatial_granularity)
class PersonWithoutUserFactory(PersonFactory): user = None first_name = factory.Faker('first_name') last_name = factory.Faker('last_name') email = factory.LazyAttribute(generate_person_email)
class TransferFactory(MongoEngineFactory): class Meta: model = models.Transfer comment = factory.LazyAttribute(lambda o: faker.sentence())
class UserFavouriteEventFactory(BaseFactory): class Meta: model = UserFavouriteEvent user = factory.LazyAttribute(lambda a: User.query.first()) event = factory.SubFactory(EventFactoryBasic)
class BaseTotalsFactory(BaseFactory): committee_id = factory.LazyAttribute( lambda o: CommitteeFactory().committee_id) cycle = 2016