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):
|
||||
checkout_f = self.form.fields["checkout"]
|
||||
self.assertListEqual(
|
||||
list(checkout_f.choices), [("", "---------"), (self.c1.pk, "C1")]
|
||||
)
|
||||
self.assertListEqual(list(checkout_f.choices), [(self.c1.pk, "C1")])
|
||||
|
||||
@mock.patch("django.utils.timezone.now")
|
||||
def test_checkout_valid(self, mock_now):
|
||||
|
@ -44,4 +42,4 @@ class KPsulCheckoutFormTests(TestCase):
|
|||
form = KPsulCheckoutForm()
|
||||
|
||||
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_expected = "/k-fet/k-psul/checkout_data"
|
||||
|
||||
http_methods = ["POST"]
|
||||
http_methods = ["GET"]
|
||||
|
||||
auth_user = "team"
|
||||
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):
|
||||
super().setUp()
|
||||
self.checkout = Checkout.objects.create(
|
||||
|
@ -1704,7 +1712,7 @@ class KPsulCheckoutDataViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
content = json.loads(r.content.decode("utf-8"))
|
||||
|
||||
expected = {"name": "Checkout", "balance": "10.00"}
|
||||
expected = {"balance": "10.00"}
|
||||
|
||||
self.assertDictContainsSubset(expected, content)
|
||||
|
||||
|
@ -1714,14 +1722,7 @@ class KPsulCheckoutDataViewTests(ViewTestCaseMixin, TestCase):
|
|||
[
|
||||
"balance",
|
||||
"id",
|
||||
"name",
|
||||
"valid_from",
|
||||
"valid_to",
|
||||
"last_statement_at",
|
||||
"last_statement_balance",
|
||||
"last_statement_by_first_name",
|
||||
"last_statement_by_last_name",
|
||||
"last_statement_by_trigramme",
|
||||
"last_statement",
|
||||
]
|
||||
),
|
||||
)
|
||||
|
|
|
@ -942,8 +942,6 @@ def kpsul_checkout_data(request, pk):
|
|||
.values(
|
||||
"id",
|
||||
"balance",
|
||||
"valid_from",
|
||||
"valid_to",
|
||||
"last_statement_balance",
|
||||
"last_statement_at",
|
||||
"last_statement_by",
|
||||
|
@ -955,9 +953,10 @@ def kpsul_checkout_data(request, pk):
|
|||
|
||||
prefix = "last_statement_"
|
||||
ls_dict = {}
|
||||
for (key, value) in data.items():
|
||||
for (key, value) in list(data.items()):
|
||||
if key.startswith(prefix):
|
||||
ls_dict[key[len(prefix) :]] = value
|
||||
del data[key]
|
||||
|
||||
data["last_statement"] = ls_dict
|
||||
return JsonResponse(data)
|
||||
|
|
Loading…
Reference in a new issue