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 process_request(self, request):
     user= request.user
     shop = request.shop        
     
     if (shop is not None) and (user is not None) and (user.is_anonymous() == False) and (user != shop.admin):
         try:
             cart = Cart.objects.filter(bidder=user).filter(shop=shop).get()
         except Cart.DoesNotExist:
             cart = Cart(shop=shop, bidder=user)
             cart.save()
         request.cart = cart
Exemple #3
0
    def setUp(self):
        # create store owner user and profile
        self.owner = User.objects.create_user("test-owner", "*****@*****.**", "test-owner")
        owner_profile = Profile(user=self.owner)
        owner_profile.save()

        # create a marketplace
        self.marketplace = MarketPlace(name="greatcoins", title="greatcoins", slug="greatcoins", 
                                       template_prefix="greatcoins", base_domain="greatcoins.com")
        self.marketplace.save()

        # create a shop
        self.shop = Shop(marketplace=self.marketplace, admin=self.owner, name="test_shop")
        self.shop.save()

        # create a Preference and SubscriptionPlan to shop
        Preference(shop=self.shop).save()
        self.shop.update()
        plan = SubscriptionPlan(plan_id=1,
                         marketplace=self.marketplace,
                         trial_period=True,
                         total_store_revenue=1000,
                         concurrent_store_items=1000)
        plan.save()
        Subscription(owner=owner_profile, plan=plan).save()

        # create marketplace categories and sub-categories
        self.category = MarketCategory(marketplace=self.marketplace, name="Category")
        self.category.save()
        self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory")
        self.subcategory.save()

        # create a user, profile and shipping data
        self.user = User.objects.create_user("test-user", "*****@*****.**", "test-user")
        Profile(user=self.user).save()
        shippingdata = ShippingData(first_name='User',
                                    last_name='Buyer',
                                    street_address="Calle 54",
                                    city="La Plata",
                                    state="Buenos Aires",
                                    zip="1900",
                                    country="AR")
        shippingdata.save()

        # create a shopping cart
        self.cart = Cart(shop=self.shop, bidder=self.user)
        self.cart.shippingdata = shippingdata
        self.cart.save()
Exemple #4
0
class ItemTestCase(unittest.TestCase):
    
    def setUp(self):
        # create store owner user and profile
        self.owner = User.objects.create_user("test-owner", "*****@*****.**", "test-owner")
        owner_profile = Profile(user=self.owner)
        owner_profile.save()

        # create a marketplace
        self.marketplace = MarketPlace(name="greatcoins", title="greatcoins", slug="greatcoins", 
                                       template_prefix="greatcoins", base_domain="greatcoins.com")
        self.marketplace.save()

        # create a shop
        self.shop = Shop(marketplace=self.marketplace, admin=self.owner, name="test_shop")
        self.shop.save()

        # create a Preference and SubscriptionPlan to shop
        Preference(shop=self.shop).save()
        self.shop.update()
        plan = SubscriptionPlan(plan_id=1,
                         marketplace=self.marketplace,
                         trial_period=True,
                         total_store_revenue=1000,
                         concurrent_store_items=1000)
        plan.save()
        Subscription(owner=owner_profile, plan=plan).save()

        # create marketplace categories and sub-categories
        self.category = MarketCategory(marketplace=self.marketplace, name="Category")
        self.category.save()
        self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory")
        self.subcategory.save()

        # create a user, profile and shipping data
        self.user = User.objects.create_user("test-user", "*****@*****.**", "test-user")
        Profile(user=self.user).save()
        shippingdata = ShippingData(first_name='User',
                                    last_name='Buyer',
                                    street_address="Calle 54",
                                    city="La Plata",
                                    state="Buenos Aires",
                                    zip="1900",
                                    country="AR")
        shippingdata.save()

        # create a shopping cart
        self.cart = Cart(shop=self.shop, bidder=self.user)
        self.cart.shippingdata = shippingdata
        self.cart.save()

    def tearDown(self):
        self.owner.delete()
        self.marketplace.delete()
        self.category.delete()
        self.subcategory.delete()
    
    def testItemCreate(self):
        import logging
        from inventory.models import Product
        products_count = Product.objects.count()
        item = Item(shop=self.shop, title="item", description="an item", 
                    price="10.0", category=self.category, subcategory=self.subcategory, 
                    qty=1, weight="2.0")
        item.save()
        
        #check Product was created
        self.assertEqual(products_count + 1, Product.objects.count())
        #check Product was deleted
        item.delete()
        self.assertEqual(products_count, Product.objects.count())

    def testSoldOut(self):
        # create a item
        item = Item(shop=self.shop,
                title="item",
                description="an item",
                price="10.0",
                category=self.category,
                subcategory=self.subcategory,
                qty=1,
                weight="2.0")
        item.save()
        
        # verify if the item is showing
        self.assertTrue(item.show)

        # add the item to cart
        self.cart.add(item, item.price, qty=1)
        self.cart.close('manual')

        # reload the item from db
        item = Item.objects.get(id=item.id)

        # verify if the item is showing and stock=0
        self.assertTrue(item.show)
        self.assertEqual(item.qty, 0)

        # change item sold_out_date and verify if the item is still showing
        past_date = datetime.datetime.now() - datetime.timedelta(days=13)
        item.sold_out_date = past_date
        item.update_show(True)
        self.assertTrue(item.show)

        # again, this time the item will not showing
        past_date = datetime.datetime.now() - datetime.timedelta(days=25)
        item.sold_out_date = past_date
        item.update_show(True)
        self.assertFalse(item.show)

        item.qty = 1
        item.save()
        self.assertTrue(item.show)

        item.qty = 0
        item.save()
        self.assertTrue(item.show)

        #
        past_date = datetime.datetime.now() - datetime.timedelta(days=25)
        item.sold_out_date = past_date
        item.update_show(True)
        self.assertFalse(item.show)
Exemple #5
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)