class PriceTestCase(TestCase): ''' Test suite for price model ''' def setUp(self): User = get_user_model() self.shop = Shop(name='hexαδακτυλος', address='Αριστοφανους 32', coordinates=Point(22.18339, 39.89279)) self.shop.save() self.product = Product(name='Αντρικιο', description='Γυναικειο', category='κουρεμα') self.product.save() userinfo = dict(username='******', password='******') self.user = User(**userinfo) self.user.save() grp, _ = Group.objects.get_or_create(name='Volunteer') self.user.groups.add(grp) self.entry = Price(shop=self.shop, product=self.product, user=self.user, price=10.0) def test_can_add_price(self): ''' check if adding price works ''' prev_count = Price.objects.count() self.entry.save() self.assertEqual(Price.objects.count(), prev_count + 1) def test_can_use_add_price(self): res = Price.add_price(shop=self.shop, product=self.product, user=self.user, date_to=Price.parse_date('2018-10-10'), date_from=Price.parse_date('2018-09-09'), price=10.0) self.assertTrue(res) self.assertEqual(Price.objects.count(), 1)
def setUp(self): User = get_user_model() self.factory = ApiRequestFactory() self.view = ParseUrlEncodedParametersMiddleware(PricesView.as_view()) # create two shops self.shop = Shop(id=10, name='hexαδακτυλος', address='Αριστοφανους 32', coordinates=Point(22.18339, 39.89279)) self.shop_away = Shop(id=11, name='χεξadaktylos', address='Devils horn', coordinates=Point(10, 10)) self.shop.save() self.shop_away.save() # add a few tags shoptag = ShopTag('shoptag') shoptag.save() self.shop.tags.add(shoptag) self.shop.save() commontag_shop = ShopTag('commontag') commontag_shop.save() self.shop_away.tags.add(commontag_shop) self.shop_away.save() # create two products self.product = Product(id=20, name='Αντρικιο', description='Γυναικειο', category='κουρεμα') self.product.save() self.product_2 = Product(id=21, name='λαδι μαλλιων', description='αντρικο', category='αναλωσιμο') self.product_2.save() # add tags producttag = ProductTag('producttag') producttag.save() self.product_2.tags.add(producttag) self.product_2.save() commontag_prod = ProductTag('commontag') commontag_prod.save() self.product.tags.add(commontag_prod) self.product.save() # create a user userinfo = dict(username='******', password='******') self.user = User(**userinfo) self.user.save() # add a few prices price_1 = Price(shop=self.shop, product=self.product, user=self.user, date_from=Price.parse_date('2018-10-15'), date_to=Price.parse_date('2018-10-20'), price=10) price_1.save() price_2 = Price(shop=self.shop_away, product=self.product, user=self.user, date_from=Price.parse_date('2018-10-16'), date_to=Price.parse_date('2018-10-21'), price=20) price_2.save() price_3 = Price(shop=self.shop, product=self.product_2, user=self.user, date_from=Price.parse_date('2018-10-10'), date_to=Price.parse_date('2018-10-23'), price=20) price_3.save()