def setUp(self): self.client = Client() self.user = User.objects.create_user('testuser1', '*****@*****.**', '12345') deal = set_advertiser_and_category() self.deal = Deal(**deal) self.deal.save()
def create_deal(self): """Create the test deal""" merchant = self.create_merchant() price = 5000 original_price = 6000 currency = 1 country = 2 location = self.get_location() quorum = 0 disclaimer = '' description = 'Holiday for two to the luxurious Masai Mara.' title = 'Masai Mara Holiday' title2 = 'Beach holiday' address = 'Masai Mara' max_quantity_available = 20 active = True advertiser_id = merchant.advertiser_ptr.id date_end = "2020-09-09" category = Category.objects.create(name="Travel N Hotels", slug="masai-mara-holiday") advertiser = Advertiser.objects.get(id=advertiser_id) deal = Deal( price=price, original_price=original_price, currency=currency, country=country, location=location, category=category, quorum=quorum, disclaimer=disclaimer, description=description, address=address, max_quantity_available=max_quantity_available, date_end=date_end, active=active, title=title, advertiser=advertiser, duration=20 ) deal.save()
def test_unique_vote_up(self): """ A user vote on a deal should raise the temperature """ #Preparation myDeal = Deal() myDeal.title_text = "This is a fake product only for testing purposes" myDeal.link_url = "http://www.amazon.com" myDeal.vendor_text = "Amazon" myDeal.price_decimal = 10.3 myDeal.description_text = "Lorem Ipsum Dolor sit amet esperum funcionorum perfectunum" myDeal.imageUrl_url = "http://www.amazon.com" myDeal.save() myUser = User() myUser.username = "******" myUser.save() myProfile = Profile() myProfile.user = myUser myProfile.save() currentVotes = myDeal.temperature #Action voteOutput = myDeal.upvote(myUser.id) #Review self.assertEqual(voteOutput, True) self.assertEqual((currentVotes < myDeal.temperature), True)
class ViewCartRouteTestCase(TestCase): """Tests view cart route.""" def setUp(self): self.client = Client() self.user = User.objects.create_user('testuser1', '*****@*****.**', '12345') deal = set_advertiser_and_category() self.deal = Deal(**deal) self.deal.save() def test_get_cart_items(self): response = self.client.post( reverse('login'), dict(username='******', password='******')) self.assertEqual(response.status_code, 302) self.assertIsInstance(response, HttpResponseRedirect) data = {"dealid": 1} res = self.client.post(reverse('add'), data) self.assertEqual(res.status_code, 302) cart_response = self.client.get(reverse('view')) self.assertEqual(cart_response.status_code, 200) def tearDown(self): del self.client
def setUp(self): advertiser = Advertiser(name="XYZ Stores") advertiser.save() category = Category(name="Books") category.save() deal = Deal( title="Deal #1", description="Deal some...deal all!", disclaimer="Deal at your own risk", advertiser=advertiser, address="14, Alara Street", country=1, location=25, category=category, original_price=1500, price=750, duration=15, active=1, max_quantity_available=3, featured=True, ) deal.save() user = User(username="******", password="******") user.save() self.ticket = dict(user=user, item=deal, quantity=1, advertiser=advertiser, ticket_id="98329u093ru032r")
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select('/html/body/div[4]/div[2]/div/div[2]/div/div[2]/h1/text()').extract() price = hxs.select('/html/body/div[4]/div[2]/div/div[2]/div/div[2]/div/div/p/strong/text()').extract() #description = hxs.select('/html/body/div[4]/div[2]/div/div[2]/div/div[3]/div/div[2]/div/div/p[2]/text()').extract() url = ['http://www.shiokdeal.com/',] deal = Deal(title=title[0].encode('ascii', 'ignore').strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select('/html/body/div/div[9]/div/div/div/div/h1/a/text()').extract() price = hxs.select('/html/body/div/div[9]/div/div/div/div[2]/form/div/span/span/text()').extract() #description = hxs.select('/html/body/div/div[9]/div/div[3]/div[2]/div[2]/p[2]/text()').extract() url = ['http://www.groupon.sg/',] deal = Deal(title=title[0].encode('ascii', 'ignore').strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title =hxs.select('/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div/a/h2/span/text()').extract() price = hxs.select('/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div[2]/div/div[2]/div/p/text()').extract() #description = hxs.select('/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div/a/h2/span/text()').extract() url = hxs.select('/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div/a/@href').extract() deal = Deal(title=title[0].encode('ascii', 'ignore').strip(), price=price[0].strip(), url= 'http://www.voucherwow.com' + url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select('/html/body/div/div/div[3]/div/div/div[2]/div/div/div/div/div/div/div/a/text()').extract() price = hxs.select('/html/body/div/div/div[3]/div/div/div[2]/div/div/div/div/div/div/div[2]/div/div/span[2]/text()').extract() #description = hxs.select('/html/body/div/div[2]/div/div[3]/div/div[2]/div/div/p[13]/text()').extract() url = hxs.select('/html/body/div/div/div[3]/div/div/div[2]/div/div/div/div/div/div/div/a/@href').extract() deal = Deal(title=title[0].encode('ascii', 'ignore').strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select("/html/body/div[4]/div[2]/div/div[2]/div/div[2]/h1/text()").extract() price = hxs.select("/html/body/div[4]/div[2]/div/div[2]/div/div[2]/div/div/p/strong/text()").extract() # description = hxs.select('/html/body/div[4]/div[2]/div/div[2]/div/div[3]/div/div[2]/div/div/p[2]/text()').extract() url = ["http://www.shiokdeal.com/"] deal = Deal(title=title[0].encode("ascii", "ignore").strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select("/html/body/div/div[9]/div/div/div/div/h1/a/text()").extract() price = hxs.select("/html/body/div/div[9]/div/div/div/div[2]/form/div/span/span/text()").extract() # description = hxs.select('/html/body/div/div[9]/div/div[3]/div[2]/div[2]/p[2]/text()').extract() url = ["http://www.groupon.sg/"] deal = Deal(title=title[0].encode("ascii", "ignore").strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select('/html/body/div[@id="ext-wrapper"]/div[@id="wrapper"]/div[@id="main"]/div[@class="content-wrap"]/h1/text()').extract() price = hxs.select('/html/body/div[@id="ext-wrapper"]/div[@id="wrapper"]/div[@id="main"]/div[@class="content-wrap"]/div[2]/div[@class="deal-wrap"]/div[@class="d-wi"]/div[@class="d-price"]/div[@class="d-price-value"]/text()').extract() #description = hxs.select('/html/body/div[@id="ext-wrapper"]/div[@id="wrapper"]/div[@id="main"]/div[@class="content-wrap"]/div[2]/div[@class="deal-wrap"]/div[@class="d-desc"]/div[[2]/div[1]/div[1]/p/text()').extract() url = ['http://www.alldealsasia.com',] deal = Deal(title=title[0].encode('ascii', 'ignore').strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select("/html/body/div/div/div[3]/div/div/div[2]/div/div/div/div/div/div/div/a/text()").extract() price = hxs.select( "/html/body/div/div/div[3]/div/div/div[2]/div/div/div/div/div/div/div[2]/div/div/span[2]/text()" ).extract() # description = hxs.select('/html/body/div/div[2]/div/div[3]/div/div[2]/div/div/p[13]/text()').extract() url = hxs.select("/html/body/div/div/div[3]/div/div/div[2]/div/div/div/div/div/div/div/a/@href").extract() deal = Deal(title=title[0].encode("ascii", "ignore").strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select("/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div/a/h2/span/text()").extract() price = hxs.select("/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div[2]/div/div[2]/div/p/text()").extract() # description = hxs.select('/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div/a/h2/span/text()').extract() url = hxs.select("/html/body/div[1]/div/div[3]/div/div[2]/div[2]/div/a/@href").extract() deal = Deal( title=title[0].encode("ascii", "ignore").strip(), price=price[0].strip(), url="http://www.voucherwow.com" + url[0].strip(), ) deal.save()
def parse(self, response): hxs = HtmlXPathSelector(response) title = hxs.select( '/html/body/div[@id="ext-wrapper"]/div[@id="wrapper"]/div[@id="main"]/div[@class="content-wrap"]/h1/text()' ).extract() price = hxs.select( '/html/body/div[@id="ext-wrapper"]/div[@id="wrapper"]/div[@id="main"]/div[@class="content-wrap"]/div[2]/div[@class="deal-wrap"]/div[@class="d-wi"]/div[@class="d-price"]/div[@class="d-price-value"]/text()' ).extract() # description = hxs.select('/html/body/div[@id="ext-wrapper"]/div[@id="wrapper"]/div[@id="main"]/div[@class="content-wrap"]/div[2]/div[@class="deal-wrap"]/div[@class="d-desc"]/div[[2]/div[1]/div[1]/p/text()').extract() url = ["http://www.alldealsasia.com"] deal = Deal(title=title[0].encode("ascii", "ignore").strip(), price=price[0].strip(), url=url[0].strip()) deal.save()
def create_deal(request): context = RequestContext(request) if request.method == 'POST': company_form = CompanyForm(request.POST) deal_form = DealForm(request.POST) if company_form.is_valid() and deal_form.is_valid(): comp = company_form.save(commit=True) deal = Deal(body=request.POST['body'], company_id=comp.pk) deal.save() return redirect('deals.views.twitter') else: print company_form.errors print deal_form.errors else: company_form = CompanyForm() # Need to investigate this further! deal_form = DealForm()
def test_can_create_read_update_delete_deal(self): # create a deal record deal = Deal(**self.deal) deal.save() self.assertIsNotNone(deal.id, None) # test a deal record has been added deal = Deal.objects.get(id=deal.id) self.assertIsNotNone(deal.id) # update a deal record new_deal_title = 'Deal #2' deal = Deal.objects.get(id=deal.id) deal.title = new_deal_title deal.save() self.deal['title'] = new_deal_title # Update deal title for next test self.assertEquals(deal.title, new_deal_title) # delete a deal record deal = Deal.objects.get(id=deal.id) Deal.delete(deal) with self.assertRaises(Deal.DoesNotExist) as context: Deal.objects.get(**self.deal) self.assertTrue("does not exist" in context.exception.message)
def setUpClass(cls): deal = set_advertiser_and_category() cls.deal = Deal(**deal) cls.deal.save() cls.user = User.objects.create_user('testuser1', '*****@*****.**', '12345') is_merchant = cls.user.profile.is_approved_merchant() if not is_merchant: cls.merchant = Merchant(advertiser_ptr=cls.deal.advertiser, userprofile=cls.user.profile, enabled=True, approved=True, intlnumber='123456789') cls.merchant.save() super(OrderModelTestCase, cls).setUpClass()
def setUpClass(cls): deal = set_advertiser_and_category() deal['title'] = 'Deal #3' # dictionary cls.deal = Deal(**deal) cls.deal.save() cls.user = User.objects.create_user('testuser3', '*****@*****.**', '123456') is_merchant = cls.user.profile.is_approved_merchant() if not is_merchant: cls.merchant = Merchant(advertiser_ptr=cls.deal.advertiser, userprofile=cls.user.profile, enabled=True, approved=True, intlnumber='123456789') cls.merchant.save() cls.selenium = webdriver.Chrome() cls.wait = ui.WebDriverWait(cls.selenium, 10) super(SalesHistoryAndTrendTestCase, cls).setUpClass()
def setUpClass(cls): Deal.objects.all().delete() User.objects.all().delete() deal = set_advertiser_and_category() # dictionary cls.deal = Deal(**deal) cls.deal.save() cls.user = User.objects.create_user('testuser1', '*****@*****.**', '12345') is_merchant = cls.user.profile.is_approved_merchant() if not is_merchant: cls.merchant = Merchant(advertiser_ptr=cls.deal.advertiser, userprofile=cls.user.profile, enabled=True, approved=True, intlnumber='123456789') cls.merchant.save() cls.client = Client() super(MerchantManageDealsTestCase, cls).setUpClass()
def test_that_discount_calculated_is_right(self): # test that the discount calculated is correct deal = Deal(**self.deal) deal.save() self.assertEqual(deal.discount(), '50%')
def test_repeated_vote_up(self): """ A user should be able to vote up, only if he has never voted before on the same article """ #Preparation myDeal = Deal() myDeal.title_text = "This is a fake product only for testing purposes" myDeal.link_url = "http://www.amazon.com" myDeal.vendor_text = "Amazon" myDeal.price_decimal = 10.3 myDeal.description_text = "Lorem Ipsum Dolor sit amet esperum funcionorum perfectunum" myDeal.imageUrl_url = "http://www.amazon.com" myDeal.save() myUser = User() myUser.username = "******" myUser.save() myProfile = Profile() myProfile.user = myUser myProfile.save() myDeal.upvote(myUser.id) currentVotes = myDeal.temperature #Action voteOutput = myDeal.upvote(myUser) #Review self.assertEqual(voteOutput, False) self.assertEqual(currentVotes, myDeal.temperature)
def post(self, request, **kwargs): """Create a deal.""" price = request.POST.get('price') original_price = request.POST.get('original_price') currency = request.POST.get('currency') country = int(request.POST.get('user_country')) deal_type = request.POST.get('deal_type') if country == 1: location = int(request.POST.get('nigeria_user_location')) elif country == 2: location = int(request.POST.get('kenya_user_location')) quorum = request.POST.get('quorum') or 0 disclaimer = request.POST.get('disclaimer') description = request.POST.get('description') title = request.POST.get('title') address = request.POST.get('address') max_quantity_available = request.POST.get('max_quantity_available') active = request.POST.get('active') active = True if active else False image = request.FILES.get('image') date_end_unicode = request.POST.get('date_end') or \ (date.today() + timedelta(days=2)).isoformat() category_id = request.POST.get('category') advertiser_id = request.user.profile.merchant.advertiser_ptr.id category = Category.objects.get(id=category_id) advertiser = Advertiser.objects.get(id=advertiser_id) ymd = date_end_unicode.split('-') date_end = date(int(ymd[0]), int(ymd[1]), int(ymd[2])) today = date.today() duration = int(str(date_end - today).split(" ")[0]) if date_end < today: messages.add_message( request, messages.ERROR, "You entered a date that's before today. Please try again") return redirect(reverse('merchant_create_deal')) deal = Deal(price=price, original_price=original_price, currency=currency, country=country, location=location, category=category, quorum=quorum, disclaimer=disclaimer, description=description, address=address, max_quantity_available=max_quantity_available, date_end=date_end, active=active, image=image, title=title, advertiser=advertiser, duration=duration, type=deal_type) deal.save() mssg = "Deal successfully created." messages.add_message(request, messages.ERROR, mssg) return redirect(reverse('merchant_manage_deals'))