Esempio n. 1
0
class SampleFactory(factory.alchemy.SQLAlchemyModelFactory):
    class Meta:
        model = Sample
        sqlalchemy_session = dal.Session()
        sqlalchemy_session_persistence = "commit"

    # id = factory.Sequence(lambda n: n)
    recipe = factory.RelatedFactory("test.database.factories.RecipeFactory",
                                    "sample")
    properties = factory.RelatedFactory(
        "test.database.factories.PropertiesFactory", "sample")
    authors = factory.RelatedFactoryList(
        "test.database.factories.AuthorFactory",
        "sample",
        size=lambda: LIST_SIZES[random.randint(0, 5)],
    )
    raman_files = factory.RelatedFactoryList(
        "test.database.factories.RamanFileFactory",
        "sample",
        size=lambda: LIST_SIZES[random.randint(0, 5)],
    )
    sem_files = factory.RelatedFactoryList(
        "test.database.factories.SemFileFactory",
        "sample",
        size=lambda: LIST_SIZES[random.randint(0, 5)],
    )
    #raman_set = factory.RelatedFactory("test.database.factories.RamanSetFactory", "sample")

    nanohub_userid = factory.Faker("pyint",
                                   min_value=0,
                                   max_value=9999,
                                   step=1)
    experiment_date = factory.Faker("date")
    material_name = factory.Iterator(Sample.material_name.info["choices"])
    validated = factory.Faker("boolean", chance_of_getting_true=50)
Esempio n. 2
0
class IncidentFactory(factory.DjangoModelFactory):
    class Meta:
        model = Incident

    impact = factory.LazyFunction(
        lambda: faker.paragraph(nb_sentences=1, variable_nb_sentences=True))
    report = factory.LazyFunction(
        lambda: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
    report_time = factory.LazyFunction(lambda: faker.date_time_between(
        start_date="-6m", end_date="now", tzinfo=None))

    reporter = factory.SubFactory("tests.factories.ExternalUserFactory")
    lead = factory.SubFactory("tests.factories.ExternalUserFactory")

    start_time = factory.LazyFunction(lambda: faker.date_time_between(
        start_date="-6m", end_date="now", tzinfo=None))

    if random.random() > 0.5:
        end_time = factory.LazyAttribute(lambda a: faker.date_time_between(
            start_date=a.start_time, end_date="now"))

    severity = factory.LazyFunction(lambda: str(random.randint(1, 4)))
    summary = factory.LazyFunction(
        lambda: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))

    related_channel = factory.RelatedFactory(CommsChannelFactory, "incident")
    related_action_items = factory.RelatedFactoryList(
        ActionFactory, "incident", size=lambda: random.randint(1, 5))
    related_timeline_events = factory.RelatedFactoryList(
        "tests.factories.TimelineEventFactory",
        "incident",
        size=lambda: random.randint(1, 20),
    )
Esempio n. 3
0
        class OriginFactory(factory_trytond.TrytonFactory):
            class Meta:
                model = 'test.one2many'

            targets = factory.RelatedFactoryList(TargetFactory,
                                                 factory_related_name='origin',
                                                 size=1)
Esempio n. 4
0
class LotWithBidsFactory(LotFactory):
    """Generates lot with bids."""
    bids = factory.RelatedFactoryList(
        factory=BidFactory,
        factory_related_name='lot',
        size=5,
    )
class UsersWithLotsAndBidsFactory(UsersFactory):
    """Generates users with lots and bids."""
    bids = factory.RelatedFactoryList(
        factory=BidFactory,
        factory_related_name='user',
        size=5,
    )
class UserWithCommentFactory(UsersFactory):
    """Factory for generating comments from one user to many lots."""
    comments = factory.RelatedFactoryList(
        CommentFactory,
        factory_related_name='user',
        size=10,
    )
class UsersWithMessagesFactory(DialogsFactory):
    """Generate dialogs with 5 messages."""
    dialogs = factory.RelatedFactoryList(
        MessagesFactory,
        factory_related_name='dialog',
        size=5,
    )
Esempio n. 8
0
class BootcampFactory(AbstractCourseFactory):
    """Factory for Bootcamps"""

    course_id = factory.Sequence(lambda n: "BOOTCAMP%03d.MIT" % n)
    offered_by = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceOfferorFactory",
        size=1,
        name=OfferedBy.bootcamps.value,
    )

    runs = factory.RelatedFactoryList(
        "course_catalog.factories.BootcampRunFactory",
        "content_object",
        size=3)

    class Meta:
        model = Bootcamp
Esempio n. 9
0
 class Params:
     with_answers = factory.Trait(
         questions=factory.RelatedFactoryList(
             'question.tests.factories.AnswerFactory',
             factory_related_name='question',
             size=2,
         )
     )
Esempio n. 10
0
class BootcampRunFactory(LearningResourceRunFactory):
    """LearningResourceRun factory specific to Bootcamps"""

    offered_by = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceOfferorFactory",
        size=1,
        name=OfferedBy.bootcamps.value,
    )
Esempio n. 11
0
class MonitorFactory(factory.alchemy.SQLAlchemyModelFactory):
    """ factory to generate a monitor """
    name = "Users list"
    endpoint = "http://apidash.dev:8000/api/v1/status/200"
    checks = factory.RelatedFactoryList(CheckFactory, 'monitor', size=24 * 7)

    class Meta:
        model = monitors_db.Monitor
        sqlalchemy_session = db_session
Esempio n. 12
0
class RosterPlayerFactory(DjangoModelFactory):
    title = factory.fuzzy.FuzzyText()
    season = factory.fuzzy.FuzzyText()
    active = factory.fuzzy.FuzzyInteger(0, 1)
    default = factory.fuzzy.FuzzyInteger(0, 1)
    players = factory.RelatedFactoryList(PlayerFactory)

    class Meta:
        model = Roster
Esempio n. 13
0
class SiderealTargetFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Target

    name = factory.Faker('pystr')
    type = Target.SIDEREAL
    ra = factory.Faker('pyfloat', min_value=-90, max_value=90)
    dec = factory.Faker('pyfloat', min_value=-90, max_value=90)
    epoch = factory.Faker('pyfloat')
    pm_ra = factory.Faker('pyfloat')
    pm_dec = factory.Faker('pyfloat')

    targetextra_set = factory.RelatedFactoryList(TargetExtraFactory,
                                                 factory_related_name='target',
                                                 size=3)
    aliases = factory.RelatedFactoryList(TargetNameFactory,
                                         factory_related_name='target',
                                         size=2)
Esempio n. 14
0
class FilterGroupFactory(factory.Factory):
    """Factory class for SQL FilterGroup objects."""
    class Meta:
        """Factory attributes for recreating the associated model's attributes."""

        model = sql.FilterGroup
        strategy = factory.BUILD_STRATEGY

    filters = factory.RelatedFactoryList(
        FilterFactory,
        size=lambda: np.random.randint(*ARBITRARY_SUBFACTORY_COUNT_RANGE))
Esempio n. 15
0
class VideoChannelFactory(LearningResourceFactory):
    """Factory for VideoChannel"""

    channel_id = factory.Sequence(lambda n: "VIDEO-CHANNEL-%03d.MIT" % n)
    platform = FuzzyChoice([PlatformType.youtube.value])

    full_description = factory.Faker("text")
    published = True

    offered_by = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceOfferorFactory",
        size=1,
        name=OfferedBy.ocw.value,
    )

    playlists = factory.RelatedFactoryList(
        "course_catalog.factories.PlaylistFactory", "channel", size=1)

    class Meta:
        model = VideoChannel
Esempio n. 16
0
class SemFileFactory(factory.alchemy.SQLAlchemyModelFactory):
    class Meta:
        model = SemFile
        sqlalchemy_session = dal.Session()
        sqlalchemy_session_persistence = "commit"

    sample = factory.SubFactory("test.database.factories.SampleFactory",
                                sem_files=None)
    analyses = factory.RelatedFactoryList(
        "test.database.factories.SemAnalysisFactory", "sem_file", size=3)

    filename = factory.Faker("file_name", extension="tif")
    url = factory.Faker("url")
Esempio n. 17
0
class HotelRoomTypeFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = models.HotelRoomType

    title = factory.LazyFunction(
        lambda: random.choice(["Single", "Double", "Triple"]) + " Room")
    hotel_rooms = factory.RelatedFactoryList(HotelRoomFactory,
                                             "hotel_room_type",
                                             size=lambda: random.randint(1, 3))
    booking_info = factory.RelatedFactory(
        BookingInfoFactory,
        "hotel_room_type",
        price=factory.LazyFunction(lambda: random.choice(PRICE_CHOICES)))
Esempio n. 18
0
class RecipeFactory(factory.alchemy.SQLAlchemyModelFactory):
    class Meta:
        model = Recipe
        sqlalchemy_session = dal.Session()
        sqlalchemy_session_persistence = "commit"

    sample = factory.SubFactory("test.database.factories.SampleFactory",
                                recipe=None)
    preparation_steps = factory.RelatedFactoryList(
        "test.database.factories.PreparationStepFactory", "recipe", size=3)

    thickness = factory.Faker("pyfloat",
                              positive=True,
                              min_value=0.0,
                              max_value=99.0)
    diameter = factory.Faker("pyfloat",
                             positive=True,
                             min_value=0.0,
                             max_value=10.0)
    length = factory.Faker("pyfloat",
                           positive=True,
                           min_value=0.0,
                           max_value=10.0)
    catalyst = factory.Faker("pyfloat",
                             positive=True,
                             min_value=0.0,
                             max_value=10.0)
    tube_diameter = factory.Faker("pyfloat",
                                  positive=True,
                                  min_value=0.0,
                                  max_value=10.0)
    cross_sectional_area = factory.Faker("pyfloat",
                                         positive=True,
                                         min_value=0.0,
                                         max_value=10.0)
    tube_length = factory.Faker("pyfloat",
                                positive=True,
                                min_value=0.0,
                                max_value=10.0)
    base_pressure = factory.Faker("pyfloat",
                                  positive=True,
                                  min_value=0.0,
                                  max_value=10.0)
    dewpoint = factory.Faker("pyfloat",
                             positive=True,
                             min_value=0.0,
                             max_value=10.0)
    sample_surface_area = factory.Faker("pyfloat",
                                        positive=True,
                                        min_value=0.0,
                                        max_value=10.0)
Esempio n. 19
0
class ProgramFactory(LearningResourceFactory):
    """Factory for Programs"""

    program_id = factory.Sequence(lambda n: n)
    image_src = factory.Faker("image_url")
    url = factory.Faker("uri")

    runs = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceRunFactory",
        "content_object",
        size=1)

    class Meta:
        model = Program
Esempio n. 20
0
class NonSiderealTargetFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Target

    name = factory.Faker('pystr')
    type = Target.NON_SIDEREAL
    mean_anomaly = factory.Faker('pyfloat')
    arg_of_perihelion = factory.Faker('pyfloat')
    lng_asc_node = factory.Faker('pyfloat')
    inclination = factory.Faker('pyfloat')
    mean_daily_motion = factory.Faker('pyfloat')
    semimajor_axis = factory.Faker('pyfloat')
    ephemeris_period = factory.Faker('pyfloat')
    ephemeris_period_err = factory.Faker('pyfloat')
    ephemeris_epoch = factory.Faker('pyfloat')
    ephemeris_epoch_err = factory.Faker('pyfloat')

    targetextra_set = factory.RelatedFactoryList(TargetExtraFactory,
                                                 factory_related_name='target',
                                                 size=3)
    aliases = factory.RelatedFactoryList(TargetNameFactory,
                                         factory_related_name='target',
                                         size=2)
Esempio n. 21
0
class MaterialFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Material

    class Params:
        name_base = factory.Faker("company")

    name = factory.LazyAttributeSequence(lambda o, n: f"{o.name_base} {n}")
    description = factory.Faker("paragraph")

    gm = factory.Faker("pybool")
    location = factory.SubFactory("booking.tests.factories.LocationFactory")
    stock_value = factory.Faker("pyfloat")
    stock_unit = factory.Faker("word")

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

        if extracted:
            # A list of groups were passed in, use them
            for category in extracted:
                self.categories.add(category)

    rate_class = factory.SubFactory("booking.tests.factories.RateClassFactory")
    images = factory.RelatedFactoryList(
        "booking.tests.factories.MaterialImageFactory",
        factory_related_name="material")
    attachments = factory.RelatedFactoryList(
        "booking.tests.factories.MaterialAttachmentFactory",
        factory_related_name="material",
    )
    aliases = factory.RelatedFactoryList(
        "booking.tests.factories.MaterialAliasFactory",
        factory_related_name="material")
Esempio n. 22
0
class FoeFactory(DjangoModelFactory):
    opponent = factory.fuzzy.FuzzyText()
    competition = factory.fuzzy.FuzzyText()
    logo = SimpleUploadedFile(image_file.name,
                              image_file.read(),
                              content_type="image/jpg")
    background_color = random_hex_color()
    accent_color = random_hex_color()
    text_color = random_hex_color()
    season = factory.fuzzy.FuzzyText()
    active = factory.fuzzy.FuzzyInteger(low=0, high=1)
    players = factory.RelatedFactoryList(FoePlayerFactory, "foe")

    class Meta:
        model = Foe
Esempio n. 23
0
class LearningResourceFactory(DjangoModelFactory):
    """Factory for LearningResource subclasses"""

    title = factory.Faker("word")
    short_description = factory.Faker("sentence")

    topics = factory.PostGeneration(_post_gen_topics)
    offered_by = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceOfferorFactory", size=1)

    class Meta:
        abstract = True

    class Params:
        no_topics = factory.Trait(topics=[])
Esempio n. 24
0
class PlayerFactory(DjangoModelFactory):

    name = factory.fuzzy.FuzzyText()
    country = factory.Faker("country_code")
    position = factory.fuzzy.FuzzyChoice([x[0] for x in Position.choices])
    squad_number = randint(0, 100)
    thumbnail = SimpleUploadedFile(image_file.name,
                                   image_file.read(),
                                   content_type="image/png")
    team = factory.fuzzy.FuzzyText()
    twitter = factory.fuzzy.FuzzyText()
    instagram = factory.fuzzy.FuzzyText()
    images = factory.RelatedFactory(PlayerImageFactory, "player")
    bios = factory.RelatedFactoryList(PlayerBioFactory, "player")

    class Meta:
        model = Player
Esempio n. 25
0
class CourseFactory(AbstractCourseFactory):
    """Factory for Courses"""

    course_id = factory.Sequence(lambda n: "COURSE%03d.MIT" % n)
    platform = FuzzyChoice((
        PlatformType.mitx.value,
        PlatformType.ocw.value,
        PlatformType.micromasters.value,
        PlatformType.xpro.value,
        PlatformType.oll.value,
        PlatformType.bootcamps.value,
    ))
    runs = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceRunFactory",
        "content_object",
        size=3)

    class Meta:
        model = Course
Esempio n. 26
0
class EventFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = "events.Event"

    class Params:
        has_store = factory.LazyAttribute(
            lambda o: o.event_type in EVENT_TYPES_ABOUT_STORE)

    event_type = factory.Faker(
        "random_element",
        elements=[choice[0] for choice in EVENT_TYPE_CHOICES])
    description = factory.Sequence(lambda n: f"event_{n}")
    store = factory.Maybe(
        "has_store",
        yes_declaration=factory.SubFactory(StoreFactory),
        no_declaration=None,
    )
    inventory_changes = factory.RelatedFactoryList(
        InventoryChangeFactory,
        factory_related_name="event",
    )
Esempio n. 27
0
class ListingFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = models.Listing

    title = factory.LazyFunction(fake_hotel_name)
    listing_type = models.Listing.HOTEL
    country = factory.Faker("country")
    city = factory.Faker("city")

    class Params:
        apartment = factory.Trait(
            listing_type=models.Listing.APARTMENT,
            booking_info=factory.RelatedFactory(
                BookingInfoFactory,
                "listing",
                price=factory.LazyFunction(
                    lambda: random.choice(PRICE_CHOICES))),
            hotel_room_types=None,
            title=factory.LazyFunction(fake_apartment_name))

    hotel_room_types = factory.RelatedFactoryList(
        HotelRoomTypeFactory, "hotel", size=lambda: random.randint(1, 3))
Esempio n. 28
0
class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = get_user_model()

    class Params:
        email_base = factory.Faker("safe_email")

    email = factory.LazyAttributeSequence(lambda o, n: f"{n}{o.email_base}")
    first_name = factory.Faker("first_name")
    last_name = factory.Faker("last_name")
    group = factory.SubFactory(GroupFactory)

    # Role
    groups = factory.RelatedFactoryList("users.tests.factories.RoleFactory",
                                        size=1,
                                        factory_related_name="user")

    @factory.post_generation
    def password(self, create, extracted, **kwargs):
        if extracted is None:
            self.password = UserFactory.PASSWORD
        else:
            self.password = make_password(extracted)
Esempio n. 29
0
class VideoFactory(LearningResourceFactory):
    """Factory for Video"""

    video_id = factory.Sequence(lambda n: "VIDEO-%03d.MIT" % n)
    platform = FuzzyChoice([PlatformType.youtube.value])

    full_description = factory.Faker("text")
    image_src = factory.Faker("image_url")

    last_modified = factory.Faker("past_datetime", tzinfo=pytz.utc)

    url = factory.Faker("uri")

    transcript = factory.Faker("text")

    offered_by = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceOfferorFactory",
        size=1,
        name=OfferedBy.ocw.value,
    )

    class Meta:
        model = Video
Esempio n. 30
0
class PlaylistFactory(LearningResourceFactory):
    """Factory for Playlist"""

    playlist_id = factory.Sequence(lambda n: "VIDEO-PLAYLIST-%03d.MIT" % n)
    platform = FuzzyChoice([PlatformType.youtube.value])

    image_src = factory.Faker("image_url")
    url = factory.Faker("image_url")
    published = True

    offered_by = factory.RelatedFactoryList(
        "course_catalog.factories.LearningResourceOfferorFactory",
        size=1,
        name=OfferedBy.ocw.value,
    )

    channel = factory.SubFactory(
        "course_catalog.factories.VideoChannelFactory")

    has_user_list = False
    user_list = None

    class Meta:
        model = Playlist