예제 #1
0
class LotTestCase(unittest.TestCase):
    
    def setUp(self):
        self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
        self.marketplace = MarketPlace(name="greatcoins", title="greatcoins", slug="greatcoins", 
                                       template_prefix="greatcoins", base_domain="greatcoins.com")
        self.marketplace.save()
        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()
        self.shop = Shop(marketplace=self.marketplace, admin=self.user, name="test shop")
        self.shop.save()
        

    def tearDown(self):
        self.user.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())
예제 #2
0
def form_view(request, user_id):
    if request.method == "POST":
        form = ShopForm(request.POST, request.FILES)
        k = 0
        places = Place.objects.all()

        obj = Place.objects.get(id=form['shop_place'].value())
        shop_owner = User.objects.get(id=user_id)
        sp = Shop(shop_image=form['shop_image'].value(),
                  shop_owner=shop_owner,
                  shop_itemtype=form['shop_itemtype'].value(),
                  shop_name=form['shop_name'].value(),
                  shop_place=obj,
                  shop_address=form['shop_address'].value(),
                  shop_contactinfo=form['shop_contactinfo'].value())
        sp.save()
        return render(request, 'hotels/redir.html')
    else:
        if (Shop.objects.filter(shop_owner_id=user_id).first()) is not None:
            temp = Shop.objects.filter(shop_owner_id=user_id).first()
            i = temp.id
            url = '/shops/shop/{}/'.format(i)
            return redirect(url)

        else:
            form = ShopForm()
            return render(request, 'shops/shop_form.html', {'form': form})
예제 #3
0
def shop_add(request):
  shopName = request.POST['shop']
  to_return = {'msg' : u'El nombre de la tienda no puede estar en blanco' }
  to_return['success'] = False
  if shopName:
    if not Shop.objects.filter(name=shopName).exists():
      data = {'name' : request.POST['shop'],
              'user' : request.user.id}
      form = ShopForm(data)
      #print form.errors
      if form.is_valid():
        shopNameCleaned = form.cleaned_data['name']
        if not Shop.objects.filter(user=request.user).exists():
          shop = Shop(name=shopNameCleaned, user=request.user)
        else:
          shop = Shop.objects.get(user=request.user)
          shop.name = shopNameCleaned
        shop.save()
        to_return['success'] = True
        to_return['url'] = u'/usuario/item/crear/'
      else:
        to_return['msg'] = form.errors
    else:
      to_return['msg']= {'name' : u'El nombre de la tienda ya esta tomado.'}
  serialized = simplejson.dumps(to_return)
  return HttpResponse(serialized, mimetype="application/json")
예제 #4
0
def shop_add(request):
    shopName = request.POST['shop']
    to_return = {'msg': u'El nombre de la tienda no puede estar en blanco'}
    to_return['success'] = False
    if shopName:
        if not Shop.objects.filter(name=shopName).exists():
            data = {'name': request.POST['shop'], 'user': request.user.id}
            form = ShopForm(data)
            #print form.errors
            if form.is_valid():
                shopNameCleaned = form.cleaned_data['name']
                if not Shop.objects.filter(user=request.user).exists():
                    shop = Shop(name=shopNameCleaned, user=request.user)
                else:
                    shop = Shop.objects.get(user=request.user)
                    shop.name = shopNameCleaned
                shop.save()
                to_return['success'] = True
                to_return['url'] = u'/usuario/item/crear/'
            else:
                to_return['msg'] = form.errors
        else:
            to_return['msg'] = {
                'name': u'El nombre de la tienda ya esta tomado.'
            }
    serialized = simplejson.dumps(to_return)
    return HttpResponse(serialized, mimetype="application/json")
예제 #5
0
 def setUp(self):
     self.owner = User.objects.create_user("owner", "*****@*****.**", "testpw")
     owner_profile = Profile(user=self.owner)
     owner_profile.save()
     self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
     self.user2 = User.objects.create_user("user2", "*****@*****.**", "user2")
     Profile(user=self.user).save()
     Profile(user=self.user2).save()
     
     self.marketplace = MarketPlace(name="greatsomething", title="Great Something", slug="great-something", 
                                    template_prefix="default", base_domain="greatsomething.com")
     self.marketplace.save()
     self.shop = Shop(marketplace=self.marketplace, admin=self.owner, name="test_shop")
     self.shop.save()
     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()
     self.category = MarketCategory(marketplace=self.marketplace, name="Category1")
     self.category.save()
     self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory1")
     self.subcategory.save()
     
     self.cart = Cart(shop=self.shop, bidder=self.user)
     self.cart.save()
     
     self.cart2 = Cart(shop=self.shop, bidder=self.user2)
     self.cart2.save()
예제 #6
0
 def get_object(self, queryset=None):
     try:
         shop = Shop.objects.get(owner=self.request.user)
     except Shop.DoesNotExist:
         shop = Shop(owner=self.request.user,
                     slug=self.request.user.username)
         shop.save()
     return shop
예제 #7
0
def create(request):
    # If this is a post request we insert the person
    if request.POST:
        shop = Shop(name=request.POST['name'],description=request.POST['description'],address=request.POST['address'],zip_code=request.POST['zip_code'],city=request.POST['city'],state=request.POST['state'],country=request.POST['country'])
        shop.save()
        all_shops = Shop.objects.all()
        context = {'all_shops': all_shops}
     
    return render(request, 'shops/all_shops.html', context) 
예제 #8
0
 def get_object(self, queryset=None):
     try:
         shop = Shop.objects.get(owner=self.request.user)
     except Shop.DoesNotExist:
         shop = Shop(
             owner=self.request.user,
             slug=self.request.user.username
         )
         shop.save()
     return shop
예제 #9
0
    def setUp(self):

        cwd = os.getcwd() + "/shops"  # Get the current working directory (cwd)
        cover_image = SimpleUploadedFile('images.jpeg',
                                         content=open(cwd + '/images.jpeg',
                                                      'rb').read(),
                                         content_type='image/jpeg')
        self.shop = Shop(title='Harry Potter',
                         author='JK Rowling',
                         price='25.00',
                         description='Harry and the ...',
                         published_year=2000,
                         cover=cover_image)

        self.shop.save()
예제 #10
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()
예제 #11
0
 def setUp(self):
     self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
     self.marketplace = MarketPlace(name="greatcoins", title="greatcoins", slug="greatcoins", 
                                    template_prefix="greatcoins", base_domain="greatcoins.com")
     self.marketplace.save()
     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()
     self.shop = Shop(marketplace=self.marketplace, admin=self.user, name="test shop")
     self.shop.save()
예제 #12
0
 def setUp(self):
     self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
     self.marketplace = MarketPlace(name="greatsomething", title="Great Something", slug="great-something", 
                                    template_prefix="default", base_domain="greatsomething.com")
     self.marketplace.save()
     self.shop = Shop(marketplace=self.marketplace, admin=self.user, name="test shop")
     self.shop.save()
     self.category = MarketCategory(marketplace=self.marketplace, name="Category1")
     self.category.save()
     self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory1")
     self.subcategory.save()
     self.cart = Cart(shop=self.shop, bidder=self.user)
     self.cart.save()
예제 #13
0
class ShopTests(TestCase):
    def setUp(self):

        cwd = os.getcwd() + "/shops"  # Get the current working directory (cwd)
        cover_image = SimpleUploadedFile('images.jpeg',
                                         content=open(cwd + '/images.jpeg',
                                                      'rb').read(),
                                         content_type='image/jpeg')
        self.shop = Shop(title='Harry Potter',
                         author='JK Rowling',
                         price='25.00',
                         description='Harry and the ...',
                         published_year=2000,
                         cover=cover_image)

        self.shop.save()

    def test_shop_list(self):
        self.assertEqual(f'{self.shop.title}', 'Harry Potter')
        self.assertEqual(f'{self.shop.author}', 'JK Rowling')
        self.assertEqual(f'{self.shop.price}', '25.00')
        self.assertEqual(f'{self.shop.description}', 'Harry and the ...')

    def test_shop_index_view(self):
        response = self.client.get(reverse('shops_index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Harry Potter')
        self.assertTemplateUsed(response, 'shops/index.html')

    def test_shop_detail_view(self):
        response = self.client.get(self.shop.get_absolute_url())
        self.assertEqual(response.status_code, 200)

        response1 = self.client.get('/show/34455')
        self.assertEqual(response1.status_code, 404)

        self.assertContains(response, 'Harry Potter')
        self.assertTemplateUsed(response, 'shops/show.html')
예제 #14
0
    def setUp(self):
        self.owner = User.objects.create_user("owner", "*****@*****.**", "testpw")
        owner_profile = Profile(user=self.owner)
        owner_profile.save()
        self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
        self.user2 = User.objects.create_user("user2", "*****@*****.**", "user2")
        Profile(user=self.user).save()
        Profile(user=self.user2).save()

        self.marketplace = MarketPlace(
            name="greatsomething",
            title="Great Something",
            slug="great-something",
            template_prefix="default",
            base_domain="greatsomething.com",
        )
        self.marketplace.save()
        self.shop = Shop(marketplace=self.marketplace, admin=self.owner, name="test_shop")
        self.shop.save()
        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()
        self.category = MarketCategory(marketplace=self.marketplace, name="Category1")
        self.category.save()
        self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory1")
        self.subcategory.save()

        self.cart = Cart(shop=self.shop, bidder=self.user)
        self.cart.save()

        self.cart2 = Cart(shop=self.shop, bidder=self.user2)
        self.cart2.save()
예제 #15
0
class BuyItemTestCase(TestCase):
    def setUp(self):
        self.owner = User.objects.create_user("owner", "*****@*****.**", "testpw")
        owner_profile = Profile(user=self.owner)
        owner_profile.save()
        self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
        self.user2 = User.objects.create_user("user2", "*****@*****.**", "user2")
        Profile(user=self.user).save()
        Profile(user=self.user2).save()

        self.marketplace = MarketPlace(
            name="greatsomething",
            title="Great Something",
            slug="great-something",
            template_prefix="default",
            base_domain="greatsomething.com",
        )
        self.marketplace.save()
        self.shop = Shop(marketplace=self.marketplace, admin=self.owner, name="test_shop")
        self.shop.save()
        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()
        self.category = MarketCategory(marketplace=self.marketplace, name="Category1")
        self.category.save()
        self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory1")
        self.subcategory.save()

        self.cart = Cart(shop=self.shop, bidder=self.user)
        self.cart.save()

        self.cart2 = Cart(shop=self.shop, bidder=self.user2)
        self.cart2.save()

    def tearDown(self):
        self.user.delete()
        self.marketplace.delete()
        self.category.delete()
        self.subcategory.delete()

    #        item.delete()

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

        shippingdata = ShippingData(
            street_address="Calle 8 n 182", city="La Plata", state="Buenos Aires", zip="1900", country="AR"
        )
        shippingdata.save()

        self.cart.shippingdata = shippingdata

        qty = item.qty
        # add an item to cart
        qty_to_buy = 2
        self.cart.add(item, item.price, qty=qty_to_buy)

        # check that qty item NOT decrease
        self.assertEqual(qty, item.qty)

        # check that item is in cart
        cart_item = self.cart.cartitem_set.all()[0]
        self.assertEqual(item, cart_item.product)

        # check cart methods
        self.assertEqual(self.cart.total_items(), qty_to_buy)
        self.assertEqual(self.cart.total_weight(), decimal.Decimal("4.0"))
        self.assertEqual(self.cart.total(), decimal.Decimal("20.0"))
        self.assertEqual(self.cart.total_with_taxes(), decimal.Decimal("20.0"))

        # clean the cart
        self.cart.clean()

        # recheck cart methods
        self.assertEqual(self.cart.total_items(), 0)
        self.assertEqual(self.cart.total_weight(), decimal.Decimal("0.0"))
        self.assertEqual(self.cart.total(), decimal.Decimal("0.0"))
        self.assertEqual(self.cart.total_with_taxes(), decimal.Decimal("0.0"))

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

        # load some taxes
        miami_tax = decimal.Decimal("2.5")
        tax_for_miami = TaxState(shop=self.shop, state="MI", tax=miami_tax)
        tax_for_miami.save()

        ny_tax = decimal.Decimal("1.5")
        tax_for_ny = TaxState(shop=self.shop, state="NY", tax=ny_tax)
        tax_for_ny.save()

        # add an item to the cart
        self.cart.add(item, item.price, qty=1)

        # set the shipping address
        shippingdata = ShippingData(
            street_address="Abey Road", city="Great Beach", state="MI", zip="11001", country="US"
        )
        shippingdata.save()
        self.cart.shippingdata = shippingdata

        # check that tax is correctly calculated
        self.assertEquals(self.cart.taxes(), miami_tax * decimal.Decimal(item.price) / decimal.Decimal("100.0"))
        self.assertNotEquals(self.cart.taxes(), ny_tax * decimal.Decimal(item.price) / decimal.Decimal("100.0"))

        # if shipping address is not MI or NY, no tax must be applied...
        shippingdata = ShippingData(
            street_address="Abey Road", city="Great Beach", state="IO", zip="11001", country="US"
        )
        shippingdata.save()
        self.cart.shippingdata = shippingdata

        self.assertEquals(self.cart.taxes(), decimal.Decimal("0.0"))

    def testShippingCharge(self):
        item = Item(
            shop=self.shop,
            title="item",
            description="an item",
            price="10.0",
            category=self.category,
            subcategory=self.subcategory,
            qty=5,
            weight="2.0",
        )
        item.save()
        # add an item to the cart
        self.cart.add(item, item.price, qty=3)

        # set the shipping address
        shippingdata = ShippingData(
            street_address="Abey Road", city="Great Beach", state="MI", zip="11001", country="US"
        )
        shippingdata.save()
        self.cart.shippingdata = shippingdata

        sw1 = ShippingWeight(
            shop=self.shop, name="Shipping by Weight", price="3.00", from_weight="0.0", to_weight="5.0"
        )
        sw1.save()
        sw2 = ShippingWeight(
            shop=self.shop, name="Shipping by Weight", price="5.00", from_weight="5.0", to_weight="10.0"
        )
        sw2.save()
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("5.0"))
        sw1.delete()
        sw2.delete()

        si1 = ShippingItem(shop=self.shop, name="Shipping by Item", price="9.00", from_item=0, to_item=3)
        si1.save()
        si2 = ShippingItem(shop=self.shop, name="Shipping by Item", price="19.00", from_item=3, to_item=5)
        si2.save()
        si3 = ShippingItem(shop=self.shop, name="Shipping by Item", price="29.00", from_item=5, to_item=15)
        si3.save()

        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("9.0"))
        si1.delete()
        si2.delete()
        si3.delete()

        pw1 = ShippingPrice(shop=self.shop, name="Shipping by Price", price="5.00", from_price="0.0", to_price="20.0")
        pw1.save()
        pw2 = ShippingPrice(shop=self.shop, name="Shipping by Price", price="9.00", from_price="20.0", to_price="40.0")
        pw2.save()
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("9.0"))
        pw1.delete()
        pw2.delete()

    def testCartClose(self):
        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()

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

        stock_item = item.qty
        stock_item2 = item2.qty

        shippingdata = ShippingData(
            street_address="Calle 8 n 182", city="La Plata", state="Buenos Aires", zip="1900", country="AR"
        )
        shippingdata.save()

        # add the shipping data
        self.cart.shippingdata = shippingdata
        self.cart.save()

        # add 2 items
        self.cart.add(item, item.price, qty=1)
        self.cart.add(item2, item2.price, qty=2)

        item = Item.objects.get(id=item.id)
        self.cart2.add(item, item.price, qty=1)

        item = Item.objects.get(id=item.id)
        self.assertEqual(stock_item, item.qty)
        self.assertEqual(stock_item2, item2.qty)

        success = self.client.login(username="******", password="******")
        self.assertEqual(success, True, "login failed")
        HTTP_HOST = self.shop.default_dns
        response = self.client.get(reverse("myshopping_checkout_shipping"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200)
        shipping_data = {
            "first_name": "User",
            "last_name": "Buyer",
            "street_address": "Street 54",
            "city": "Washington",
            "state": "DC",
            "zip": "12345-4321",
            "country": "United States",
        }
        response = self.client.post(reverse("myshopping_checkout_shipping"), shipping_data, HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 302)

        # cart and cart2 is availables
        self.assertTrue(self.cart.is_available())
        self.assertTrue(self.cart2.is_available())

        # close the cart
        sell = self.cart.close("manual")

        self.assertTrue(self.cart.is_available())

        # cart2 is not available
        self.assertFalse(self.cart2.is_available())

        response = self.client.get(reverse("myshopping_checkout_confirm"), HTTP_HOST=HTTP_HOST, follow=True)
        self.assertRedirects(response, reverse("my_shopping"), status_code=302, host=HTTP_HOST)
        logging.info("\t%s" % response.redirect_chain)

        item = Item.objects.get(id=item.id)
        item2 = Item.objects.get(id=item2.id)

        self.assertEqual(stock_item - 1, item.qty)
        self.assertEqual(stock_item2 - 2, item2.qty)

        # check that the sell object has the default values setted...
        self.assertEquals(self.cart.total_items(), 0)
        self.assertEquals(sell.closed, False)
        self.assertEquals(sell.sellitem_set.count(), 2)
        self.assertEquals(sell.payment.state_actual.state, "PE")
        self.assertEquals(sell.shipping.state_actual.state, "PE")
예제 #16
0
class BuyItemTestCase(unittest.TestCase):
    
    def setUp(self):
        self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
        self.marketplace = MarketPlace(name="greatsomething", title="Great Something", slug="great-something", 
                                       template_prefix="default", base_domain="greatsomething.com")
        self.marketplace.save()
        self.shop = Shop(marketplace=self.marketplace, admin=self.user, name="test shop")
        self.shop.save()
        self.category = MarketCategory(marketplace=self.marketplace, name="Category1")
        self.category.save()
        self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory1")
        self.subcategory.save()
        self.cart = Cart(shop=self.shop, bidder=self.user)
        self.cart.save()
        
        
    def tearDown(self):
        self.user.delete()
        self.marketplace.delete()
        self.category.delete()
        self.subcategory.delete()
#        item.delete()
    
    def testCartMethods(self):
        item = Item(shop=self.shop, 
                        title="item",
                        description="an item", 
                        price="10.0", 
                        category=self.category, 
                        subcategory=self.subcategory, 
                        qty=5, 
                        weight="2.0")
        item.save()
        
        
        shippingdata = ShippingData(street_address="Calle 8 n 182", city="La Plata", state="Buenos Aires", zip="1900", country="AR")
        shippingdata.save()

        self.cart.shippingdata = shippingdata
                
        qty = item.qty
        #add an item to cart
        qty_to_buy = 2
        self.cart.add(item, item.price, qty=qty_to_buy)
        
        #check that qty item decrease in one unit
        self.assertEqual(qty, item.qty + qty_to_buy)
        
        #check that item is in cart
        cart_item = self.cart.cartitem_set.all()[0]
        self.assertEqual(item, cart_item.product)
        
        #check cart methods
        self.assertEqual(self.cart.total_items(), qty_to_buy)
        self.assertEqual(self.cart.total_weight() , decimal.Decimal("4.0"))
        self.assertEqual(self.cart.total(), decimal.Decimal("20.0"))
        self.assertEqual(self.cart.total_with_taxes(), decimal.Decimal("20.0"))
        
        #clean the cart
        self.cart.clean()
        
        #recheck cart methods
        self.assertEqual(self.cart.total_items(), 0)
        self.assertEqual(self.cart.total_weight() , decimal.Decimal("0.0"))
        self.assertEqual(self.cart.total(), decimal.Decimal("0.0"))
        self.assertEqual(self.cart.total_with_taxes(), decimal.Decimal("0.0"))
        
        
    def testTaxCalculation(self):
        item = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=5, 
                weight="2.0")
        item.save()
        
        #load some taxes 
        miami_tax = decimal.Decimal("2.5")
        tax_for_miami = TaxState(shop=self.shop, state="MI", tax=miami_tax)
        tax_for_miami.save()
        
        ny_tax = decimal.Decimal("1.5")
        tax_for_ny = TaxState(shop=self.shop, state="NY", tax=ny_tax)
        tax_for_ny.save()
        
        #add an item to the cart
        self.cart.add(item, item.price, qty=1)
        
        #set the shipping address        
        shippingdata = ShippingData(street_address="Abey Road", city="Great Beach", state="MI", zip="11001", country="US")
        shippingdata.save()
        self.cart.shippingdata = shippingdata
      
        #check that tax is correctly calculated
        self.assertEquals(self.cart.taxes(), miami_tax * decimal.Decimal(item.price) / decimal.Decimal("100.0"))
        self.assertNotEquals(self.cart.taxes(), ny_tax * decimal.Decimal(item.price) / decimal.Decimal("100.0"))

        #if shipping address is not MI or NY, no tax must be applied...
        shippingdata = ShippingData(street_address="Abey Road", city="Great Beach", state="IO", zip="11001", country="US")
        shippingdata.save()
        self.cart.shippingdata = shippingdata

        self.assertEquals(self.cart.taxes(), decimal.Decimal("0.0") )        
        
        
    def testShippingCharge(self):
        item = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=5, 
                weight="2.0")
        item.save()
        #add an item to the cart
        self.cart.add(item, item.price, qty=3)
        
        #set the shipping address        
        shippingdata = ShippingData(street_address="Abey Road", city="Great Beach", state="MI", zip="11001", country="US")
        shippingdata.save()
        self.cart.shippingdata = shippingdata
        
        sw1 = ShippingWeight(shop=self.shop, name="Shipping by Weight", price="3.00", from_weight="0.0", to_weight="5.0")
        sw1.save()
        sw2 = ShippingWeight(shop=self.shop, name="Shipping by Weight", price="5.00", from_weight="5.0", to_weight="10.0")
        sw2.save()
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("5.0"))
        sw1.delete()
        sw2.delete()
        
        si1 = ShippingItem(shop=self.shop, name="Shipping by Item", price="9.00", from_item=0, to_item=3)
        si1.save()
        si2 = ShippingItem(shop=self.shop, name="Shipping by Item", price="19.00", from_item=3, to_item=5)
        si2.save()
        si3 = ShippingItem(shop=self.shop, name="Shipping by Item", price="29.00", from_item=5, to_item=15)
        si3.save()
        
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("9.0"))
        si1.delete()
        si2.delete()
        si3.delete()
        
        pw1 = ShippingPrice(shop=self.shop, name="Shipping by Price", price="5.00", from_price="0.0", to_price="20.0")
        pw1.save()
        pw2 = ShippingPrice(shop=self.shop, name="Shipping by Price", price="9.00", from_price="20.0", to_price="40.0")
        pw2.save()
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("9.0"))
        pw1.delete()
        pw2.delete()
        
        
    def testCartClose(self):
        item = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=2, 
                weight="2.0")
        item.save()
        
        item2 = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=2, 
                weight="2.0")
        item2.save()
        
        shippingdata = ShippingData(street_address="Calle 8 n 182", city="La Plata", state="Buenos Aires", zip="1900", country="AR")
        shippingdata.save()
        
        #add the shipping data
        self.cart.shippingdata = shippingdata
        self.cart.save()
        
        #add 2 items
        self.cart.add(item, item.price, qty=1)
        self.cart.add(item2, item.price, qty=2)
        
        #close the cart
        sell = self.cart.close("manual")
        
        #check that the sell object has the default values setted... 
        self.assertEquals(self.cart.total_items(), 0)
        self.assertEquals(sell.closed, False)
        self.assertEquals(sell.sellitem_set.count(), 2)
        self.assertEquals(sell.payment.state_actual.state, "PE")
        self.assertEquals(sell.shipping.state_actual.state, "PE")
        
        
예제 #17
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)
예제 #18
0
 def get_context_data(self, **kwargs):
     kwargs['shop_list'] = Shop.list_ranking(head=3)
     kwargs['review_list'] = Review.list_latest()[:10]
     return super().get_context_data(**kwargs)
예제 #19
0
class BuyItemTestCase(TestCase):
    
    def setUp(self):
        self.owner = User.objects.create_user("owner", "*****@*****.**", "testpw")
        owner_profile = Profile(user=self.owner)
        owner_profile.save()
        self.user = User.objects.create_user("test", "*****@*****.**", "testpw")
        self.user2 = User.objects.create_user("user2", "*****@*****.**", "user2")
        Profile(user=self.user).save()
        Profile(user=self.user2).save()
        
        self.marketplace = MarketPlace(name="greatsomething", title="Great Something", slug="great-something", 
                                       template_prefix="default", base_domain="greatsomething.com")
        self.marketplace.save()
        self.shop = Shop(marketplace=self.marketplace, admin=self.owner, name="test_shop")
        self.shop.save()
        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()
        self.category = MarketCategory(marketplace=self.marketplace, name="Category1")
        self.category.save()
        self.subcategory = MarketSubCategory(marketplace=self.marketplace, parent=self.category, name="SubCategory1")
        self.subcategory.save()
        
        self.cart = Cart(shop=self.shop, bidder=self.user)
        self.cart.save()
        
        self.cart2 = Cart(shop=self.shop, bidder=self.user2)
        self.cart2.save()
        
        
    def tearDown(self):
        self.user.delete()
        self.marketplace.delete()
        self.category.delete()
        self.subcategory.delete()
#        item.delete()
    
    def testCartMethods(self):
        item = Item(shop=self.shop, 
                        title="item",
                        description="an item", 
                        price="10.0", 
                        category=self.category, 
                        subcategory=self.subcategory, 
                        qty=5, 
                        weight="2.0")
        item.save()
        
        
        shippingdata = ShippingData(street_address="Calle 8 n 182", city="La Plata", state="Buenos Aires", zip="1900", country="AR")
        shippingdata.save()

        self.cart.shippingdata = shippingdata
                
        qty = item.qty
        #add an item to cart
        qty_to_buy = 2
        self.cart.add(item, item.price, qty=qty_to_buy)
        
        #check that qty item NOT decrease
        self.assertEqual(qty, item.qty)
        
        #check that item is in cart
        cart_item = self.cart.cartitem_set.all()[0]
        self.assertEqual(item, cart_item.product)
        
        #check cart methods
        self.assertEqual(self.cart.total_items(), qty_to_buy)
        self.assertEqual(self.cart.total_weight() , decimal.Decimal("4.0"))
        self.assertEqual(self.cart.total(), decimal.Decimal("20.0"))
        self.assertEqual(self.cart.total_with_taxes(), decimal.Decimal("20.0"))
        
        #clean the cart
        self.cart.clean()
        
        #recheck cart methods
        self.assertEqual(self.cart.total_items(), 0)
        self.assertEqual(self.cart.total_weight() , decimal.Decimal("0.0"))
        self.assertEqual(self.cart.total(), decimal.Decimal("0.0"))
        self.assertEqual(self.cart.total_with_taxes(), decimal.Decimal("0.0"))
        
        
    def testTaxCalculation(self):
        item = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=5, 
                weight="2.0")
        item.save()
        
        #load some taxes 
        miami_tax = decimal.Decimal("2.5")
        tax_for_miami = TaxState(shop=self.shop, state="MI", tax=miami_tax)
        tax_for_miami.save()
        
        ny_tax = decimal.Decimal("1.5")
        tax_for_ny = TaxState(shop=self.shop, state="NY", tax=ny_tax)
        tax_for_ny.save()
        
        #add an item to the cart
        self.cart.add(item, item.price, qty=1)
        
        #set the shipping address        
        shippingdata = ShippingData(street_address="Abey Road", city="Great Beach", state="MI", zip="11001", country="US")
        shippingdata.save()
        self.cart.shippingdata = shippingdata
      
        #check that tax is correctly calculated
        self.assertEquals(self.cart.taxes(), miami_tax * decimal.Decimal(item.price) / decimal.Decimal("100.0"))
        self.assertNotEquals(self.cart.taxes(), ny_tax * decimal.Decimal(item.price) / decimal.Decimal("100.0"))

        #if shipping address is not MI or NY, no tax must be applied...
        shippingdata = ShippingData(street_address="Abey Road", city="Great Beach", state="IO", zip="11001", country="US")
        shippingdata.save()
        self.cart.shippingdata = shippingdata

        self.assertEquals(self.cart.taxes(), decimal.Decimal("0.0") )        
        
        
    def testShippingCharge(self):
        item = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=5, 
                weight="2.0")
        item.save()
        #add an item to the cart
        self.cart.add(item, item.price, qty=3)
        
        #set the shipping address        
        shippingdata = ShippingData(street_address="Abey Road", city="Great Beach", state="MI", zip="11001", country="US")
        shippingdata.save()
        self.cart.shippingdata = shippingdata
        
        sw1 = ShippingWeight(shop=self.shop, name="Shipping by Weight", price="3.00", from_weight="0.0", to_weight="5.0")
        sw1.save()
        sw2 = ShippingWeight(shop=self.shop, name="Shipping by Weight", price="5.00", from_weight="5.0", to_weight="10.0")
        sw2.save()
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("5.0"))
        sw1.delete()
        sw2.delete()
        
        si1 = ShippingItem(shop=self.shop, name="Shipping by Item", price="9.00", from_item=0, to_item=3)
        si1.save()
        si2 = ShippingItem(shop=self.shop, name="Shipping by Item", price="19.00", from_item=3, to_item=5)
        si2.save()
        si3 = ShippingItem(shop=self.shop, name="Shipping by Item", price="29.00", from_item=5, to_item=15)
        si3.save()
        
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("9.0"))
        si1.delete()
        si2.delete()
        si3.delete()
        
        pw1 = ShippingPrice(shop=self.shop, name="Shipping by Price", price="5.00", from_price="0.0", to_price="20.0")
        pw1.save()
        pw2 = ShippingPrice(shop=self.shop, name="Shipping by Price", price="9.00", from_price="20.0", to_price="40.0")
        pw2.save()
        self.assertEquals(self.cart.shipping_charge(), decimal.Decimal("9.0"))
        pw1.delete()
        pw2.delete()
        
        
    def testCartClose(self):
        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()
        
        item2 = Item(shop=self.shop, 
                title="item",
                description="an item", 
                price="10.0", 
                category=self.category, 
                subcategory=self.subcategory, 
                qty=2, 
                weight="2.0")
        item2.save()

        stock_item = item.qty
        stock_item2 = item2.qty
        
        shippingdata = ShippingData(street_address="Calle 8 n 182", city="La Plata", state="Buenos Aires", zip="1900", country="AR")
        shippingdata.save()
        
        #add the shipping data
        self.cart.shippingdata = shippingdata
        self.cart.save()
        
        #add 2 items
        self.cart.add(item, item.price, qty=1)
        self.cart.add(item2, item2.price, qty=2)
        
        item = Item.objects.get(id=item.id)
        self.cart2.add(item, item.price, qty=1)
        
        item = Item.objects.get(id=item.id)
        self.assertEqual(stock_item, item.qty)
        self.assertEqual(stock_item2, item2.qty)
        
        success = self.client.login(username='******', password='******')
        self.assertEqual(success, True, "login failed")
        HTTP_HOST = self.shop.default_dns
        response = self.client.get(reverse("myshopping_checkout_shipping"), HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 200)
        shipping_data = { 
            'first_name': 'User',
            'last_name': 'Buyer',
            'street_address': 'Street 54',
            'city': 'Washington',
            'state': 'DC',
            'zip': '12345-4321',
            'country': 'United States',
        }
        response = self.client.post(reverse("myshopping_checkout_shipping"), shipping_data, HTTP_HOST=HTTP_HOST)
        self.assertEqual(response.status_code, 302)


        # cart and cart2 is availables
        self.assertTrue(self.cart.is_available())
        self.assertTrue(self.cart2.is_available())
        
        #close the cart
        sell = self.cart.close("manual")
        
        self.assertTrue(self.cart.is_available())

        # cart2 is not available
        self.assertFalse(self.cart2.is_available())
         
        response = self.client.get(reverse("myshopping_checkout_confirm"), HTTP_HOST=HTTP_HOST,  follow=True)
        self.assertRedirects(response, reverse('my_shopping'),  status_code=302, host=HTTP_HOST)
        logging.info('\t%s' % response.redirect_chain)

        item = Item.objects.get(id=item.id)
        item2 = Item.objects.get(id=item2.id)
        
        self.assertEqual(stock_item - 1, item.qty)
        self.assertEqual(stock_item2 - 2, item2.qty)
        
        #check that the sell object has the default values setted... 
        self.assertEquals(self.cart.total_items(), 0)
        self.assertEquals(sell.closed, False)
        self.assertEquals(sell.sellitem_set.count(), 2)
        self.assertEquals(sell.payment.state_actual.state, "PE")
        self.assertEquals(sell.shipping.state_actual.state, "PE")