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
d9920f7a
Commit
d9920f7a
authored
Jun 07, 2020
by
Maxime Emschwiller
Browse files
test(backend): Add test to check functions of contributions stats computing
parent
1fc1f920
Changes
1
Show whitespace changes
Inline
Side-by-side
backend/stats_app/tests/test_nb_contributions.py
0 → 100644
View file @
d9920f7a
from
datetime
import
timedelta
from
django.test
import
TestCase
from
backend_app.models.exchangeFeedback
import
ExchangeFeedback
from
backend_app.models.exchange
import
Exchange
from
backend_app.tests.utils
import
get_dummy_university
from
stats_app.compute_stats
import
update_daily_exchange_contributions_info
from
stats_app.models
import
DailyExchangeContributionsInfo
from
stats_app.utils
import
get_today_as_datetime
,
get_contributions_profiles
class
StatsContributionsTest
(
TestCase
):
@
classmethod
def
setUpTestData
(
cls
):
today
=
get_today_as_datetime
()
yesterday
=
today
-
timedelta
(
days
=
1
)
cls
.
univ
=
get_dummy_university
()
utc_partner_id
=
cls
.
univ
.
corresponding_utc_partners
.
all
()[
0
].
utc_id
for
i
in
range
(
2
):
exchange
=
Exchange
.
objects
.
update_or_create
(
pk
=
i
,
defaults
=
dict
(
utc_id
=
i
,
utc_partner_id
=
utc_partner_id
,
year
=
2019
,
semester
=
"A"
,
student_major_and_semester
=
"IM4"
,
student_minor
=
"IDI"
,
duration
=
2
,
double_degree
=
False
,
master_obtained
=
False
,
utc_allow_courses
=
True
,
utc_allow_login
=
True
,
university
=
cls
.
univ
,
),
)[
0
]
ExchangeFeedback
.
objects
.
update_or_create
(
exchange
=
exchange
,
defaults
=
dict
(
updated_on
=
yesterday
,
untouched
=
False
,
university
=
cls
.
univ
),
)
def
test_get_contributions_profiles
(
self
):
daily_contributions_profiles
=
get_contributions_profiles
()
self
.
assertEqual
(
len
(
daily_contributions_profiles
),
2
)
for
p
in
daily_contributions_profiles
:
self
.
assertEqual
(
p
.
major
,
"IM"
)
self
.
assertEqual
(
p
.
minor
,
"IDI"
)
self
.
assertEqual
(
p
.
exchange_semester
,
"A2019"
)
self
.
assertEqual
(
p
.
university_pk
,
self
.
univ
.
pk
)
def
test_update_daily_exchange_contributions_info
(
self
):
today
=
get_today_as_datetime
()
yesterday
=
today
-
timedelta
(
days
=
1
)
update_daily_exchange_contributions_info
()
contributions
=
DailyExchangeContributionsInfo
.
objects
.
filter
(
date
=
yesterday
)
self
.
assertEqual
(
len
(
contributions
),
1
)
contribution
:
DailyExchangeContributionsInfo
=
contributions
[
0
]
self
.
assertEqual
(
contribution
.
university
.
pk
,
self
.
univ
.
pk
)
self
.
assertEqual
(
contribution
.
major
,
"IM"
)
self
.
assertEqual
(
contribution
.
minor
,
"IDI"
)
self
.
assertEqual
(
contribution
.
exchange_semester
,
"A2019"
)
self
.
assertEqual
(
contribution
.
nb_contributions
,
2
)
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