Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
acf63fd4
Commit
acf63fd4
authored
May 23, 2020
by
Florent Chehab
Committed by
Maxime Emschwiller
May 23, 2020
Browse files
test(backend): add tests to check functions of stats computing
parent
22a43b4c
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
acf63fd4
...
...
@@ -67,7 +67,7 @@ test_back:
-
make setup
script
:
-
cd backend
-
pytest base_app/ backend_app/ --cov --cov-config .coveragerc --cov-report term --cov-report html
-
pytest base_app/ backend_app/
stats_app/
--cov --cov-config .coveragerc --cov-report term --cov-report html
artifacts
:
paths
:
-
backend/htmlcov/
...
...
Makefile
View file @
acf63fd4
...
...
@@ -28,7 +28,7 @@ reformat_backend:
docker-compose
exec
backend sh
-c
"cd backend && black ."
test_backend
:
docker-compose
exec
backend sh
-c
"cd backend && pytest --cov --cov-config .coveragerc --cov-report term
base_app/ backend_app/"
docker-compose
exec
backend sh
-c
"cd backend && pytest --cov --cov-config .coveragerc --cov-report term base_app/ backend_app/
stats_app/
"
test_frontend
:
docker-compose
exec
frontend sh
-c
"cd frontend && yarn test"
...
...
backend/stats_app/tests/__init__.py
0 → 100644
View file @
acf63fd4
backend/stats_app/tests/test_nb_connections.py
0 → 100644
View file @
acf63fd4
from
datetime
import
timedelta
from
django.test
import
TestCase
from
base_app.models
import
User
from
stats_app.compute_stats
import
update_all_stats
from
stats_app.models
import
DailyConnections
from
stats_app.utils
import
get_daily_connections
,
get_today_as_datetime
class
StatsConnectionsTest
(
TestCase
):
def
test_get_daily_connections
(
self
):
today
=
get_today_as_datetime
()
yesterday
=
today
-
timedelta
(
days
=
1
)
for
i
in
range
(
10
):
User
.
objects
.
update_or_create
(
username
=
f
"
{
i
}
"
,
defaults
=
dict
(
last_login
=
yesterday
)
)
daily_connections
=
get_daily_connections
()
self
.
assertEqual
(
daily_connections
,
10
)
two_days_ago
=
today
-
timedelta
(
days
=
2
)
for
i
in
range
(
10
,
20
):
User
.
objects
.
update_or_create
(
username
=
f
"
{
i
}
"
,
defaults
=
dict
(
last_login
=
two_days_ago
)
)
daily_connections
=
get_daily_connections
()
self
.
assertEqual
(
daily_connections
,
10
)
def
test_update_all_stats
(
self
):
today
=
get_today_as_datetime
()
yesterday
=
today
-
timedelta
(
days
=
1
)
for
i
in
range
(
10
):
User
.
objects
.
update_or_create
(
username
=
f
"
{
i
}
"
,
defaults
=
dict
(
last_login
=
yesterday
)
)
update_all_stats
()
yesterday_daily_connections
=
DailyConnections
.
objects
.
get
(
date
=
yesterday
)
self
.
assertEqual
(
yesterday_daily_connections
.
nb_connections
,
10
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment