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: if end is not None:
end = self.do_step(self.get_chunk_start(end)) 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.begin = begin
self.end = self.do_step(self.begin, n_steps=n_steps) 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.end = end
self.begin = self.do_step(self.end, n_steps=-n_steps) self.begin = self.do_step(self.end, n_steps=-n_steps)
elif begin is not None and end is not None: 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( "/k-fet/accounts/FOO/stat/operations?{}".format(
"&".join( "&".join(
[ [
"scale=day", "scale-name=day",
"types=['purchase']", "scale-n_steps=7",
"scale_args={'n_steps':+7,+'last':+True}", "scale-last=True",
"format=json", "format=json",
] ]
) )
@ -64,7 +64,17 @@ class TestStats(TestCase):
# receives a Redirect response # receives a Redirect response
articles_urls = [ articles_urls = [
"/k-fet/articles/{}/stat/sales/list".format(article.pk), "/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: for url in articles_urls:
resp = client.get(url) resp = client.get(url)

View file

@ -651,10 +651,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"types": ["['purchase']"], "scale-name": ["month"],
"scale_name": ["month"], "scale-last": ["True"],
"scale_last": ["True"], "scale-begin": [
"scale_begin": [
self.accounts["user1"].created_at.isoformat(" ") self.accounts["user1"].created_at.isoformat(" ")
], ],
}, },
@ -665,10 +664,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"types": ["['purchase']"], "scale-n_steps": ["12"],
"scale_n_steps": ["12"], "scale-name": ["month"],
"scale_name": ["month"], "scale-last": ["True"],
"scale_last": ["True"],
}, },
}, },
}, },
@ -677,10 +675,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"types": ["['purchase']"], "scale-n_steps": ["13"],
"scale_n_steps": ["13"], "scale-name": ["week"],
"scale_name": ["week"], "scale-last": ["True"],
"scale_last": ["True"],
}, },
}, },
}, },
@ -689,10 +686,9 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"types": ["['purchase']"], "scale-n_steps": ["14"],
"scale_n_steps": ["14"], "scale-name": ["day"],
"scale_name": ["day"], "scale-last": ["True"],
"scale_last": ["True"],
}, },
}, },
}, },
@ -739,7 +735,9 @@ class AccountStatOperationViewTests(ViewTestCaseMixin, TestCase):
return {"user1": create_user("user1", "001")} return {"user1": create_user("user1", "001")}
def test_ok(self): 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) self.assertEqual(r.status_code, 200)
@ -1593,9 +1591,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"scale_name": ["month"], "scale-name": ["month"],
"scale_last": ["True"], "scale-last": ["True"],
"scale_begin": [self.opegroup.at.isoformat(" ")], "scale-begin": [self.opegroup.at.isoformat(" ")],
}, },
}, },
}, },
@ -1604,9 +1602,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"scale_n_steps": ["12"], "scale-n_steps": ["12"],
"scale_name": ["month"], "scale-name": ["month"],
"scale_last": ["True"], "scale-last": ["True"],
}, },
}, },
}, },
@ -1615,9 +1613,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"scale_n_steps": ["13"], "scale-n_steps": ["13"],
"scale_name": ["week"], "scale-name": ["week"],
"scale_last": ["True"], "scale-last": ["True"],
}, },
}, },
}, },
@ -1626,9 +1624,9 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
"url": { "url": {
"path": base_url, "path": base_url,
"query": { "query": {
"scale_n_steps": ["14"], "scale-n_steps": ["14"],
"scale_name": ["day"], "scale-name": ["day"],
"scale_last": ["True"], "scale-last": ["True"],
}, },
}, },
}, },
@ -1661,7 +1659,9 @@ class ArticleStatSalesViewTests(ViewTestCaseMixin, TestCase):
) )
def test_ok(self): 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) 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), ("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") @method_decorator(login_required, name="dispatch")
@ -2542,7 +2542,12 @@ class ArticleStatSalesList(SingleResumeStat):
# On le crée dans le passé au cas où # On le crée dans le passé au cas où
first_conso = timezone.now() - timedelta(seconds=1) first_conso = timezone.now() - timedelta(seconds=1)
scales_def = [ 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), ("1 an", MonthScale, {"last": True, "n_steps": 12}, False),
("3 mois", WeekScale, {"last": True, "n_steps": 13}, True), ("3 mois", WeekScale, {"last": True, "n_steps": 13}, True),
("2 semaines", DayScale, {"last": True, "n_steps": 14}, False), ("2 semaines", DayScale, {"last": True, "n_steps": 14}, False),
@ -2572,8 +2577,8 @@ class ArticleStatSales(ScaleMixin, JSONDetailView):
.values("group__at", "article_nb") .values("group__at", "article_nb")
.order_by("group__at") .order_by("group__at")
) )
cof_accts = all_purchases.filter(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__profile__is_cof=True) noncof_accts = all_purchases.exclude(group__on_acc__cofprofile__is_cof=True)
nb_cof = scale.chunkify_qs( nb_cof = scale.chunkify_qs(
cof_accts, field="group__at", aggregate=Sum("article_nb") cof_accts, field="group__at", aggregate=Sum("article_nb")