Пример #1
0
    def test_create(self):
        """Test the create method."""
        site_configuration = SiteConfigurationFactory(partner__name='TestX')
        site = SiteFactory()
        site.siteconfiguration = site_configuration
        data = {
            'title': 'Test coupon',
            'client_username': '******',
            'stock_record_ids': [1],
            'start_date': '2015-1-1',
            'end_date': '2020-1-1',
            'code': '',
            'benefit_type': Benefit.PERCENTAGE,
            'benefit_value': 100,
            'voucher_type': Voucher.SINGLE_USE,
            'quantity': 1,
            'price': 100
        }
        request = RequestFactory()
        request.data = data
        request.site = site

        response = CouponViewSet().create(request)

        self.assertEqual(response.status_code, 200)
        self.assertDictEqual(
            response.data,
            {'payment_data': {'payment_processor_name': 'Invoice'}, 'id': 1, 'order': 1, 'coupon_id': 3}
        )
    def test_with_orders(self):
        """
        The view should return a list of the user's orders, sorted reverse chronologically, filtered by current site.
        """
        order = create_order(site=self.site, user=self.user)
        create_order(site=SiteFactory(), user=self.user)
        response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)

        self.assertEqual(Order.objects.count(), 2)
        self.assertEqual(content['count'], 1)
        self.assertEqual(content['results'][0]['number'],
                         unicode(order.number))

        # Test ordering
        order_2 = create_order(site=self.site, user=self.user)
        response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)

        self.assertEqual(content['count'], 2)
        self.assertEqual(content['results'][0]['number'],
                         unicode(order_2.number))
        self.assertEqual(content['results'][1]['number'],
                         unicode(order.number))
Пример #3
0
 def test_voucher_not_valid_for_other_site(self):
     """ Verify correct error message is returned when coupon is applied against on the wrong site. """
     site2 = SiteFactory()
     self.mock_access_token_response()
     self.mock_account_api(self.request, self.user.username, data={'is_active': True})
     voucher, product = prepare_voucher(code=COUPON_CODE, site=site2)
     self.basket.add_product(product)
     self.assert_form_valid_message("Coupon code '{code}' is not valid for this basket.".format(code=voucher.code))
Пример #4
0
    def test_create(self):
        """Test the create method."""
        site_configuration = SiteConfigurationFactory(partner__name='TestX')
        site = SiteFactory()
        site.siteconfiguration = site_configuration
        self.coupon_data.update({
            'title': 'Test coupon',
            'client_username': '******',
            'stock_record_ids': [1],
            'voucher_type': Voucher.SINGLE_USE,
            'price': 100,
            'category_ids': [self.category.id]
        })
        request = RequestFactory()
        request.data = self.coupon_data
        request.site = site

        response = CouponViewSet().create(request)

        self.assertEqual(response.status_code, 200)
        self.assertDictEqual(
            response.data,
            {'payment_data': {'payment_processor_name': 'Invoice'}, 'id': 1, 'order': 1, 'coupon_id': 3}
        )
Пример #5
0
 def setup_site_configuration(self):
     site_configuration = SiteConfigurationFactory(partner__name='TestX')
     site = SiteFactory()
     site.siteconfiguration = site_configuration
     return site
Пример #6
0
 def setup_site_configuration(self):
     site_configuration = SiteConfigurationFactory(partner__name='TestX')
     site = SiteFactory()
     site.siteconfiguration = site_configuration
     return site
Пример #7
0
    def test_site(self):
        """ Verify the site is stored in the session. """
        user = self.create_user(is_staff=True)
        self.client.login(username=user.username, password=self.password)
        site = SiteFactory()

        self.assertEqual(ConditionalOffer.objects.count(), 0)

        # Start creating the offer by defining by setting the name and site
        metadata = {
            'name': 'Test Offer',
            'description': 'Blah!',
            'site': site.id,
        }
        metadata_url = reverse('dashboard:offer-metadata')
        response = self.client.post(metadata_url, metadata)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'],
                         reverse('dashboard:offer-benefit'))

        # Ensure the Site ID is stored in the session
        actual = json.loads(
            self.client.session['offer_wizard']['metadata'])['data']['site_id']
        self.assertEqual(actual, site.id)

        # Set the offer benfit data
        offer_range = RangeFactory()
        data = {
            'range': offer_range.id,
            'type': Benefit.PERCENTAGE,
            'value': 100
        }
        response = self.client.post(response['Location'], data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'],
                         reverse('dashboard:offer-condition'))

        # Set the restrictions on the offer
        restrictions_url = reverse('dashboard:offer-restrictions')
        data = {'range': offer_range.id, 'type': Condition.COUNT, 'value': 1}
        response = self.client.post(response['Location'], data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], restrictions_url)

        # Reload the first page to exercise _fetch_form_kwargs, which should pull the site from the session
        response = self.client.get(metadata_url)
        self.assertEqual(response.status_code, 200)

        # Finish saving the offer
        data = {}
        response = self.client.post(restrictions_url, data)
        self.assertEqual(response.status_code, 302)

        self.assertEqual(ConditionalOffer.objects.count(), 1)
        offer = ConditionalOffer.objects.first()
        self.assertEqual(
            response['Location'],
            reverse('dashboard:offer-detail', kwargs={'pk': offer.pk}))

        # Ensure the offer is associated to the site set in the first step of the wizard
        self.assertEqual(offer.site, site)