Fix tests

This commit is contained in:
Ludovic Stephan 2020-09-16 19:19:29 +02:00
parent 8f9c94fe10
commit a14c9d9574
4 changed files with 55 additions and 40 deletions

View file

@ -47,10 +47,10 @@ class Scale(object):
if end is not None:
end = self.do_step(self.get_chunk_start(end))
if begin is not None and n_steps != 0:
if begin is not None and n_steps:
self.begin = begin
self.end = self.do_step(self.begin, n_steps=n_steps)
elif end is not None and n_steps != 0:
elif end is not None and n_steps:
self.end = end
self.begin = self.do_step(self.end, n_steps=-n_steps)
elif begin is not None and end is not None:

View file

@ -44,9 +44,9 @@ class TestStats(TestCase):
"/k-fet/accounts/FOO/stat/operations?{}".format(
"&".join(
[
"scale=day",
"types=['purchase']",
"scale_args={'n_steps':+7,+'last':+True}",
"scale-name=day",
"scale-n_steps=7",
"scale-last=True",
"format=json",
]
)
@ -64,7 +64,17 @@ class TestStats(TestCase):
# receives a Redirect response
articles_urls = [
"/k-fet/articles/{}/stat/sales/list".format(article.pk),
"/k-fet/articles/{}/stat/sales".format(article.pk),
"/k-fet/articles/{}/stat/sales?{}".format(
article.pk,
"&".join(
[
"scale-name=day",
"scale-n_steps=7",
"scale-last=True",
"format=json",
]
),
),
]
for url in articles_urls:
resp = client.get(url)

View file

@ -651,10 +651,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"types": ["['purchase']"],
"scale_name": ["month"],
"scale_last": ["True"],
"scale_begin": [
"scale-name": ["month"],
"scale-last": ["True"],
"scale-begin": [
self.accounts["user1"].created_at.isoformat(" ")
],
},
@ -665,10 +664,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"types": ["['purchase']"],
"scale_n_steps": ["12"],
"scale_name": ["month"],
"scale_last": ["True"],
"scale-n_steps": ["12"],
"scale-name": ["month"],
"scale-last": ["True"],
},
},
},
@ -677,10 +675,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"types": ["['purchase']"],
"scale_n_steps": ["13"],
"scale_name": ["week"],
"scale_last": ["True"],
"scale-n_steps": ["13"],
"scale-name": ["week"],
"scale-last": ["True"],
},
},
},
@ -689,10 +686,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"types": ["['purchase']"],
"scale_n_steps": ["14"],
"scale_name": ["day"],
"scale_last": ["True"],
"scale-n_steps": ["14"],
"scale-name": ["day"],
"scale-last": ["True"],
},
},
},
@ -739,7 +735,9 @@ class AccountStatOperationViewTests(ViewTestCaseMixin, TestCase):
return {"user1": create_user("user1", "001")}
def test_ok(self):
r = self.client.get(self.url)
r = self.client.get(
self.url, {"scale-name": "day", "scale-n_steps": 7, "scale-last": True}
)
self.assertEqual(r.status_code, 200)
@ -1593,9 +1591,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"scale_name": ["month"],
"scale_last": ["True"],
"scale_begin": [self.opegroup.at.isoformat(" ")],
"scale-name": ["month"],
"scale-last": ["True"],
"scale-begin": [self.opegroup.at.isoformat(" ")],
},
},
},
@ -1604,9 +1602,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"scale_n_steps": ["12"],
"scale_name": ["month"],
"scale_last": ["True"],
"scale-n_steps": ["12"],
"scale-name": ["month"],
"scale-last": ["True"],
},
},
},
@ -1615,9 +1613,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"scale_n_steps": ["13"],
"scale_name": ["week"],
"scale_last": ["True"],
"scale-n_steps": ["13"],
"scale-name": ["week"],
"scale-last": ["True"],
},
},
},
@ -1626,9 +1624,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": {
"path": base_url,
"query": {
"scale_n_steps": ["14"],
"scale_name": ["day"],
"scale_last": ["True"],
"scale-n_steps": ["14"],
"scale-name": ["day"],
"scale-last": ["True"],
},
},
},
@ -1661,7 +1659,9 @@ class ArticleStatSalesViewTests(ViewTestCaseMixin, TestCase):
)
def test_ok(self):
r = self.client.get(self.url)
r = self.client.get(
self.url, {"scale-name": "day", "scale-n_steps": 7, "scale-last": True}
)
self.assertEqual(r.status_code, 200)

View file

@ -2478,7 +2478,7 @@ class AccountStatOperationList(UserAccountMixin, SingleResumeStat):
("2 semaines", DayScale, {"last": True, "n_steps": 14}, False),
]
return scale_url_params(scales_def, types=[Operation.PURCHASE])
return scale_url_params(scales_def)
@method_decorator(login_required, name="dispatch")
@ -2542,7 +2542,12 @@ class ArticleStatSalesList(SingleResumeStat):
# On le crée dans le passé au cas où
first_conso = timezone.now() - timedelta(seconds=1)
scales_def = [
("Tout le temps", MonthScale, {"last": True, "begin": first_conso}, False),
(
"Tout le temps",
MonthScale,
{"last": True, "begin": first_conso.strftime("%Y-%m-%d %H:%M:%S")},
False,
),
("1 an", MonthScale, {"last": True, "n_steps": 12}, False),
("3 mois", WeekScale, {"last": True, "n_steps": 13}, True),
("2 semaines", DayScale, {"last": True, "n_steps": 14}, False),
@ -2572,8 +2577,8 @@ class ArticleStatSales(ScaleMixin, JSONDetailView):
.values("group__at", "article_nb")
.order_by("group__at")
)
cof_accts = all_purchases.filter(group__on_acc__profile__is_cof=True)
noncof_accts = all_purchases.exclude(group__on_acc__profile__is_cof=True)
cof_accts = all_purchases.filter(group__on_acc__cofprofile__is_cof=True)
noncof_accts = all_purchases.exclude(group__on_acc__cofprofile__is_cof=True)
nb_cof = scale.chunkify_qs(
cof_accts, field="group__at", aggregate=Sum("article_nb")