def setUp(self): super().setUp() self.category = CategoryFactory() self.client_1 = ClientFactory() AccountFactory.create(user=self.user, client=self.client_1) self.product_1, self.product_2 = ProductFactory.create_batch(2, category=self.category) self.feature_1 = FeatureFactory(name='Wireless', product=self.product_2, shared_image=SharedImageFactory(image=ImageField(filename='wireless.jpg'))) self.feature_2, self.feature_3 = FeatureFactory.create_batch(2, product=self.product_2) price_1 = ClientPriceFactory(client=self.client_1, product=self.product_1, unit_cost=200, system_cost=300) price_2 = ClientPriceFactory(client=self.client_1, product=self.product_2, unit_cost=250, system_cost=300) ClientPriceFactory(client=self.client_1, unit_cost=250, system_cost=300, product=ProductFactory(enabled=False),) self.discount_1 = DiscountFactory( client_price=price_1, discount_type=VALUE_DISCOUNT, value=50, name='CCO', order=1, percent=0, apply_type=ON_DOCTOR_ORDER, cost_type=UNIT_COST, shared_image=SharedImageFactory(image=ImageField(filename='CCO.png')) ) self.discount_2 = DiscountFactory( client_price=price_2, discount_type=PERCENT_DISCOUNT, percent=10, cost_type=SYSTEM_COST, order=2, apply_type=ON_DOCTOR_ORDER, name='Repless', shared_image=SharedImageFactory(image=ImageField(filename='repless.png')) ) self.discount_3 = DiscountFactory( client_price=price_1, discount_type=PERCENT_DISCOUNT, value=0, name='Bulk', order=2, percent=15, apply_type=PRE_DOCTOR_ORDER, cost_type=UNIT_COST, shared_image=None) device = self.client_1.device_set.get(product=self.product_1) ItemFactory(device=device, discounts=[self.discount_3], purchase_type=BULK_PURCHASE, is_used=False, cost_type=UNIT_COST) self.path = reverse('api:hospital:device:products', args=(self.client_1.id, self.category.id,))
def setUp(self): self.client_1, self.client_2 = ClientFactory.create_batch(2) manufacturer = ManufacturerFactory(image=ImageField( filename='biotronik.jpg')) product = ProductFactory(manufacturer=manufacturer) self.item_1 = ItemFactory(cost=randint(110, 150), cost_type=UNIT_COST, device=DeviceFactory(client=self.client_1, product=product)) self.item_2 = ItemFactory(cost=randint(210, 290), cost_type=UNIT_COST, device=DeviceFactory(client=self.client_1)) self.item_3 = ItemFactory(cost=randint(400, 500), device=DeviceFactory(client=self.client_2)) self.item_4 = ItemFactory(cost=1000, cost_type=UNIT_COST, device=DeviceFactory( client=self.client_1, product=ProductFactory( manufacturer=manufacturer, category=product.category))) physician_role = RoleFactory(priority=RolePriority.PHYSICIAN.value) self.physician_1 = AccountFactory(client=self.client_1, role=physician_role) self.physician_2 = AccountFactory(client=self.client_2, role=physician_role, user=self.physician_1.user) self.physician_3 = AccountFactory(client=self.client_1, role=physician_role)
def handle(self, *args, **options): """Populate database with fake objects.""" self.stdout.write(self.style.SUCCESS('Creating 15 organizations')) for _ in tqdm(range(15)): organization = OrganizationFactory.create() UserProfileFactory.create(organizations=(organization, ), ) self.stdout.write(self.style.SUCCESS('Creating 50 offers')) for _ in tqdm(range(50)): OfferFactory.create( organization=random.choice(Organization.objects.all()), image__path=ImageField( from_func=placeimg_com_download(1000, 400, 'any'))) self.stdout.write(self.style.SUCCESS('Creating 150 volunteers')) for _ in tqdm(range(150)): userprofile = UserProfileFactory.create() no_of_offers = random.randrange(10) for offer in random.sample(list(Offer.objects.all()), no_of_offers): offer.volunteers.add(userprofile.user) self.stdout.write( self.style.SUCCESS('Database successfully populated'))
class ProfileMemberFactory(CleanModelFactory): name = FuzzyText() role = FuzzyText() image = ImageField() class Meta: model = ProfileMember
class ArticleFactory(DjangoModelFactory): title = Sequence(lambda n: f'Статья {n}') text = Faker('text', max_nb_chars=1000) image = ImageField() class Meta: model = 'articles.Article'
class OfferImageFactory(factory.DjangoModelFactory): """Factory for OfferImage.""" class Meta: # pylint: disable=C0111 model = OfferImage is_main = True path = ImageField(from_func=placeimg_com_download(1000, 400, 'any'))
class DummyImageFactory(factory.DjangoModelFactory): class Meta: model = get_image_model() title = factory.LazyAttribute(fake_title) file = ImageField(from_path=os.path.join(settings.BASE_DIR, 'core', 'static', 'img', 'dummy.jpg'))
class ImageFactory(CleanModelFactory): caption = FuzzyText() image = ImageField() gallery = SubFactory(GalleryFactory) class Meta: model = Image
class ProjectFactory(factory.django.DjangoModelFactory): FACTORY_FOR = Project name = factory.Sequence(lambda n: 'name%s' % n) url = factory.Sequence(lambda n: 'www.rosedu%s.org' % n) description = factory.Sequence(lambda n: 'description%s' % n) logo = ImageField()
def test_uploading_filepath_exists(self): SharedImageFactory(name='shock', image=ImageField(filename='test_image.png')) uploading_filename = make_imagefield_filepath('shared', self.instance, 'test_image.png') self.assertRegex(uploading_filename, r'shared\/test_image-\d+\.png') rmtree(settings.MEDIA_ROOT)
class AchievementFactory(DjangoModelFactory): class Meta: model = Achievement code = UniqueFaker('bban') name = Faker('job') image = ImageField(filename='achievement_icon.png') description = UniqueFaker('sentence')
class PersonsFactory(factory.DjangoModelFactory): FACTORY_FOR = Persons kinopoisk_id = factory.Sequence(lambda i: i) name = factory.Sequence(lambda n: u'Персона_{0}'.format(n)) bio = factory.Sequence(lambda n: u'Биография_{0}'.format(n)) photo = ImageField(color='red') birthdate = datetime.datetime.now() city = factory.SubFactory(CitiesFactory)
class ApplicantFactory(DjangoModelFactory): user = SubFactory(UserFactory) about = Faker('text') biography = Faker('text') speaker_experience = Faker('text') image = ImageField() class Meta: model = Applicant
class CharityFactory(DjangoModelFactory): name = Faker("company") link = Faker("url") description = Faker("text", max_nb_chars=1000) how_to_donate = Faker("text", max_nb_chars=300) logo = ImageField() class Meta: model = Charity
class CuratorFactory(DjangoModelFactory): user = factory.SubFactory(UserFactory) actor = None title = 'visuomenės veikėjas' photo = ImageField() class Meta: model = models.Curator django_get_or_create = ('user',)
def generate_dummy_image(_unused): """ Used for image fields to create a sane default. """ return ContentFile( ImageField()._make_data( # pylint: disable=protected-access {'color': 'blue', 'width': 50, 'height': 50, 'format': 'PNG'} ), 'test.png' )
class ImageWithTextFactory(CleanModelFactory): title = FuzzyText() content = FuzzyText() image = ImageField() background = FuzzyChoice([i[0] for i in BACKGROUND_CHOICES]) align = FuzzyChoice([i[0] for i in ALIGNMENT_CHOICES]) class Meta: model = ImageWithText
class FeatureFactory(CleanModelFactory): title = FuzzyText() content = FuzzyText() align = FuzzyChoice([i[0] for i in ALIGNMENT_CHOICES]) background = FuzzyChoice([i[0] for i in BACKGROUND_CHOICES]) text_size = FuzzyChoice([i[0] for i in TEXT_SIZE_CHOICES]) image = ImageField() class Meta: model = Feature
class QuoteFactory(CleanModelFactory): quote = FuzzyText() author = FuzzyText() align = FuzzyChoice([i[0] for i in ALIGNMENT_CHOICES]) background = FuzzyChoice([i[0] for i in BACKGROUND_CHOICES]) text_size = FuzzyChoice([i[0] for i in TEXT_SIZE_CHOICES]) image = ImageField() class Meta: model = Quote
class BadgeImageConfigurationFactory(DjangoModelFactory): FACTORY_FOR = BadgeImageConfiguration mode = 'honor' icon = ImageField(color='blue', height=50, width=50, filename='test.png', format='PNG')
class UserFactory(factory.django.DjangoModelFactory): class Meta: model = User name = factory.Faker("name") email = factory.LazyAttribute( lambda o: '*****@*****.**' % o.name.replace(" ", ".")) role = FuzzyChoice([obj[0] for obj in Config.CHOICES]) profile_image = ImageField(filename="new_image.jpg") password = factory.PostGenerationMethodCall('set_password', 'test_pass')
class ProfileFactory(DjangoModelFactory): """Factory for Profiles""" name = Faker("name") image = Faker("file_path", extension="jpg") image_small = Faker("file_path", extension="jpg") image_medium = Faker("file_path", extension="jpg") image_file = ImageField() image_small_file = ImageField() image_medium_file = ImageField() email_optin = Faker("boolean") location = Faker("location") class Meta: model = Profile
class ImageFactory(CollectionMemberFactory): """ Custom image factory that is almost exactly like the default image factory, except all images are part of the Root collection, rather than each image being its own collection. """ class Meta: model = get_image_model() title = "An image" file = ImageField()
class PartyActorFactory(DjangoModelFactory): first_name = 'Lietuvos Žaliųjų Partija' last_name = '' title = 'politinė partija' photo = ImageField() group = True body = factory.SubFactory(BodyFactory, name='Seimas') class Meta: model = models.Actor django_get_or_create = ('first_name',)
class PersonActorFactory(DjangoModelFactory): first_name = 'Mantas' last_name = 'Adomėnas' title = 'seimo narys' photo = ImageField() group = False body = None class Meta: model = models.Actor django_get_or_create = ('first_name', 'last_name')
class OfferImageFactory(factory.DjangoModelFactory): """Factory for OfferImage.""" class Meta: # pylint: disable=C0111 model = OfferImage is_main = True path = ImageField(from_path=os.path.join( os.path.dirname(__file__), 'frontend/img/volontulo_baner.png' ))
class OrganizationFactory(DjangoModelFactory): name = factory.Sequence(lambda n: f"{faker.word()} #{n}") picture = LazyAttribute( lambda _: ContentFile( ImageField()._make_data({"width": 1024, "height": 768}), "example.jpg", ) ) class Meta: model = Organization
def setUp(self): super().setUp() self.product = ProductFactory() self.shared_image = SharedImageFactory(name='url', image=ImageField(filename='test_image.jpg')) self.category_feature = CategoryFeatureFactory(name='website', category=self.product.category) self.feature_1 = FeatureFactory(name='size', value='24/11', product=self.product, category_feature=None) self.feature_2 = FeatureFactory(name='website', value='http://biotronik.com', shared_image=self.shared_image, category_feature=self.category_feature, product=self.product) self.feature_3 = FeatureFactory(name='shock', value='yes', shared_image=self.shared_image, product=self.product, category_feature=None) FeatureFactory(product=self.product, value=None) self.path = reverse('api:device:features', args=(self.product.id,))
class PostFactory(DjangoModelFactory): class Meta: model = Post author = SubFactory(UserFactory) title = LazyFunction(lambda: fake.text(randint(5, 20))) picture = ImageField(color=choice(['blue', 'yellow', 'green', 'orange']), height=randint(250, 1000), width=randint(250, 1000), ) text = LazyFunction(lambda: fake.text(randint(200, 3000))) created_at = LazyFunction(lambda: now() - delta(days=365))
class PropertyFactory(DjangoModelFactory): class Meta: model = Property title = Sequence(lambda x: u'title %d' % x) description = Sequence(lambda x: u'description %d' % x) slug = LazyAttribute(lambda a: slugify(a.title)) address = Sequence(lambda x: u'address %d' % x) image = ImageField(color='blue') is_available = True price = 7 created_by = SubFactory(UserFactory)