wagtail-longclaw/longclaw/tests/utils.py

153 wiersze
5.2 KiB
Python
Czysty Zwykły widok Historia

Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
from unittest import mock
from contextlib import contextmanager
2017-03-29 16:28:43 +00:00
import factory
from django.urls import reverse_lazy
2017-03-29 16:28:43 +00:00
from rest_framework.test import APITestCase
from rest_framework import status
from wagtail_factories import PageFactory
from longclaw.basket.models import BasketItem
from longclaw.orders.models import Order
from longclaw.shipping.models import Address, Country, ShippingRate
from longclaw.utils import ProductVariant, maybe_get_product_model
2017-03-29 16:28:43 +00:00
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
@contextmanager
def catch_signal(signal):
"""
Catch django signal and return the mocked call.
https://medium.freecodecamp.org/how-to-testing-django-signals-like-a-pro-c7ed74279311
"""
handler = mock.Mock()
signal.connect(handler)
yield handler
signal.disconnect(handler)
class OrderFactory(factory.django.DjangoModelFactory):
class Meta:
model = Order
class CountryFactory(factory.django.DjangoModelFactory):
class Meta:
model = Country
iso = factory.Faker('pystr', max_chars=2, min_chars=2)
name_official = factory.Faker('text', max_nb_chars=128)
name = factory.Faker('text', max_nb_chars=128)
class AddressFactory(factory.django.DjangoModelFactory):
class Meta:
model = Address
name = factory.Faker('text', max_nb_chars=64)
line_1 = factory.Faker('text', max_nb_chars=128)
line_2 = factory.Faker('text', max_nb_chars=128)
city = factory.Faker('text', max_nb_chars=64)
postcode = factory.Faker('text', max_nb_chars=10)
country = factory.SubFactory(CountryFactory)
class ShippingRateFactory(factory.django.DjangoModelFactory):
class Meta:
model = ShippingRate
name = factory.Faker('text', max_nb_chars=32)
rate = 1.0
carrier = 'Royal Mail'
description = 'Test'
@factory.post_generation
def countries(self, create, extracted, **kwargs):
if not create:
# Simple build, do nothing.
return
if extracted:
# A list of countries were passed in, use them
for country in extracted:
self.countries.add(country)
2017-03-29 16:28:43 +00:00
class ProductFactory(PageFactory):
2017-10-01 10:19:37 +00:00
""" Create a random Product
"""
2017-03-29 16:28:43 +00:00
class Meta:
model = maybe_get_product_model()
2017-03-29 16:28:43 +00:00
title = factory.Faker('sentence', nb_words=1)
description = factory.Faker('text')
class ProductVariantFactory(factory.django.DjangoModelFactory):
class Meta:
model = ProductVariant
product = factory.SubFactory(ProductFactory)
2017-04-02 09:14:20 +00:00
description = factory.Faker('text')
2017-09-17 15:36:04 +00:00
base_price = factory.Faker('pyfloat', positive=True, left_digits=2, right_digits=2)
2017-03-29 16:28:43 +00:00
ref = factory.Faker('pystr', min_chars=3, max_chars=10)
stock = factory.Faker('pyint')
class BasketItemFactory(factory.django.DjangoModelFactory):
class Meta:
model = BasketItem
quantity = 1
variant = factory.SubFactory(ProductVariantFactory)
class LongclawTestCase(APITestCase):
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
def get_test(self, urlname, urlkwargs=None, params=None, success_expected=True, **kwargs):
2017-10-01 10:19:37 +00:00
""" Submit a GET request and assert the response status code is 200
2017-03-29 16:28:43 +00:00
Arguments:
2018-03-23 20:50:38 +00:00
urlname (str): The url name to pass to the 'reverse_lazy' function
urlkwargs (dict): The `kwargs` parameter to pass to the `reverse_lazy` function
2017-10-01 10:19:37 +00:00
"""
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
params = params or {}
response = self.client.get(reverse_lazy(urlname, kwargs=urlkwargs), params, **kwargs)
if success_expected:
self.assertTrue(status.is_success(response.status_code), response.content)
2017-03-29 16:28:43 +00:00
return response
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
def post_test(self, data, urlname, urlkwargs=None, success_expected=True, **kwargs):
2017-10-01 10:19:37 +00:00
""" Submit a POST request and assert the response status code is 201
2017-03-29 16:28:43 +00:00
Arguments:
data (dict): The data to pass to the post request
2018-03-23 20:50:38 +00:00
urlname (str): The url name to pass to the 'reverse_lazy' function
urlkwargs (dict): The `kwargs` parameter to pass to the `reverse_lazy` function
2017-10-01 10:19:37 +00:00
"""
2018-03-23 20:50:38 +00:00
response = self.client.post(reverse_lazy(urlname, kwargs=urlkwargs), data, **kwargs)
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
if success_expected:
self.assertTrue(status.is_success(response.status_code), response.content)
2017-03-29 16:28:43 +00:00
return response
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
def patch_test(self, data, urlname, urlkwargs=None, success_expected=True, **kwargs):
2017-10-01 10:19:37 +00:00
""" Submit a PATCH request and assert the response status code is 200
"""
2018-03-23 20:50:38 +00:00
response = self.client.patch(reverse_lazy(urlname, kwargs=urlkwargs), data, **kwargs)
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
if success_expected:
self.assertTrue(status.is_success(response.status_code), response.content)
2017-03-29 16:28:43 +00:00
return response
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
def put_test(self, data, urlname, urlkwargs=None, success_expected=True, **kwargs):
2018-03-23 20:50:38 +00:00
response = self.client.put(reverse_lazy(urlname, kwargs=urlkwargs), data, **kwargs)
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
if success_expected:
self.assertTrue(status.is_success(response.status_code), response.content)
2017-04-02 09:14:20 +00:00
return response
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
def del_test(self, urlname, urlkwargs=None, success_expected=True, **kwargs):
2018-03-23 20:50:38 +00:00
response = self.client.delete(reverse_lazy(urlname, kwargs=urlkwargs), **kwargs)
Issue 219 calculated rates base class (#230) * add test for get_shipping_cost with a basket rate * add fields to allow us to tie shipping rate to a basket & address * add test for testing specified address and basket * add migration for new shipping rate fields * add missing import * fix name errors * add shipping possibilities based on shipping address and basket id * test basket, shipping address, & basket+shipping address rate assignment * return correct rates for basket and address rate cases * rename shipping rate address for clarity (origin/destination) * send basket modified signal when basket is modified via api endpoints * test address only rate * remove basket rates when the basket_modified signal is sent * show response content on error * print response content on failure for more tests and include more 200 statuses for put * getting different status codes back from our endpoints, check success * clear shipping rates based on destination address when address modified * allow get params * return cost and rate options for more cases (test not complete) * fix mock * return applicable shipping options and test some combinations * stub the rate processor interface * add fk from rate to processor that created it * set rate basket and destination * shipping processor instance can apply to more than one country * run processor get_rates if configured * let child models handle assignment * add some initial testing for processor * rename _get_rates() to process_rates() * allow disabling the success check * test country shipping option with processor requires destination * test that the endpoint calls get_rate on the processor * test that multiple processors are called once * add shipping_origin fk to site settings * add default cache key based on origin, destination, & basket items * test a trivial rate processor implementation is used * test cost endpoint returns the processed rate * pin version requirement * fix wagtail version * start vagrant config * get tox to run * install nvm for vagrant user * add instructions to move npm deps off shared folder for speed * compact into a shell script for ease of use * add some more examples as temporary documentation * tests require dev reqs * clean this up a little * add migrations for productrequest app to fix test runner * raise exception on error instead of returning error response * test exception raised when country and country code specified * test for destination address does not exist * test exception when country and country code are not supplied * set request.site as it is expected * test get_shipping_cost_kwargs with only country code * check the basket id and the settings * value passed for country is supposed to be PK * test with country specified * write test so we can test with iso as string of known value * tes destination is respected * test with destination and country code * test shipping_rate_name is set as name * move models * rename models.py * rename to be consistent with rates being plural * move serializers * move models * ignore private vagrant subdir * move code around to fix circular imports to allow top level imports * move address serializer import to top level * ws * ws
2019-11-06 12:46:07 +00:00
if success_expected:
self.assertTrue(status.is_success(response.status_code), response.content)
return response