Fix tests and simplify checkout data
This commit is contained in:
parent
b7ebd77afb
commit
f4def6d51b
3 changed files with 15 additions and 17 deletions
|
@ -28,9 +28,7 @@ class KPsulCheckoutFormTests(TestCase):
|
||||||
|
|
||||||
def test_checkout(self):
|
def test_checkout(self):
|
||||||
checkout_f = self.form.fields["checkout"]
|
checkout_f = self.form.fields["checkout"]
|
||||||
self.assertListEqual(
|
self.assertListEqual(list(checkout_f.choices), [(self.c1.pk, "C1")])
|
||||||
list(checkout_f.choices), [("", "---------"), (self.c1.pk, "C1")]
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch("django.utils.timezone.now")
|
@mock.patch("django.utils.timezone.now")
|
||||||
def test_checkout_valid(self, mock_now):
|
def test_checkout_valid(self, mock_now):
|
||||||
|
@ -44,4 +42,4 @@ class KPsulCheckoutFormTests(TestCase):
|
||||||
form = KPsulCheckoutForm()
|
form = KPsulCheckoutForm()
|
||||||
|
|
||||||
checkout_f = form.fields["checkout"]
|
checkout_f = form.fields["checkout"]
|
||||||
self.assertListEqual(list(checkout_f.choices), [("", "---------")])
|
self.assertListEqual(list(checkout_f.choices), [])
|
||||||
|
|
|
@ -1683,11 +1683,19 @@ class KPsulCheckoutDataViewTests(ViewTestCaseMixin, TestCase):
|
||||||
url_name = "kfet.kpsul.checkout_data"
|
url_name = "kfet.kpsul.checkout_data"
|
||||||
url_expected = "/k-fet/k-psul/checkout_data"
|
url_expected = "/k-fet/k-psul/checkout_data"
|
||||||
|
|
||||||
http_methods = ["POST"]
|
http_methods = ["GET"]
|
||||||
|
|
||||||
auth_user = "team"
|
auth_user = "team"
|
||||||
auth_forbidden = [None, "user"]
|
auth_forbidden = [None, "user"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def url_kwargs(self):
|
||||||
|
return {"pk": self.checkout.pk}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def url_expected(self):
|
||||||
|
return "/k-fet/k-psul/checkout_data/{}".format(self.checkout.pk)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.checkout = Checkout.objects.create(
|
self.checkout = Checkout.objects.create(
|
||||||
|
@ -1704,7 +1712,7 @@ class KPsulCheckoutDataViewTests(ViewTestCaseMixin, TestCase):
|
||||||
|
|
||||||
content = json.loads(r.content.decode("utf-8"))
|
content = json.loads(r.content.decode("utf-8"))
|
||||||
|
|
||||||
expected = {"name": "Checkout", "balance": "10.00"}
|
expected = {"balance": "10.00"}
|
||||||
|
|
||||||
self.assertDictContainsSubset(expected, content)
|
self.assertDictContainsSubset(expected, content)
|
||||||
|
|
||||||
|
@ -1714,14 +1722,7 @@ class KPsulCheckoutDataViewTests(ViewTestCaseMixin, TestCase):
|
||||||
[
|
[
|
||||||
"balance",
|
"balance",
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"last_statement",
|
||||||
"valid_from",
|
|
||||||
"valid_to",
|
|
||||||
"last_statement_at",
|
|
||||||
"last_statement_balance",
|
|
||||||
"last_statement_by_first_name",
|
|
||||||
"last_statement_by_last_name",
|
|
||||||
"last_statement_by_trigramme",
|
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -942,8 +942,6 @@ def kpsul_checkout_data(request, pk):
|
||||||
.values(
|
.values(
|
||||||
"id",
|
"id",
|
||||||
"balance",
|
"balance",
|
||||||
"valid_from",
|
|
||||||
"valid_to",
|
|
||||||
"last_statement_balance",
|
"last_statement_balance",
|
||||||
"last_statement_at",
|
"last_statement_at",
|
||||||
"last_statement_by",
|
"last_statement_by",
|
||||||
|
@ -955,9 +953,10 @@ def kpsul_checkout_data(request, pk):
|
||||||
|
|
||||||
prefix = "last_statement_"
|
prefix = "last_statement_"
|
||||||
ls_dict = {}
|
ls_dict = {}
|
||||||
for (key, value) in data.items():
|
for (key, value) in list(data.items()):
|
||||||
if key.startswith(prefix):
|
if key.startswith(prefix):
|
||||||
ls_dict[key[len(prefix) :]] = value
|
ls_dict[key[len(prefix) :]] = value
|
||||||
|
del data[key]
|
||||||
|
|
||||||
data["last_statement"] = ls_dict
|
data["last_statement"] = ls_dict
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
Loading…
Reference in a new issue