class BackendNetworkFactory(factory.DjangoModelFactory): FACTORY_FOR = models.BackendNetwork network = factory.SubFactory(NetworkFactory, state="ACTIVE") backend = factory.SubFactory(BackendFactory) operstate = factory.Sequence(round_seq_first(FACTORY_FOR.OPER_STATES))
class BookingErrorFactory(factory.DjangoModelFactory): """ Factory for the ``BookingError`` model. """ class Meta: model = models.BookingError booking = factory.SubFactory(BookingFactory)
class UserImageFactory(factory.django.DjangoModelFactory): class Meta: model = UserImage user = factory.SubFactory(CustomUserFactory) image = factory.django.ImageField(file_name='test_image.jpg')
class TopicPollVoteFactory(factory.DjangoModelFactory): poll_option = factory.SubFactory(TopicPollOptionFactory) voter = factory.SubFactory(UserFactory) class Meta: model = TopicPollVote
class AuthorBioFactory(factory.django.DjangoModelFactory): class Meta: model = AuthorBio author = factory.SubFactory(AuthorFactory) body = factory.LazyAttribute(lambda x: faker.text())
class UserLogFactory(BaseFactory): class Meta: model = demoapp.UserLog message = factory.fuzzy.FuzzyText() user = factory.SubFactory(UserFactory)
class TopicPollFactory(factory.DjangoModelFactory): topic = factory.SubFactory(TopicFactory) question = faker.text(max_nb_chars=200) class Meta: model = TopicPoll
class CollectionMemberFactory(DjangoModelFactory): collection = factory.SubFactory(CollectionFactory, parent=None)
class PlanScheduleFactory(factory.django.DjangoModelFactory): class Meta: model = PlanSchedule branch = factory.SubFactory(BranchFactory) plan = factory.SubFactory(PlanFactory)
class LessonFactory(factory.DjangoModelFactory): class Meta: model = Lesson course = factory.SubFactory(CourseFactory) start_time = ru_faker('date_time')
class IndustryTagFactory(factory.django.DjangoModelFactory): class Meta: model = snippets.IndustryTag name = factory.fuzzy.FuzzyText(length=10) icon = factory.SubFactory(wagtail_factories.ImageFactory)
class TeacherFactory(factory.DjangoModelFactory): class Meta: model = Teacher user = factory.SubFactory(UserFactory)
class ProjectBackendFactory(factory.DjangoModelFactory): FACTORY_FOR = models.ProjectBackend project = factory.Sequence(prefix_seq("project")) backend = factory.SubFactory(BackendFactory)
class FloatingIPFactory(IPv4AddressFactory): network = factory.SubFactory(NetworkFactory, public=True, floating_ip_pool=True, state="ACTIVE") floating_ip = True
class PlantationFactory(factory.django.DjangoModelFactory): name = factory.fuzzy.FuzzyText() geo_location = factory.SubFactory(GeolocationFactory) class Meta: model = PlantationModel
class OrgFactory(factory.django.DjangoModelFactory): class Meta: model = Org repo = factory.SubFactory(RepositoryFactory) json = "{}"
class FavoriteProductFactory(factory.django.DjangoModelFactory): class Meta: model = FavoriteProduct customer = factory.SubFactory(CustomerFactory) product = factory.SubFactory(ProductFactory)
class ScratchOrgInstanceFactory(factory.django.DjangoModelFactory): class Meta: model = ScratchOrgInstance org = factory.SubFactory(OrgFactory)
class TaggedItemFactory(factory.django.DjangoModelFactory): class Meta: model = TaggedItem content_object = factory.SubFactory(EntryFactory) tag = factory.LazyAttribute(lambda x: faker.word())
class PlanRepositoryFactory(factory.django.DjangoModelFactory): class Meta: model = PlanRepository plan = factory.SubFactory(PlanFactory) repo = factory.SubFactory(RepositoryFactory)
class TopicPollOptionFactory(factory.DjangoModelFactory): poll = factory.SubFactory(TopicPollFactory) text = faker.text(max_nb_chars=100) class Meta: model = TopicPollOption
class BranchFactory(factory.django.DjangoModelFactory): class Meta: model = Branch name = factory.fuzzy.FuzzyChoice(["master", "branch1", "branch2"]) repo = factory.SubFactory(RepositoryFactory)
class TaxSubFactory(TaxFactoryBase): event = factory.SubFactory(EventFactoryBasic)
class BlogPostVersionFactory(AbstractVersionFactory): content = factory.SubFactory(BlogContentFactory) class Meta: model = Version
class ProfileFactory(factory.django.DjangoModelFactory): class Meta: model = Profile user = factory.SubFactory(UserFactory, profile=None)
class PageFactory(factory.django.DjangoModelFactory): node = factory.SubFactory(TreeNodeFactory) class Meta: model = Page
class ExperimentFactory(factory.django.DjangoModelFactory): type = Experiment.TYPE_PREF owner = factory.SubFactory(UserFactory) project = factory.SubFactory(ProjectFactory) name = factory.LazyAttribute(lambda o: faker.catch_phrase()) slug = factory.LazyAttribute(lambda o: "{}_".format(slugify(o.name))) archived = False short_description = factory.LazyAttribute( lambda o: faker.text(random.randint(100, 500))) proposed_start_date = factory.LazyAttribute(lambda o: (datetime.date.today( ) + datetime.timedelta(days=random.randint(1, 10)))) proposed_end_date = factory.LazyAttribute( lambda o: (o.proposed_start_date + datetime.timedelta(days=random. randint(1, 10)))) pref_key = factory.LazyAttribute(lambda o: "browser.{pref}.enabled".format( pref=faker.catch_phrase().replace(" ", ".").lower())) pref_type = factory.LazyAttribute( lambda o: random.choice(Experiment.PREF_TYPE_CHOICES[1:])[0]) pref_branch = factory.LazyAttribute( lambda o: random.choice(Experiment.PREF_BRANCH_CHOICES[1:])[0]) firefox_version = factory.LazyAttribute( lambda o: random.choice(Experiment.VERSION_CHOICES[1:])[0]) firefox_channel = factory.LazyAttribute( lambda o: random.choice(Experiment.CHANNEL_CHOICES[1:])[0]) objectives = factory.LazyAttribute( lambda o: faker.text(random.randint(500, 5000))) analysis_owner = factory.LazyAttribute(lambda o: faker.name()) analysis = factory.LazyAttribute( lambda o: faker.text(random.randint(500, 5000))) testing = factory.LazyAttribute( lambda o: faker.text(random.randint(500, 5000))) risks = factory.LazyAttribute( lambda o: faker.text(random.randint(500, 5000))) total_users = factory.LazyAttribute( lambda o: random.randint(100000, 1000000)) risk_partner_related = False risk_brand = False risk_fast_shipped = False risk_confidential = False risk_release_population = False enrollment_dashboard_url = "http://www.example.com/enrollment" dashboard_url = "http://www.example.com/dashboard" dashboard_image_url = "http://www.example.com/dashboard.png" population_percent = factory.LazyAttribute( lambda o: decimal.Decimal(random.randint(1, 10) * 10)) client_matching = ("Locales: en-US, en-CA, en-GB\nGeos: US, CA, GB\n" 'Some "additional" filtering') review_phd = False review_science = False review_peer = False review_relman = False review_qa = False review_legal = False review_ux = False review_security = False review_vp = False review_data_steward = False class Meta: model = Experiment @classmethod def create_with_variants(cls, num_variants=3, *args, **kwargs): experiment = cls.create(*args, **kwargs) for i in range(num_variants): if i == 0: ExperimentControlFactory.create(experiment=experiment) else: ExperimentVariantFactory.create(experiment=experiment) return experiment @classmethod def create_with_status(cls, target_status, *args, **kwargs): experiment = cls.create_with_variants(*args, **kwargs) now = datetime.datetime.now() - datetime.timedelta( days=random.randint(100, 200)) old_status = None for status_value, status_label in Experiment.STATUS_CHOICES: experiment.status = status_value experiment.save() change = ExperimentChangeLogFactory.create( experiment=experiment, old_status=old_status, new_status=status_value, ) change.changed_on = now change.save() if status_value == target_status: break old_status = status_value now += datetime.timedelta(days=random.randint(5, 20)) return experiment
class PollVersionFactory(AbstractVersionFactory): content = factory.SubFactory(PollContentFactory) class Meta: model = Version
class NotificationFactory(factory.django.DjangoModelFactory): user = factory.SubFactory(UserFactory) class Meta: model = "notifications.Notification"
class VirtualMachineMetadataFactory(factory.DjangoModelFactory): FACTORY_FOR = models.VirtualMachineMetadata meta_key = factory.Sequence(prefix_seq('key')) meta_value = factory.Sequence(prefix_seq('pass')) vm = factory.SubFactory(VirtualMachineFactory)