def setUp(self): self.structure_type = StructureTypeFactory(child_depth=2) self.structure = StructureFactory(child_depth=2, structure_type=self.structure_type) self.stock = mixer.blend('stock_setup_info.models.Stock', structure=self.structure) self.p_date1 = datetime(year=2014, month=11, day=15, hour=0, minute=0, second=0) self.price_list = mixer.blend('stock_maintain.models.PriceList', stock=self.stock, price_date=self.p_date1) self.p_date = datetime(year=2014, month=11, day=15, hour=0, minute=0, second=0) PriceListFactory.create_batch(20, stock=self.stock, price_date=self.p_date, sec_code=self.stock.stock_code)
def setUp(self): self.structure_type = StructureTypeFactory(child_depth=2) self.structure = StructureFactory(child_depth=2, structure_type=self.structure_type) self.stock = mixer.blend('stock_setup_info.models.Stock', structure=self.structure) self.news = mixer.blend('stock_maintain.models.News', content='Hello this is the main news', stock=self.stock)
def setUp(self): self.structure_type = StructureTypeFactory(child_depth=2) self.structure = StructureFactory(child_depth=2, structure_type=self.structure_type) self.stock = mixer.blend('stock_setup_info.models.Stock', structure=self.structure) self.news = mixer.blend('stock_maintain.models.News', news_section=self.structure, stock=self.stock) self.news_image = mixer.blend('stock_maintain.models.News', news_section=self.structure, stock=self.stock)
def test_sqlalchemy(): from mixer.auto import mixer from .test_sqlalchemy import User user = mixer.blend(User) assert user user = mixer.blend('tests.test_sqlalchemy.User') assert user users = mixer.cycle(2).blend(User) assert all(users)
def test_sqlalchemy(self): from mixer.auto import mixer from .test_sqlalchemy import User user = mixer.blend(User) self.assertTrue(user) user = mixer.blend('tests.test_sqlalchemy.User') self.assertTrue(user) users = mixer.cycle(2).blend(User) self.assertTrue(all(users))
def test_mongoengine(self): from mixer.auto import mixer from .test_mongoengine import User user = mixer.blend(User) self.assertTrue(user) user = mixer.blend('tests.test_mongoengine.User') self.assertTrue(user) users = mixer.cycle(2).blend(User) self.assertTrue(all(users))
def test_mongoengine(self): from mixer.backend.mongoengine import mixer as m m.params['commit'] = False from mixer.auto import mixer from .test_mongoengine import User user = mixer.blend(User) self.assertTrue(user) user = mixer.blend('tests.test_mongoengine.User') self.assertTrue(user) users = mixer.cycle(2).blend(User) self.assertTrue(all(users))
def setUp(self): # self.stock = StockFactory() self.structure_type = StructureTypeFactory(child_depth=2) self.structure = StructureFactory(child_depth=2, structure_type=self.structure_type) self.stock = mixer.blend('stock_setup_info.models.Stock', structure=self.structure)
def test_django(self): from django.core.management import call_command from mixer.auto import mixer from .django_app.models import Rabbit call_command('syncdb', interactive=False) rabbit = mixer.blend(Rabbit) self.assertTrue(rabbit) rabbit = mixer.blend('tests.django_app.models.Rabbit') self.assertTrue(rabbit) rabbits = mixer.cycle(2).blend(Rabbit) self.assertTrue(all(rabbits)) call_command('flush', interactive=False)
def test_django(): from django.core.management import call_command from mixer.auto import mixer from .django_app.models import Rabbit call_command('migrate', interactive=False) rabbit = mixer.blend(Rabbit) assert rabbit rabbit = mixer.blend('tests.django_app.models.Rabbit') assert rabbit rabbits = mixer.cycle(2).blend(Rabbit) assert all(rabbits) call_command('flush', interactive=False)
def setUp(self): self.structure_type = StructureTypeFactory(child_depth=2) self.structure = StructureFactory(child_depth=2, structure_type=self.structure_type) self.stock = mixer.blend('stock_setup_info.models.Stock', structure=self.structure) self.news = mixer.blend('stock_maintain.models.News', stock=self.stock) NewsFactory.create_batch(10, stock=self.stock, is_featured=False) NewsFactory.create_batch(10, stock=self.stock, is_featured=True) self.main_featured_news = News.objects.filter( is_featured=True).latest('id') self.main_featured_news.is_main = True self.p_date = datetime(year=2014, month=11, day=15, hour=0, minute=0, second=0)
def setUp(self): self.structure_type = StructureTypeFactory(child_depth=2) self.structure = StructureFactory(child_depth=2, structure_type=self.structure_type) self.analysis = mixer.blend('stock_maintain.models.AnalysisOpinion') self.p_date = datetime(year=2014, month=11, day=15, hour=0, minute=0, second=0) AnalysisOpinionFactory.create_batch(10, opinion_date=self.p_date)
def test_view_analysis_existing(self): """ This test ensures that proper error is shown for non existing news """ name_for_section = 'World' analysis_section = StructureFactory(child_depth=2, structure_type=self.structure_type, structure_name=name_for_section) analysis_for_section = mixer.blend( 'stock_maintain.models.AnalysisOpinion') AnalysisCategorySectionFactory(analysis=analysis_for_section, section=analysis_section) response = self.client.get( reverse("analysis-detail", args=[analysis_for_section.id]), ) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_news_by_section_with_valid_data(self): name_for_section = 'World' news_section = StructureFactory(child_depth=2, structure_type=self.structure_type, structure_name=name_for_section) news_for_section = mixer.blend('stock_maintain.models.News', stock=self.stock) NewsCategorySectionFactory(news=news_for_section, section=news_section) response = self.client.get(reverse("news-list-by-section"), {'section_list': name_for_section}) search_array = name_for_section.split(',') news_by_section = News.objects.filter( category_news__section__structure_name__in=search_array) n_count = news_by_section.count() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), n_count)
def handle(self, *args, **options): """ Remove existing data """ UsersData.objects.all().delete() self.stdout.write(self.style.SUCCESS("All the existing users cleared")) """ Generate mock data """ timezones = pytz.all_timezones mock_user_count = 10 for i in range(0, mock_user_count): user = UsersData.objects.create(name=fake.name(), tz=random.choice(timezones)) mock_activity_factors_count = random.randint(1, 5) for j in range(0, mock_activity_factors_count): _ = mixer.blend(UsersActivityPeriodsData, user=user) self.stdout.write( self.style.SUCCESS("Added " + str(mock_user_count) + "new users with their activity periods of " "total 1-5 (Random)"))
def test_model_via_mixer(self): obj = mixer.blend('stock_setup_info.models.Industry') assert obj.pk > 1, 'Should create an Industry Instance'
def test_get_detail(self): user = mixer.blend(ToDoUser) response = self.client.get(f'/api/v1/users/{user.id}/') self.assertEqual(response.status_code, status.HTTP_200_OK)
def setUp(self): self.analysis = mixer.blend('stock_maintain.models.AnalysisOpinion', content='Hello this is the main analysis')
def __call__(cls, model, **params): return mixer.blend(model, **params)