def test_lot_sold(self):
        """
        """       
        
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)
    
        category = MarketCategory.objects.all()[0]
        
        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)
        
        auction = AuctionSession(shop=self.shop, title="Auction Session Nr 1", description="-- no desc --", start=now, end=now_plus_10)
        auction.save()
        
        lot = Lot(shop = self.shop,
                  title = "Coin From Rusia 1901 (PCGS 60)",
                  description = "rare coin",
                  category = category,
                  date_time = now,
                  weight = "5",
                  session=auction, 
                  starting_bid=decimal.Decimal("10.00"), 
                  reserve=decimal.Decimal("0.00"))
        lot.save()
        
        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")
        
        bidder = User.objects.filter(username="******").get()
        cart = Cart(shop=self.shop, bidder=bidder)
        cart.save()
        
        #Check that lot is still active...
        self.assertEqual(lot.is_active(), True , "Failed: The lot should be active!")
        self.assertEqual(lot.bidhistory_set.all().count(), 0 , "Failed: The lot should not have any bid yet!")
        
        my_bid = decimal.Decimal("19.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': my_bid}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302, "Failed when trying to bid a valid amount $19.00. This value should be allowed...")    
        
        lot = Lot.objects.get(id=lot.id)
        
        self.assertNotEqual(lot.bidhistory_set.all().count(), 0 , "Failed: The lot should have at least one bid!")
        logging.info("waiting to auction session finish...")
        
        while not lot.session.finished():
            time.sleep(1)
            
        logging.info("Running cron...")
        cron.minute_update()
        
        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.reserve_has_been_met(), True , "Failed, reserved has not been met!")
        self.assertEqual(lot.bid_actual.bid_amount, my_bid , "Failed: The bid actual is wrong, is %s but should be %s" % (lot.bid_actual.bid_amount, my_bid))
        self.assertEqual(lot.bid_actual.bidder.username, "test" , "Failed, wrong bidder won!")
        self.assertEqual(lot.is_active(), False, "Failed: The lot state is wrong, should be SOLD but it is %s" % lot.state)
        self.assertEqual(lot.is_didnt_sell(), False, "Failed: The lot state is wrong, should be SOLD but it is %s" % lot.state)
        self.assertEqual(lot.is_sold(), True, "Failed: The lot state is wrong, should be SOLD but it is %s" % lot.state)
Exemple #2
0
    def test_bidding_home(self):

        category = MarketCategory.objects.all()[0]
        subcategory = MarketSubCategory.objects.all()[0]

        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)

        auction = AuctionSession(shop=self.shop,
                                 title="Auction Session Nr 4",
                                 description="-- no desc --",
                                 start=now,
                                 end=now_plus_10)
        auction.save()

        lot = Lot(shop=self.shop,
                  title="Coin From USA 1905 (PCGS 50)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("100.00"),
                  reserve=decimal.Decimal("300.00"))
        lot.save()

        item = Item(shop=self.shop,
                    title="Item",
                    description="an item",
                    price="10.0",
                    category=category,
                    subcategory=subcategory,
                    qty=2,
                    weight="2.0")
        item.save()

        response = self.client.post(reverse("bidding_home"),
                                    {'email': "*****@*****.**"},
                                    HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302)

        #            param = {
        #             'about': about,
        #             'home':
        #                {
        #                 'title': home.title,
        #                 'body': home.body,
        #                 'image': home.image
        #                 },
        #             'last_post': last_post,
        #             'mailing_list': block_mailing_list,
        #             'new_items': new_items,
        #             'page_title': 'Home',
        #             'page_description': striptags(home.body),
        #             'sessions': new_sessions,
        #            }

        response = self.client.get(reverse("bidding_home"),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)
    def test_lot_didnt_sell(self):
        """
        Check that a lot get state DIDN'T SELL when there no bidding...
        """       
        
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)
    
        category = MarketCategory.objects.all()[0]
        
        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)
        
        auction = AuctionSession(shop=self.shop, title="Auction Session Nr 2", description="-- no desc --", start=now, end=now_plus_10)
        auction.save()
        
        lot = Lot(shop = self.shop,
                  title = "Coin From Argentina 1890 (PCGS 60)",
                  description = "rare coin",
                  category = category,
                  date_time = now,
                  weight = "5",
                  session=auction, 
                  starting_bid=decimal.Decimal("100.00"), 
                  reserve=decimal.Decimal("0.00"))
        lot.save()
        
        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")
        
        #Check that lot is still active...
        self.assertEqual(lot.is_active(), True , "Failed: The lot should be active!")
        self.assertEqual(lot.bidhistory_set.all().count(), 0 , "Failed: The lot should not have any bid yet!")
        
        my_bid = decimal.Decimal("90.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': my_bid}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed: this bid is not valid...")    
        
        self.assertEqual(lot.bidhistory_set.all().count(), 0 , "Failed: The lot should not have any bid yet!")
        
        logging.info("waiting to auction session finish...")
        
        while not lot.session.finished():
            time.sleep(1)
        
        logging.info("Running cron...")
        cron.minute_update()
        
        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.reserve_has_been_met(), False , "Failed, the reserved price should not be reached!")
        self.assertEqual(lot.bid_actual, None , "Failed: There were no bids! ")
        self.assertEqual(lot.is_active(), False, "Failed: The lot could not be active, the lot finished and there were no bids!")
        self.assertEqual(lot.is_sold(), False, "Failed: The lot could not be sold, there were no bids!")
        self.assertEqual(lot.is_didnt_sell(), True, "Failed: The lot wasn't sell!")
    def test_bidding_home(self):
        
        category = MarketCategory.objects.all()[0]
        subcategory = MarketSubCategory.objects.all()[0]

        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)
        
        auction = AuctionSession(shop=self.shop, title="Auction Session Nr 4", 
                                 description="-- no desc --", 
                                 start=now, 
                                 end=now_plus_10)
        auction.save()
        
        lot = Lot(shop=self.shop,
                  title="Coin From USA 1905 (PCGS 50)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction, 
                  starting_bid=decimal.Decimal("100.00"), 
                  reserve=decimal.Decimal("300.00"))
        lot.save()
        
        item = Item(shop=self.shop, title="Item", description="an item", 
                    price="10.0", 
                    category=category, 
                    subcategory=subcategory, 
                    qty=2, weight="2.0")
        item.save() 
        
        response = self.client.post(reverse("bidding_home"), {'email': "*****@*****.**"}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302)
            
#            param = {
#             'about': about,
#             'home': 
#                {
#                 'title': home.title, 
#                 'body': home.body, 
#                 'image': home.image
#                 },
#             'last_post': last_post,
#             'mailing_list': block_mailing_list,
#             'new_items': new_items,
#             'page_title': 'Home',
#             'page_description': striptags(home.body),
#             'sessions': new_sessions,
#            }
            
        response = self.client.get(reverse("bidding_home"), HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)
    def test_lot_still_active(self):
        """
        Check that nothing happend to those lots that aren't finished yet when cron is executed
        """ 
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)
    
        category = MarketCategory.objects.all()[0]
        
        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)
        
        auction = AuctionSession(shop=self.shop, title="Auction Session Nr 4", description="-- no desc --", start=now, end=now_plus_10)
        auction.save()
        
        lot = Lot(shop=self.shop,
                  title="Coin From USA 1905 (PCGS 50)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction, 
                  starting_bid=decimal.Decimal("100.00"), 
                  reserve=decimal.Decimal("300.00"))
        lot.save()
        
        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")
        
        my_bid = decimal.Decimal("120.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': my_bid}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302, "Failed when trying to bid a valid amount %s. This value should be allowed..." % my_bid)    
        
        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bidhistory_set.all().count(), 1 , "Failed: The lot should not have any bid yet!")
        
        logging.info("don't wait for auction session to finish...")

        #Check that lot is still active...
        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.is_active(), True , "Failed: The lot should be active!")

        logging.info("Running cron...")
        
        cron.minute_update()
        
        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.is_active(), True , "Failed: The lot should be active!")
        self.assertEqual(lot.bid_actual.bid_amount, my_bid, "Failed: The bid actual is wrong, is %s but should be %s" % (lot.bid_actual.bid_amount, my_bid))
        self.assertEqual(lot.bid_actual.bidder.username, "test" , "Failed, wrong bidder won!")
        self.assertEqual(lot.is_sold(), False, "Failed: The lot state is wrong, should be ACTIVE but it is %s" % lot.state)
Exemple #6
0
 def test_model_methods(self):
     shop = Shop.objects.all()[0]
     HTTP_HOST = shop.default_dns
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 0)
     
     #Save an active session
     starting_date = datetime.datetime.now() 
     end_date = starting_date + datetime.timedelta(days=3)
     
     auction = AuctionSession(shop=shop, title="Friday Night Session", description="No description for now", start=starting_date, end=end_date)
     auction.save()
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 1, "There should be at least one auction session in the db")
     
     auction = auctions[0]
     self.assertEqual(auction.title, "Friday Night Session")
     self.assertEqual(auction.description, "No description for now")
     
     self.assertEqual(auction.finished(), False)
     self.assertEqual(auction.actual(), True)
     self.assertEqual(auction.future(), False)
     
     self.assertEqual(auction.status(), "In Progress")
     self.assertEqual(auction.count_lots(), 0)
     
     #Save a session that will be in the future
     now = datetime.datetime.now()
     starting_date = now + datetime.timedelta(3) 
     end_date = starting_date + datetime.timedelta(days=7)
     
     auction = AuctionSession(shop=shop, title="Next week Session", description="No description for now", start=starting_date, end=end_date)
     auction.save()
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 2, "There should be 2 sessions")
     
     auction = auctions[1]
     self.assertEqual(auction.title, "Next week Session")
     self.assertEqual(auction.description, "No description for now")
     
     self.assertEqual(auction.finished(), False)
     self.assertEqual(auction.actual(), False)
     self.assertEqual(auction.future(), True)
     
     self.assertEqual(auction.status(), "Future")
     self.assertEqual(auction.count_lots(), 0)
     
     
     #Save a finished session
     now = datetime.datetime.now()
     starting_date = now - datetime.timedelta(7) 
     end_date = now - datetime.timedelta(days=5)
     
     auction = AuctionSession(shop=shop, title="Finished Session", description="No description for now", start=starting_date, end=end_date)
     auction.save()
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 3, "There should be 3 sessions")
     
     auction = auctions[2]
     self.assertEqual(auction.title, "Finished Session")
     self.assertEqual(auction.description, "No description for now")
     
     self.assertEqual(auction.finished(), True)
     self.assertEqual(auction.actual(), False)
     self.assertEqual(auction.future(), False)
     
     self.assertEqual(auction.status(), "Finished")
     self.assertEqual(auction.count_lots(), 0)
     
     print "Done.."
    def test_urls_access(self):
        
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)
    
        shop = Shop.objects.all()[0]
        category = MarketCategory.objects.all()[0]
        HTTP_HOST = shop.default_dns
        
        now = datetime.datetime.now()
        tomorrow = now + datetime.timedelta(days=1)
        auction = AuctionSession(shop=shop, title="Auction Session Nr 0", description="-- no desc --", start=now, end=tomorrow)
        auction.save()
        
        lot = Lot(shop = shop,
                  title = "Coin From Egypt 1905 (PCGS 60)",
                  description = "rare coin",
                  category = category,
                  date_time = now,
                  weight = "5",
                  session=auction, 
                  starting_bid=decimal.Decimal("10.00"), 
                  reserve=decimal.Decimal("0.00"))
        lot.save()
        
        item = Item(shop = shop,
                  title = "Coin From Rusia 1917 (PCGS 60)",
                  description = "rare coin",
                  category = category,
                  date_time = now,
                  weight = "5",
                  qty = "10",
                  price = decimal.Decimal("150"))
        item.save()
        
        user = shop.admin
#        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), HTTP_HOST=HTTP_HOST)
#        self.assertEqual(response.status_code, 200, "Failed when trying to view lot")
#       
        success = self.client.login(username=user.username, password="******")
        self.assertEqual(success, True, "Login failed")
         
        ############# CUSTOMERS ################
        response = self.client.get(reverse("home_admin"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach home_admin")
        
        response = self.client.get(reverse("customers"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers")
        
        response = self.client.get(reverse("customers_overview"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_overview")
        
        response = self.client.get(reverse("customers_profiles"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_profiles")
        
        response = self.client.get(reverse("customers_sold_items"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_sold_items")
        
        response = self.client.get(reverse("customers_payments"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_payments")
        
        response = self.client.get(reverse("customers_shipments"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_shipments")
        
        response = self.client.get(reverse("customers_wish_lists"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_wish_list")
        
#        response = self.client.get(reverse("customers_send_notification"), HTTP_HOST=HTTP_HOST)
#        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")
        
        response = self.client.get(reverse("customers_mailing_list"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_mailing_list")
        
        response = self.client.get(reverse("customers_export_mailinglist"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach customers_export_mailinglist")
        
        ######### WEBSTORE ############
        response = self.client.get(reverse("web_store"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store")
        
        response = self.client.get(reverse("web_store_overview"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_overview")
        
        response = self.client.get(reverse("web_store_marketing"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_marketing")
        
        response = self.client.get(reverse("web_store_shows"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_shows")
        
#        response = self.client.get(reverse("web_store_theme"), HTTP_HOST=HTTP_HOST)
#        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_theme")
        
        response = self.client.get(reverse("web_store_pages"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_pages")
        
        response = self.client.get(reverse("web_store_blogs"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_blogs")
        
        response = self.client.get(reverse("web_store_navigation"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_navigation")
        
#        response = self.client.get(reverse("web_store_show_go"), HTTP_HOST=HTTP_HOST)
#        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")
#        
#        response = self.client.get(reverse("web_store_show_not_go"), HTTP_HOST=HTTP_HOST)
#        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")
#        
#        response = self.client.get(reverse("web_store_theme"), HTTP_HOST=HTTP_HOST)
#        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")
        
        ######### INVENTORY ##########
        response = self.client.get(reverse("inventory"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory")
        
        response = self.client.get(reverse("inventory_overview"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory_overview")
        
        response = self.client.get(reverse("inventory_items"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory_items")
        
        response = self.client.get(reverse("inventory_items_import"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory_items_import")
        
        response = self.client.get(reverse("inventory_lots"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory_lots")
                
        response = self.client.get(reverse("inventory_auctions"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory_auctions")
        
        response = self.client.get(reverse("inventory_categorize"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach inventory_categorize")
        
        ######## ACCOUNT #########
        response = self.client.get(reverse("account"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach account")
        
        response = self.client.get(reverse("account_profile"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach account_profile")
        
        response = self.client.get(reverse("account_password"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach account_password")
        
        response = self.client.get(reverse("add_profile_photo"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 302, "Failed when trying to reach add_profile_photo")
        
        response = self.client.get(reverse("preferences"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed when trying to reach preferences")
Exemple #8
0
    def test_bidding_views(self):

        now = datetime.datetime.now()
        tomarrow = now + datetime.timedelta(days=1)
        category = MarketCategory.objects.all()[0]
        subcategory = MarketSubCategory.objects.all()[0]

        item = Item(shop=self.shop,
                    title="My Unique Item",
                    description="the description of my unique item",
                    price="10.0",
                    category=category,
                    subcategory=subcategory,
                    qty=2,
                    weight="2.0")
        item.save()

        auction = AuctionSession(shop=self.shop,
                                 title="Test Session",
                                 description="-- no desc --",
                                 start=now,
                                 end=tomarrow)
        auction.save()

        lot = Lot(shop=self.shop,
                  title="Coin From USA 1905 (PCGS 50)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("100.00"),
                  reserve=decimal.Decimal("300.00"))
        lot.save()

        response = self.client.get(reverse("bidding_about_us"),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertContains(
            response,
            "Nam est mauris, pretium eu imperdiet ut, iaculis sit amet sapien",
            count=None,
            status_code=200,
            msg_prefix='')

        response = self.client.get(reverse("bidding_auctions_id",
                                           args=[auction.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['sessions']), 1)

        response = self.client.get(reverse("bidding_blog"),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)

        response = self.client.get(reverse("bidding_buy_now", args=[item.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302)

        #bidding_search

        page = Page(shop=self.shop,
                    name_link="somewhere",
                    title="Page Title",
                    body="This is the page content")
        page.save()
        response = self.client.get(reverse("bidding_page",
                                           args=[page.name_link]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertContains(response,
                            "Page Title",
                            count=None,
                            status_code=200,
                            msg_prefix='')
        self.assertContains(response,
                            "This is the page content",
                            count=None,
                            status_code=200,
                            msg_prefix='')

        response = self.client.get(reverse("bidding_sitemap"),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)

        #self.assertContains(response, "Page Title", count=None, status_code=200, msg_prefix='')

        response = self.client.get(reverse("bidding_for_sale"),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)

        response = self.client.get(reverse("bidding_map",
                                           args=[self.shop.about.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)

        response = self.client.get(reverse("bidding_view_history_lot",
                                           args=[lot.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)

        response = self.client.post(reverse("bidding_view_history_lot",
                                            args=[lot.id]),
                                    {'amount': '10.00'},
                                    HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200)

        response = self.client.get(reverse("bidding_view_item",
                                           args=[item.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertContains(response,
                            "My Unique Item",
                            count=None,
                            status_code=200,
                            msg_prefix='')

        post = Post(shop=self.shop,
                    title="This is my first blog post",
                    body="some content here")
        post.save()

        self.assertEqual(post.views, 0)
        response = self.client.get(reverse("bidding_view_post",
                                           args=[post.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertContains(response,
                            "This is my first blog post",
                            count=None,
                            status_code=200,
                            msg_prefix='')

        post = Post.objects.filter(id=post.id)[0]
        self.assertEqual(post.views, 1)
Exemple #9
0
    def test_bidding_place_bid(self):
        """
        """
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)

        category = MarketCategory.objects.all()[0]

        now = datetime.datetime.now()
        tomorrow = now + datetime.timedelta(days=1)

        # Creates an auction
        auction = AuctionSession(shop=self.shop,
                                 title="Auction Session Nr 0",
                                 description="-- no desc --",
                                 start=now,
                                 end=tomorrow)
        auction.save()

        # Creates a lot
        lot = Lot(shop=self.shop,
                  title="Coin From Egypt 1905 (PCGS 60)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("10.00"),
                  reserve=decimal.Decimal("0.00"))
        lot.save()

        # Ttry to login
        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")

        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to view lot")

        # Check than when is created there is no any bid
        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bid_actual, None)

        # Testing bid increment table
        increment_calculator = BidderIncrementCalculator()
        #from    0.01    to    0.99   --> 0.05
        #from    1.00    to    4.99   --> 0.25
        #from    5.00    to    24.99   --> 0.50
        #from    25.00   to    99.99   --> 1.00
        #from    100.00  to    249.99  --> 2.50
        #from    250.00  to    499.99  --> 5.00
        #from    500.00  to    999.99  --> 10.00
        #from    1000.00 to    2499.99 --> 25.00
        #from    2500.00 to    4999.99 --> 50.00
        #from    5000.00 to    99999.99--> 100.00

        for i in range(30):
            lot = Lot.objects.get(id=lot.id)
            if lot.bid_actual:
                logging.info("Current Bid: %s" % (lot.bid_actual.bid_amount))

            else:
                logging.info("Starting Bid: %s" % (lot.starting_bid))

            min_bid = lot.next_bid_from()
            (from_price, to_price,
             inc) = increment_calculator.match_for(min_bid)
            logging.info(
                "From: %s To: %s Bid must be grater than %s (increment to be applied %s)"
                % (from_price, to_price, min_bid, inc))

            logging.info("Minimum Bid allowed: %s" % min_bid)

            # Should not be allowed to bid
            wrong_bid = min_bid - (min_bid * decimal.Decimal(("0.1")))
            logging.info("Testing Invalid Bidding Price: %s" % wrong_bid)
            response = self.client.get(reverse("bidding_view_lot",
                                               args=[lot.id]),
                                       {'amount': wrong_bid},
                                       HTTP_HOST=self.HTTP_HOST)
            self.assertEqual(response.status_code, 200,
                             "Failed: This bid shouldn't be valid!!")

            # Should be allowed to bid
            string_format = '%.2f' % (min_bid + (min_bid * decimal.Decimal(
                ("0.5"))))
            valid_bid = decimal.Decimal((string_format))
            logging.info("Testing Valid Bidding Price: %s" % valid_bid)
            response = self.client.get(reverse("bidding_view_lot",
                                               args=[lot.id]),
                                       {'amount': valid_bid},
                                       HTTP_HOST=self.HTTP_HOST)
            self.assertEqual(
                response.status_code, 302,
                "Failed when trying to bid a valid amount %s. This value should be allowed..."
                % valid_bid)

            # Check that last bid is the the currently lot.bid_actual
            logging.info("Testing Correct Lot.bid_actual: %s" % valid_bid)
            lot = Lot.objects.get(id=lot.id)
            self.assertEqual(
                lot.bid_actual.bid_amount, valid_bid,
                "Failed: The bid actual is wrong, is %s but should be %s" %
                (lot.bid_actual.bid_amount, valid_bid))
Exemple #10
0
    def test_lot_still_active(self):
        """
        Check that nothing happend to those lots that aren't finished yet when cron is executed
        """
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)

        category = MarketCategory.objects.all()[0]

        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)

        auction = AuctionSession(shop=self.shop,
                                 title="Auction Session Nr 4",
                                 description="-- no desc --",
                                 start=now,
                                 end=now_plus_10)
        auction.save()

        lot = Lot(shop=self.shop,
                  title="Coin From USA 1905 (PCGS 50)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("100.00"),
                  reserve=decimal.Decimal("300.00"))
        lot.save()

        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")

        my_bid = decimal.Decimal("120.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   {'amount': my_bid},
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(
            response.status_code, 302,
            "Failed when trying to bid a valid amount %s. This value should be allowed..."
            % my_bid)

        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bidhistory_set.all().count(), 1,
                         "Failed: The lot should not have any bid yet!")

        logging.info("don't wait for auction session to finish...")

        #Check that lot is still active...
        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.is_active(), True,
                         "Failed: The lot should be active!")

        logging.info("Running cron...")

        cron.minute_update()

        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.is_active(), True,
                         "Failed: The lot should be active!")
        self.assertEqual(
            lot.bid_actual.bid_amount, my_bid,
            "Failed: The bid actual is wrong, is %s but should be %s" %
            (lot.bid_actual.bid_amount, my_bid))
        self.assertEqual(lot.bid_actual.bidder.username, "test",
                         "Failed, wrong bidder won!")
        self.assertEqual(
            lot.is_sold(), False,
            "Failed: The lot state is wrong, should be ACTIVE but it is %s" %
            lot.state)
Exemple #11
0
    def test_lot_didnt_sell(self):
        """
        Check that a lot get state DIDN'T SELL when there no bidding...
        """

        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)

        category = MarketCategory.objects.all()[0]

        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)

        auction = AuctionSession(shop=self.shop,
                                 title="Auction Session Nr 2",
                                 description="-- no desc --",
                                 start=now,
                                 end=now_plus_10)
        auction.save()

        lot = Lot(shop=self.shop,
                  title="Coin From Argentina 1890 (PCGS 60)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("100.00"),
                  reserve=decimal.Decimal("0.00"))
        lot.save()

        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")

        #Check that lot is still active...
        self.assertEqual(lot.is_active(), True,
                         "Failed: The lot should be active!")
        self.assertEqual(lot.bidhistory_set.all().count(), 0,
                         "Failed: The lot should not have any bid yet!")

        my_bid = decimal.Decimal("90.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   {'amount': my_bid},
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed: this bid is not valid...")

        self.assertEqual(lot.bidhistory_set.all().count(), 0,
                         "Failed: The lot should not have any bid yet!")

        logging.info("waiting to auction session finish...")

        while not lot.session.finished():
            time.sleep(1)

        logging.info("Running cron...")
        cron.minute_update()

        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.reserve_has_been_met(), False,
                         "Failed, the reserved price should not be reached!")
        self.assertEqual(lot.bid_actual, None, "Failed: There were no bids! ")
        self.assertEqual(
            lot.is_active(), False,
            "Failed: The lot could not be active, the lot finished and there were no bids!"
        )
        self.assertEqual(
            lot.is_sold(), False,
            "Failed: The lot could not be sold, there were no bids!")
        self.assertEqual(lot.is_didnt_sell(), True,
                         "Failed: The lot wasn't sell!")
Exemple #12
0
    def test_lot_sold(self):
        """
        """

        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)

        category = MarketCategory.objects.all()[0]

        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)

        auction = AuctionSession(shop=self.shop,
                                 title="Auction Session Nr 1",
                                 description="-- no desc --",
                                 start=now,
                                 end=now_plus_10)
        auction.save()

        lot = Lot(shop=self.shop,
                  title="Coin From Rusia 1901 (PCGS 60)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("10.00"),
                  reserve=decimal.Decimal("0.00"))
        lot.save()

        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")

        bidder = User.objects.filter(username="******").get()
        cart = Cart(shop=self.shop, bidder=bidder)
        cart.save()

        #Check that lot is still active...
        self.assertEqual(lot.is_active(), True,
                         "Failed: The lot should be active!")
        self.assertEqual(lot.bidhistory_set.all().count(), 0,
                         "Failed: The lot should not have any bid yet!")

        my_bid = decimal.Decimal("19.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   {'amount': my_bid},
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(
            response.status_code, 302,
            "Failed when trying to bid a valid amount $19.00. This value should be allowed..."
        )

        lot = Lot.objects.get(id=lot.id)

        self.assertNotEqual(lot.bidhistory_set.all().count(), 0,
                            "Failed: The lot should have at least one bid!")
        logging.info("waiting to auction session finish...")

        while not lot.session.finished():
            time.sleep(1)

        logging.info("Running cron...")
        cron.minute_update()

        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.reserve_has_been_met(), True,
                         "Failed, reserved has not been met!")
        self.assertEqual(
            lot.bid_actual.bid_amount, my_bid,
            "Failed: The bid actual is wrong, is %s but should be %s" %
            (lot.bid_actual.bid_amount, my_bid))
        self.assertEqual(lot.bid_actual.bidder.username, "test",
                         "Failed, wrong bidder won!")
        self.assertEqual(
            lot.is_active(), False,
            "Failed: The lot state is wrong, should be SOLD but it is %s" %
            lot.state)
        self.assertEqual(
            lot.is_didnt_sell(), False,
            "Failed: The lot state is wrong, should be SOLD but it is %s" %
            lot.state)
        self.assertEqual(
            lot.is_sold(), True,
            "Failed: The lot state is wrong, should be SOLD but it is %s" %
            lot.state)
 def test_bidding_place_bid(self):
     """
     """
     context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
     decimal.setcontext(context)
 
     
     category = MarketCategory.objects.all()[0]
     
     now = datetime.datetime.now()
     tomorrow = now + datetime.timedelta(days=1)
     
     # Creates an auction
     auction = AuctionSession(shop=self.shop, title="Auction Session Nr 0", description="-- no desc --", start=now, end=tomorrow)
     auction.save()
     
     # Creates a lot 
     lot = Lot(shop = self.shop,
               title = "Coin From Egypt 1905 (PCGS 60)",
               description = "rare coin",
               category = category,
               date_time = now,
               weight = "5",
               session=auction, 
               starting_bid=decimal.Decimal("10.00"), 
               reserve=decimal.Decimal("0.00"))
     lot.save()
     
     # Ttry to login
     success = self.client.login(username='******', password='******')
     self.assertEqual(success, True, "login failed")
     
     response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200, "Failed when trying to view lot")
     
     # Check than when is created there is no any bid
     lot = Lot.objects.get(id=lot.id)
     self.assertEqual(lot.bid_actual, None)
     
     # Testing bid increment table
     increment_calculator = BidderIncrementCalculator()
     #from    0.01    to    0.99   --> 0.05
     #from    1.00    to    4.99   --> 0.25
     #from    5.00    to    24.99   --> 0.50
     #from    25.00   to    99.99   --> 1.00
     #from    100.00  to    249.99  --> 2.50
     #from    250.00  to    499.99  --> 5.00
     #from    500.00  to    999.99  --> 10.00
     #from    1000.00 to    2499.99 --> 25.00
     #from    2500.00 to    4999.99 --> 50.00
     #from    5000.00 to    99999.99--> 100.00
     
     for i in range(30):
         lot = Lot.objects.get(id=lot.id)
         if lot.bid_actual:
             logging.info("Current Bid: %s" % (lot.bid_actual.bid_amount))
             
         else:
             logging.info("Starting Bid: %s" % (lot.starting_bid))
             
         min_bid = lot.next_bid_from()
         (from_price, to_price, inc) = increment_calculator.match_for(min_bid)
         logging.info("From: %s To: %s Bid must be grater than %s (increment to be applied %s)" % (from_price, to_price, min_bid, inc))
         
         logging.info("Minimum Bid allowed: %s" % min_bid)
         
         # Should not be allowed to bid
         wrong_bid = min_bid - (min_bid * decimal.Decimal(("0.1")))
         logging.info("Testing Invalid Bidding Price: %s" % wrong_bid)
         response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': wrong_bid}, HTTP_HOST=self.HTTP_HOST)
         self.assertEqual(response.status_code, 200, "Failed: This bid shouldn't be valid!!")
         
         # Should be allowed to bid
         string_format = '%.2f' % (min_bid + (min_bid * decimal.Decimal(("0.5"))))
         valid_bid = decimal.Decimal((string_format))
         logging.info("Testing Valid Bidding Price: %s" % valid_bid)       
         response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': valid_bid}, HTTP_HOST=self.HTTP_HOST)
         self.assertEqual(response.status_code, 302, "Failed when trying to bid a valid amount %s. This value should be allowed..." % valid_bid)
         
         # Check that last bid is the the currently lot.bid_actual
         logging.info("Testing Correct Lot.bid_actual: %s" % valid_bid) 
         lot = Lot.objects.get(id=lot.id)
         self.assertEqual(lot.bid_actual.bid_amount, valid_bid, "Failed: The bid actual is wrong, is %s but should be %s" % (lot.bid_actual.bid_amount, valid_bid))
 def test_bidding_views(self):
     
     now = datetime.datetime.now()
     tomarrow = now + datetime.timedelta(days=1)
     category = MarketCategory.objects.all()[0]
     subcategory = MarketSubCategory.objects.all()[0]
     
     item = Item(shop=self.shop, title="My Unique Item", description="the description of my unique item", 
                 price="10.0", 
                 category=category, 
                 subcategory=subcategory, 
                 qty=2, weight="2.0")
     item.save() 
     
     auction = AuctionSession(shop=self.shop, title="Test Session", 
                              description="-- no desc --", 
                              start=now, 
                              end=tomarrow)
     auction.save()
     
     lot = Lot(shop=self.shop,
               title="Coin From USA 1905 (PCGS 50)",
               description="rare coin",
               category=category,
               date_time=now,
               weight="5",
               session=auction, 
               starting_bid=decimal.Decimal("100.00"), 
               reserve=decimal.Decimal("300.00"))
     lot.save()
     
     
     response = self.client.get(reverse("bidding_about_us"), HTTP_HOST=self.HTTP_HOST)
     self.assertContains(response, "Nam est mauris, pretium eu imperdiet ut, iaculis sit amet sapien", count=None, status_code=200, msg_prefix='')     
     
     response = self.client.get(reverse("bidding_auctions_id", args=[auction.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.context['sessions']), 1)
     
     response = self.client.get(reverse("bidding_blog"), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
     
     response = self.client.get(reverse("bidding_buy_now", args=[item.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 302)
     
     #bidding_search
 
     page = Page(shop=self.shop, name_link="somewhere", title="Page Title", body="This is the page content")
     page.save()
     response = self.client.get(reverse("bidding_page", args=[page.name_link]), HTTP_HOST=self.HTTP_HOST)
     self.assertContains(response, "Page Title", count=None, status_code=200, msg_prefix='')
     self.assertContains(response, "This is the page content", count=None, status_code=200, msg_prefix='')
     
     response = self.client.get(reverse("bidding_sitemap"), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
     
     #self.assertContains(response, "Page Title", count=None, status_code=200, msg_prefix='')
     
     response = self.client.get(reverse("bidding_for_sale"), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
     
     response = self.client.get(reverse("bidding_map", args=[self.shop.about.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
         
     response = self.client.get(reverse("bidding_view_history_lot", args=[lot.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
     
     response = self.client.post(reverse("bidding_view_history_lot", args=[lot.id]), {'amount': '10.00' },HTTP_HOST=self.HTTP_HOST)
     self.assertEqual(response.status_code, 200)
     
     response = self.client.get(reverse("bidding_view_item", args=[item.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertContains(response, "My Unique Item", count=None, status_code=200, msg_prefix='')
     
     post = Post(shop=self.shop, title="This is my first blog post", body="some content here")
     post.save()
     
     self.assertEqual(post.views, 0)
     response = self.client.get(reverse("bidding_view_post", args=[post.id]), HTTP_HOST=self.HTTP_HOST)
     self.assertContains(response, "This is my first blog post" , count=None, status_code=200, msg_prefix='')
 
     post = Post.objects.filter(id=post.id)[0]
     self.assertEqual(post.views, 1)
    def test_lot_didnt_sell2(self):
        """
        Check that a lot get state DIDN'T SELL when there are no biddings that reach the reserve price
        """       
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)
        
        category = MarketCategory.objects.all()[0]
        
        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)
        
        auction = AuctionSession(shop=self.shop, title="Auction Session Nr 3", description="-- no desc --", start=now, end=now_plus_10)
        auction.save()
        
        lot = Lot(shop=self.shop,
                  title = "Coin From Brasil 1900 (PCGS 60)",
                  description = "rare coin",
                  category = category,
                  date_time = now,
                  weight="5",
                  session=auction, 
                  starting_bid=decimal.Decimal("100.00"), 
                  reserve=decimal.Decimal("300.00"))
        lot.save()
        
        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")
        
        #Check that lot is still active...
        self.assertEqual(lot.is_active(), True , "Failed: The lot should be active!")
        self.assertEqual(lot.bidhistory_set.all().count(), 0 , "Failed: The lot should not have any bid yet!")
        
        #1) Trying To BID wrong
        my_bid = decimal.Decimal("90.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': my_bid}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200, "Failed: this bid is not valid...")    
        self.assertEqual(lot.bidhistory_set.all().count(), 0 , "Failed: The lot should not have any bid yet!")
        
        #2) First valid bid, but don't reach the reserve price
        my_bid = decimal.Decimal("120.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': my_bid}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302, "Failed when trying to bid a valid amount %s. This value should be allowed..." % my_bid)    
        
        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bidhistory_set.all().count(), 1 , "Failed: The lot should have 1 bid!")
        
        #3) Second valid bid, but neither reach the reserve price
        my_bid = decimal.Decimal("290.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), {'amount': my_bid}, HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 302, "Failed when trying to bid a valid amount %s. This value should be allowed..." % my_bid)    
        
        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bidhistory_set.all().count(), 2 , "Failed: The lot should have 2 bids!")
        
        logging.info("waiting to auction session finish...")
        while not lot.session.finished():
            time.sleep(1)
            
        logging.info("Running cron...")
        cron.minute_update()
        
        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.reserve_has_been_met(), False , "Failed, the reserved price should not be reached!")
        self.assertEqual(lot.bid_actual.bid_amount, my_bid, "Failed: The bid actual is wrong, is %s but should be %s" % (lot.bid_actual.bid_amount, my_bid))
        self.assertEqual(lot.bid_actual.bidder.username, "test" , "Failed, wrong bidder won!")
        self.assertEqual(lot.is_sold(), False, "Failed: The lot state is wrong, should be DIDN'T SELL but it is %s" % lot.state)
        self.assertEqual(lot.is_didnt_sell(), True, "Failed: The lot state is wrong, should be DIDN'T SELL but it is %s" % lot.state)
 def test_model_methods(self):
     shop = Shop.objects.all()[0]
     HTTP_HOST = shop.default_dns
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 0)
     
     #Save an active session
     starting_date = datetime.datetime.now() 
     end_date = starting_date + datetime.timedelta(days=3)
     
     auction = AuctionSession(shop=shop, title="Friday Night Session", description="No description for now", start=starting_date, end=end_date)
     auction.save()
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 1, "There should be at least one auction session in the db")
     
     auction = auctions[0]
     self.assertEqual(auction.title, "Friday Night Session")
     self.assertEqual(auction.description, "No description for now")
     
     self.assertEqual(auction.finished(), False)
     self.assertEqual(auction.actual(), True)
     self.assertEqual(auction.future(), False)
     
     self.assertEqual(auction.status(), "Actual")
     self.assertEqual(auction.count_lots(), 0)
     
     #Save a session that will be in the future
     now = datetime.datetime.now()
     starting_date = now + datetime.timedelta(3) 
     end_date = starting_date + datetime.timedelta(days=7)
     
     auction = AuctionSession(shop=shop, title="Next week Session", description="No description for now", start=starting_date, end=end_date)
     auction.save()
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 2, "There should be 2 sessions")
     
     auction = auctions[1]
     self.assertEqual(auction.title, "Next week Session")
     self.assertEqual(auction.description, "No description for now")
     
     self.assertEqual(auction.finished(), False)
     self.assertEqual(auction.actual(), False)
     self.assertEqual(auction.future(), True)
     
     self.assertEqual(auction.status(), "Future")
     self.assertEqual(auction.count_lots(), 0)
     
     
     #Save a finished session
     now = datetime.datetime.now()
     starting_date = now - datetime.timedelta(7) 
     end_date = now - datetime.timedelta(days=5)
     
     auction = AuctionSession(shop=shop, title="Finished Session", description="No description for now", start=starting_date, end=end_date)
     auction.save()
     
     auctions = AuctionSession.objects.all()
     self.assertEqual(auctions.count(), 3, "There should be 3 sessions")
     
     auction = auctions[2]
     self.assertEqual(auction.title, "Finished Session")
     self.assertEqual(auction.description, "No description for now")
     
     self.assertEqual(auction.finished(), True)
     self.assertEqual(auction.actual(), False)
     self.assertEqual(auction.future(), False)
     
     self.assertEqual(auction.status(), "Finished")
     self.assertEqual(auction.count_lots(), 0)
     
     print "Done.."
    def test_urls_access(self):

        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)

        shop = Shop.objects.all()[0]
        category = MarketCategory.objects.all()[0]
        HTTP_HOST = shop.default_dns

        now = datetime.datetime.now()
        tomorrow = now + datetime.timedelta(days=1)
        auction = AuctionSession(shop=shop,
                                 title="Auction Session Nr 0",
                                 description="-- no desc --",
                                 start=now,
                                 end=tomorrow)
        auction.save()

        lot = Lot(shop=shop,
                  title="Coin From Egypt 1905 (PCGS 60)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("10.00"),
                  reserve=decimal.Decimal("0.00"))
        lot.save()

        item = Item(shop=shop,
                    title="Coin From Rusia 1917 (PCGS 60)",
                    description="rare coin",
                    category=category,
                    date_time=now,
                    weight="5",
                    qty="10",
                    price=decimal.Decimal("150"))
        item.save()

        user = shop.admin
        #        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]), HTTP_HOST=HTTP_HOST)
        #        self.assertEqual(response.status_code, 200, "Failed when trying to view lot")
        #
        success = self.client.login(username=user.username, password="******")
        self.assertEqual(success, True, "Login failed")

        ############# CUSTOMERS ################
        response = self.client.get(reverse("home_admin"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach home_admin")

        response = self.client.get(reverse("customers"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers")

        response = self.client.get(reverse("customers_overview"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_overview")

        response = self.client.get(reverse("customers_profiles"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_profiles")

        response = self.client.get(reverse("customers_sold_items"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_sold_items")

        response = self.client.get(reverse("customers_payments"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_payments")

        response = self.client.get(reverse("customers_shipments"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_shipments")

        response = self.client.get(reverse("customers_wish_lists"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_wish_list")

        #        response = self.client.get(reverse("customers_send_notification"), HTTP_HOST=HTTP_HOST)
        #        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")

        response = self.client.get(reverse("customers_mailing_list"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach customers_mailing_list")

        response = self.client.get(reverse("customers_export_mailinglist"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(
            response.status_code, 200,
            "Failed when trying to reach customers_export_mailinglist")

        ######### WEBSTORE ############
        response = self.client.get(reverse("web_store"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store")

        response = self.client.get(reverse("web_store_overview"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store_overview")

        response = self.client.get(reverse("web_store_marketing"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store_marketing")

        response = self.client.get(reverse("web_store_shows"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store_shows")

        #        response = self.client.get(reverse("web_store_theme"), HTTP_HOST=HTTP_HOST)
        #        self.assertEqual(response.status_code, 200, "Failed when trying to reach web_store_theme")

        response = self.client.get(reverse("web_store_pages"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store_pages")

        response = self.client.get(reverse("web_store_blogs"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store_blogs")

        response = self.client.get(reverse("web_store_navigation"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach web_store_navigation")

        #        response = self.client.get(reverse("web_store_show_go"), HTTP_HOST=HTTP_HOST)
        #        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")
        #
        #        response = self.client.get(reverse("web_store_show_not_go"), HTTP_HOST=HTTP_HOST)
        #        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")
        #
        #        response = self.client.get(reverse("web_store_theme"), HTTP_HOST=HTTP_HOST)
        #        self.assertEqual(response.status_code, 200, "Failed when trying to bid a valid amount")

        ######### INVENTORY ##########
        response = self.client.get(reverse("inventory"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory")

        response = self.client.get(reverse("inventory_overview"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory_overview")

        response = self.client.get(reverse("inventory_items"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory_items")

        response = self.client.get(reverse("inventory_items_import"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory_items_import")

        response = self.client.get(reverse("inventory_lots"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory_lots")

        response = self.client.get(reverse("inventory_auctions"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory_auctions")

        response = self.client.get(reverse("inventory_categorize"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach inventory_categorize")

        ######## ACCOUNT #########
        response = self.client.get(reverse("account"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach account")

        response = self.client.get(reverse("account_profile"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach account_profile")

        response = self.client.get(reverse("account_password"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach account_password")

        response = self.client.get(reverse("add_profile_photo"),
                                   HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 302,
                         "Failed when trying to reach add_profile_photo")

        response = self.client.get(reverse("preferences"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed when trying to reach preferences")
Exemple #18
0
    def test_lot_didnt_sell2(self):
        """
        Check that a lot get state DIDN'T SELL when there are no biddings that reach the reserve price
        """
        context = decimal.Context(prec=20, rounding=decimal.ROUND_HALF_DOWN)
        decimal.setcontext(context)

        category = MarketCategory.objects.all()[0]

        now = datetime.datetime.now()
        now_plus_10 = now + datetime.timedelta(seconds=5)

        auction = AuctionSession(shop=self.shop,
                                 title="Auction Session Nr 3",
                                 description="-- no desc --",
                                 start=now,
                                 end=now_plus_10)
        auction.save()

        lot = Lot(shop=self.shop,
                  title="Coin From Brasil 1900 (PCGS 60)",
                  description="rare coin",
                  category=category,
                  date_time=now,
                  weight="5",
                  session=auction,
                  starting_bid=decimal.Decimal("100.00"),
                  reserve=decimal.Decimal("300.00"))
        lot.save()

        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")

        #Check that lot is still active...
        self.assertEqual(lot.is_active(), True,
                         "Failed: The lot should be active!")
        self.assertEqual(lot.bidhistory_set.all().count(), 0,
                         "Failed: The lot should not have any bid yet!")

        #1) Trying To BID wrong
        my_bid = decimal.Decimal("90.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   {'amount': my_bid},
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(response.status_code, 200,
                         "Failed: this bid is not valid...")
        self.assertEqual(lot.bidhistory_set.all().count(), 0,
                         "Failed: The lot should not have any bid yet!")

        #2) First valid bid, but don't reach the reserve price
        my_bid = decimal.Decimal("120.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   {'amount': my_bid},
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(
            response.status_code, 302,
            "Failed when trying to bid a valid amount %s. This value should be allowed..."
            % my_bid)

        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bidhistory_set.all().count(), 1,
                         "Failed: The lot should have 1 bid!")

        #3) Second valid bid, but neither reach the reserve price
        my_bid = decimal.Decimal("290.00")
        response = self.client.get(reverse("bidding_view_lot", args=[lot.id]),
                                   {'amount': my_bid},
                                   HTTP_HOST=self.HTTP_HOST)
        self.assertEqual(
            response.status_code, 302,
            "Failed when trying to bid a valid amount %s. This value should be allowed..."
            % my_bid)

        lot = Lot.objects.get(id=lot.id)
        self.assertEqual(lot.bidhistory_set.all().count(), 2,
                         "Failed: The lot should have 2 bids!")

        logging.info("waiting to auction session finish...")
        while not lot.session.finished():
            time.sleep(1)

        logging.info("Running cron...")
        cron.minute_update()

        lot = Lot.objects.get(id=lot.id)

        self.assertEqual(lot.reserve_has_been_met(), False,
                         "Failed, the reserved price should not be reached!")
        self.assertEqual(
            lot.bid_actual.bid_amount, my_bid,
            "Failed: The bid actual is wrong, is %s but should be %s" %
            (lot.bid_actual.bid_amount, my_bid))
        self.assertEqual(lot.bid_actual.bidder.username, "test",
                         "Failed, wrong bidder won!")
        self.assertEqual(
            lot.is_sold(), False,
            "Failed: The lot state is wrong, should be DIDN'T SELL but it is %s"
            % lot.state)
        self.assertEqual(
            lot.is_didnt_sell(), True,
            "Failed: The lot state is wrong, should be DIDN'T SELL but it is %s"
            % lot.state)