示例#1
0
    def setUp(self):
        u = User(username='******',
                 email='*****@*****.**',
                 is_active=True)
        u.set_password('johnpassword')
        u.save()
        p = Profile(user=u,
                       campaign_cid='0',
                       sid='0',
                       affiliate='0',
                       phone='(555) 555-5555',
                       shipping_address1="9518 New Waterford Cv",
                       shipping_zip="33446-9747",
                       shipping_state="FL",
                       shipping_city="Delray Beach",
                       shipping_county="Palm Beach",
                       shipping_checksum="0d35b4ffcb260482947680f48ba8e482",
                       )
        p.save()

        billing_card = BillingCard(user=u,
                type="visa",
                display_number="XXXX-XXXX-XXXX-1150",
                data = "XnSDaVgvyOUaZmrftFo0rKPFhyHdf+E6WyMxz45cG6yk4kr6ob0A+6mxnY8Xrf2IMXBEIBrNN7FhvyzpGb77JX0PG1sl8rDKhdPNMsa8xBt9pzVee9nsUXm3GYo2VRLpGLPrRoBphEPkdnGw",
                first_name="Mvi",
                last_name="Mvi",
                address1="9518 New Waterford Cv",
                address2="",
                city="Delray Beach",
                state="FL",
                county="Palm Beach",
                zip="33446-9747",
                checksum="670bee769cd1e3644e411110a6b32dd4",
                address_checksum="3e3c98e96e4dd335c59629b323892b5a"
        )
        billing_card.save()
        self.user = u
        self.game_item = Item.objects.get(pk=100000077)
        #creating a distributor and an entry in stock for this game
        self.fake_distributor = Distributor(id=5,name='fake distributor', address='fake address',new_games_vendor=True)
        self.fake_distributor.save()
        self.game_distributor_item = DistributorItem(distributor=self.fake_distributor,
            item=self.game_item,
            is_new=True,
            retail_price=Decimal('18.99'),
            wholesale_price=Decimal('18.99'),
            quantity=50,
            profit=1,
            retail_price_used_vendor=Decimal('11.99'),
            wholesale_price_used=Decimal('11.99'),
            quantity_used=10,
            trade_price=Decimal('11.99'),
            trade_price_incomplete=Decimal('5.99')
        )
        self.game_distributor_item.save()
示例#2
0
 def setUp(self):
     raise SkipTest
     self.game_item = Item.objects.get(pk=100000077)
     #creating a distributor and an entry in stock for this game
     self.fake_distributor = Distributor(id=5,name='fake distributor', address='fake address',new_games_vendor=True)
     self.fake_distributor.save()
     self.game_distributor_item = DistributorItem(distributor=self.fake_distributor,
         item=self.game_item,
         is_new=True,
         retail_price=Decimal('18.99'),
         wholesale_price=Decimal('18.99'),
         quantity=50,
         profit=1,
         retail_price_used_vendor=Decimal('11.99'),
         wholesale_price_used=Decimal('11.99'),
         quantity_used=10,
         trade_price=Decimal('11.99'),
         trade_price_incomplete=Decimal('5.99')
     )
     self.game_distributor_item.save()
示例#3
0
class TestWizards(TestCase):
    fixtures = ['categories','genres','publishers','types','test_item','dropships']
    def setUp(self):
        u = User(username='******',
                 email='*****@*****.**',
                 is_active=True)
        u.set_password('johnpassword')
        u.save()
        p = Profile(user=u,
                       campaign_cid='0',
                       sid='0',
                       affiliate='0',
                       phone='(555) 555-5555',
                       shipping_address1="9518 New Waterford Cv",
                       shipping_zip="33446-9747",
                       shipping_state="FL",
                       shipping_city="Delray Beach",
                       shipping_county="Palm Beach",
                       shipping_checksum="0d35b4ffcb260482947680f48ba8e482",
                       )
        p.save()

        billing_card = BillingCard(user=u,
                type="visa",
                display_number="XXXX-XXXX-XXXX-1150",
                data = "XnSDaVgvyOUaZmrftFo0rKPFhyHdf+E6WyMxz45cG6yk4kr6ob0A+6mxnY8Xrf2IMXBEIBrNN7FhvyzpGb77JX0PG1sl8rDKhdPNMsa8xBt9pzVee9nsUXm3GYo2VRLpGLPrRoBphEPkdnGw",
                first_name="Mvi",
                last_name="Mvi",
                address1="9518 New Waterford Cv",
                address2="",
                city="Delray Beach",
                state="FL",
                county="Palm Beach",
                zip="33446-9747",
                checksum="670bee769cd1e3644e411110a6b32dd4",
                address_checksum="3e3c98e96e4dd335c59629b323892b5a"
        )
        billing_card.save()
        self.user = u
        self.game_item = Item.objects.get(pk=100000077)
        #creating a distributor and an entry in stock for this game
        self.fake_distributor = Distributor(id=5,name='fake distributor', address='fake address',new_games_vendor=True)
        self.fake_distributor.save()
        self.game_distributor_item = DistributorItem(distributor=self.fake_distributor,
            item=self.game_item,
            is_new=True,
            retail_price=Decimal('18.99'),
            wholesale_price=Decimal('18.99'),
            quantity=50,
            profit=1,
            retail_price_used_vendor=Decimal('11.99'),
            wholesale_price_used=Decimal('11.99'),
            quantity_used=10,
            trade_price=Decimal('11.99'),
            trade_price_incomplete=Decimal('5.99')
        )
        self.game_distributor_item.save()


    def test_checkout(self):
        c = Client()
        c.login(username='******',password='******')
        response = c.get('/Cart/Add/100000077/',HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        response = c.post('/Cart/Add/100000077/',dict(condition='new',submit='cart'),HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        response = c.get('/Cart/Checkout/',HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        #response = c.post('/Cart/Checkout/',{
        #    "0-first_name":"Mvi",
        #    "0-last_name":"Mvi",
        #    "0-address1":"9518 New Waterford Cv",
        #    "0-address2":"",
        #    "0-city":"Delray Beach",
        #    "0-state":"FL",
        #    "0-zip_code":"33446-9747",
        #    "wizard_step":"0"
        #},HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        import fudge
        @fudge.patch('urllib2.urlopen','random.choice')
        def test(fake_urlopen,fake_choice):
            #faking an error in urllib2
            fake_urlopen.is_callable().raises(Exception("error"))
            #faking a choice that is made at the authorizenet api when in test mode to accept the order
            fake_choice.is_callable().returns(False)
            response = c.post('/Cart/Checkout/',{
                "1-first_name":"Mvi",
                "1-last_name":"Mvi",
                "1-address1":"9518 New Waterford Cv",
                "1-address2":"",
                "1-city":"Delray Beach",
                "1-state":"FL",
                "1-zip_code":"33446-9747",
                "1-type":"visa",
                "1-number":"4111111111111150",
                "1-exp_month":"3",
                "1-exp_year":"2011",
                "1-code":"123",
                "0-first_name":"Mvi",
                "0-last_name":"Mvi",
                "0-address1":"9518 New Waterford Cv",
                "0-address2":"",
                "0-city":"Delray Beach",
                "0-state":"FL",
                "0-zip_code":"33446-9747",
                "hash_0":"3081159020514cc7dbe50aa208897880877ef7d9",
                "wizard_step":"1"
            },HTTP_X_REQUESTED_WITH='XMLHttpRequest')
            return response

        test_reponse = test()
        #now, making sure there are no ghost buyorder
        buy_orders = BuyOrder.objects.filter(user=self.user).exclude(status=BuyOrderStatus.Checkout).count()
        #import pdb;pdb.set_trace()
        self.assertEqual(buy_orders,0)

    def test_store_credit_checkout(self):
        c = Client()
        c.login(username='******',password='******')
        p = self.user.get_profile()
        p.store_credits = Decimal("18.99")
        p.locked_store_credits = Decimal("10.00")
        p.save()

        response = c.get('/Cart/Add/100000077/',HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        response = c.post('/Cart/Add/100000077/',dict(condition='new',submit='cart'),HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        response = c.get('/Cart/')
        import re
        p = re.compile(r"store_credits: parseFloat\('(?P<credit>[0-9\.]+)'\)")
        match = p.search(response.content)
        store_credits_shown = match.groupdict()['credit']
        response = c.post('/Cart/Apply-Credits/', dict(amount=store_credits_shown), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        response = c.get('/Cart/Checkout/',HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        #response = c.post('/Cart/Checkout/',{
        #    "0-first_name":"Mvi",
        #    "0-last_name":"Mvi",
        #    "0-address1":"9518 New Waterford Cv",
        #    "0-address2":"",
        #    "0-city":"Delray Beach",
        #    "0-state":"FL",
        #    "0-zip_code":"33446-9747",
        #    "wizard_step":"0"
        #},HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        response = c.post('/Cart/Checkout/',{
            "1-first_name":"Mvi",
            "1-last_name":"Mvi",
            "1-address1":"9518 New Waterford Cv",
            "1-address2":"",
            "1-city":"Delray Beach",
            "1-state":"FL",
            "1-zip_code":"33446-9747",
            "1-type":"visa",
            "1-number":"4111111111111150",
            "1-exp_month":"3",
            "1-exp_year":"2011",
            "1-code":"123",
            "0-first_name":"Mvi",
            "0-last_name":"Mvi",
            "0-address1":"9518 New Waterford Cv",
            "0-address2":"",
            "0-city":"Delray Beach",
            "0-state":"FL",
            "0-zip_code":"33446-9747",
            "hash_0":"3081159020514cc7dbe50aa208897880877ef7d9",
            "wizard_step":"1"
        },HTTP_X_REQUESTED_WITH='XMLHttpRequest')


        #now, making sure there are no ghost buyorder
        buy_orders = BuyOrder.objects.filter(user=self.user).exclude(status=BuyOrderStatus.Checkout).count()
        #import pdb;pdb.set_trace()
        self.assertEqual(buy_orders,0)
示例#4
0
class TestWizards(TestCase):
    fixtures = ['categories','genres','publishers','types','test_item','dropships','rental_plans']
    def setUp(self):
        raise SkipTest
        self.game_item = Item.objects.get(pk=100000077)
        #creating a distributor and an entry in stock for this game
        self.fake_distributor = Distributor(id=5,name='fake distributor', address='fake address',new_games_vendor=True)
        self.fake_distributor.save()
        self.game_distributor_item = DistributorItem(distributor=self.fake_distributor,
            item=self.game_item,
            is_new=True,
            retail_price=Decimal('18.99'),
            wholesale_price=Decimal('18.99'),
            quantity=50,
            profit=1,
            retail_price_used_vendor=Decimal('11.99'),
            wholesale_price_used=Decimal('11.99'),
            quantity_used=10,
            trade_price=Decimal('11.99'),
            trade_price_incomplete=Decimal('5.99')
        )
        self.game_distributor_item.save()


    def test_nonmember_rental_signup(self):
        import re
        c = Client()
        response = c.get('/Rent/Add/100000077/',HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        response = c.post('/Rent/Add/100000077/',HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        json_response = json.loads(response.content)
        wizard_url = json_response['goto_url']

        response = c.get(wizard_url,HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        form_data = {'0-plan':RentalPlan.PlanB}
        response = c.post(wizard_url,form_data.copy(),HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        json_response = json.loads(response.content)
        form_html = json_response['form']
        hash_0 = re.search(r'hash_0" value="(?P<hash_0>[^"]*)',form_html).groupdict()['hash_0']

        form_data['1-address1'] = '306 Broadway'
        form_data['1-address2'] = ''
        form_data['1-city'] = 'New York'
        form_data['1-confirm_password'] = '******'
        form_data['1-email'] = '*****@*****.**'
        form_data['1-first_name'] = 'Mauricio'
        form_data['1-how_did_you_hear'] = '1'
        form_data['1-last_name'] = 'Lima'
        form_data['1-password'] = '******'
        form_data['1-phone_number'] = '(555) 888-9999'
        form_data['1-state'] = 'NY'
        form_data['1-username'] = '******'
        form_data['1-zip_code'] = '10007-1223'
        form_data['hash_0'] = hash_0
        form_data['wizard_step'] = '1'
        response = c.post(wizard_url,form_data.copy(),HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        json_response = json.loads(response.content)
        form_html = json_response['form']
        hash_1 = re.search(r'hash_1" value="(?P<hash_1>[^"]*)',form_html).groupdict()['hash_1']


        form_data['2-address1'] = '306 Broadway'
        form_data['2-address2'] = ''
        form_data['2-city'] = 'New York'
        form_data['2-code'] = '111'
        form_data['2-exp_month'] = '3'
        form_data['2-exp_year'] = '2013'
        form_data['2-first_name'] = 'Mauricio'
        form_data['2-last_name'] = 'Lima'
        form_data['2-number'] = '4111111111111114'
        form_data['2-state'] = 'NY'
        form_data['2-type'] = 'visa'
        form_data['2-zip_code'] = '10007-1223'
        form_data['hash_1'] = hash_1
        form_data['wizard_step'] = '2'

        response = c.post(wizard_url,form_data.copy(),HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(response.status_code, 200)
        u = User.objects.get(username='******')
        user_rental_plan = MemberRentalPlan.objects.get(user=u)
        self.assertEqual(user_rental_plan.plan, RentalPlan.PlanB)
        self.assertEqual(user_rental_plan.status, RentalPlanStatus.Active)

        self.assertEqual(len(mail.outbox), 1)
示例#5
0
def upload__used(request, **kwargs):
    class UploadInventoryForm(forms.Form):
        retailer = forms.ModelChoiceField(Distributor.objects.filter(new_games_vendor=False))
        file = forms.FileField()

    message = None    
    not_founded_upc = []
    if request.method == 'POST':
        form = UploadInventoryForm(request.POST, request.FILES)
        if form.is_valid():
            dtn = datetime.datetime.now()
            reader = csv.reader(form.cleaned_data['file'], delimiter='\t')
            
            lineno = 0
            unrecognized_lines = []
            founded_upc = []
            error_upc = []
            
            retailer = form.cleaned_data['retailer']
            retailer.items.all().delete()
            
            for row in reader:
                lineno += 1
                if lineno == 1:
                    continue
                
                try:
                    UPC, PRODUCT_NAME, PLATFORM, WHOLESALE_PRICE, QUANTITY, DROPSHIP_KEY_GAMEMINE, DISTRIBUTOR, CONDITION = row #@UnusedVariable
                except:
                    unrecognized_lines.append(lineno)
                    continue
                try:
                    item = Item.objects.get(upc=UPC)
                    founded_upc.append(UPC)
                    
                    di = DistributorItem(
                        distributor = retailer,
                        item=item,
                        wholesale_price = WHOLESALE_PRICE.replace('$',''),
                        quantity = QUANTITY,
                        is_new=False,
                    )
                    di.save()
                    
                except Item.DoesNotExist:
                    not_founded_upc.append(row)
                except:
                    import traceback
                    traceback.print_exc()
                    error_upc.append((UPC, lineno, row)) 

            message = """
Elapsed Time: %s<br />
Total Lines: %d<br />
Unrecognized Lines: %d<br />
Found UPC: %d<br />
Not Found UPC: %d<br />
Error UPC: %d<br />
            """ % (datetime.datetime.now()-dtn, lineno, len(unrecognized_lines), len(founded_upc), len(not_founded_upc), len(error_upc))
            
            if len(error_upc)>0:
                message += '<p><b>Errors:</b><ul>\n'
                message += ''.join("<li>line:%d | %s</li>\n" % (lineno, str(row)) for (upc, lineno, row) in error_upc) #@UnusedVariable
                message += '</ul>\n'
                
            r = ReportUpload(
                created = datetime.datetime.now(),
                type = 'New Inventory and Price',
                source = form.cleaned_data['file'],
                report = message.replace('<br />', ''),
                unknown_upc_count = len(not_founded_upc),
                unknown_upc = '\n'.join(map(lambda x: '\t'.join(x), not_founded_upc))
            )
            r.save()
    else:
        form = UploadInventoryForm()

    return {
        'title': 'Upload Used Inventory Feed',
        'form': form,
        'message': message,
        'not_found': '\n'.join(map(lambda x: '\t'.join(x), not_founded_upc)),
    }, None