Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittests for models #1416

Merged
merged 2 commits into from
Jun 13, 2020
Merged

Add unittests for models #1416

merged 2 commits into from
Jun 13, 2020

Conversation

Ninjaclasher
Copy link
Member

No description provided.

@Ninjaclasher Ninjaclasher force-pushed the models-testing branch 3 times, most recently from 8d0dade to 32a36de Compare June 2, 2020 03:34
@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2020

Codecov Report

Merging #1416 into master will increase coverage by 7.69%.
The diff coverage is 99.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1416      +/-   ##
==========================================
+ Coverage   37.92%   45.62%   +7.69%     
==========================================
  Files         198      207       +9     
  Lines       11337    11872     +535     
==========================================
+ Hits         4300     5417    +1117     
+ Misses       7037     6455     -582     
Impacted Files Coverage Δ
judge/models/tests/util.py 97.50% <97.50%> (ø)
judge/models/tests/test_blogpost.py 100.00% <100.00%> (ø)
judge/models/tests/test_contest.py 100.00% <100.00%> (ø)
judge/models/tests/test_problem.py 100.00% <100.00%> (ø)
judge/models/tests/test_profile.py 100.00% <100.00%> (ø)
judge/models/tests/test_submission.py 100.00% <100.00%> (ø)
judge/admin/problem.py 57.23% <0.00%> (-2.21%) ⬇️
judge/models/comment.py 38.81% <0.00%> (-0.79%) ⬇️
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6e7a38...185eed7. Read the comment docs.

@Ninjaclasher Ninjaclasher force-pushed the models-testing branch 7 times, most recently from fc08a80 to f82908b Compare June 2, 2020 17:25
@Ninjaclasher
Copy link
Member Author

Ninjaclasher commented Jun 2, 2020

Todo:

  • Add tests for Comment
  • Add fixture (?) for users, profiles, permissions, organizations
  • Fix wrong Problem.is_accessible_by method
  • Reduce the amount of copy pasting for Contest, Problem, and BlogPost method testing

@Ninjaclasher
Copy link
Member Author

This PR covers unittests for most of the models.

Models excluded:

  • Comments (this will be done in a future PR)
  • Problem Data (this should probably just be done alongside unittests for the views)
  • Judge/Runtime (this requires a running bridge/judges for thorough testing)

judge/models/tests/test_submission.py Outdated Show resolved Hide resolved
judge/models/tests/util.py Outdated Show resolved Hide resolved
@Ninjaclasher Ninjaclasher force-pushed the models-testing branch 2 times, most recently from ffc9bb8 to c20ec28 Compare June 3, 2020 18:21
judge/models/tests/util.py Outdated Show resolved Hide resolved
judge/models/tests/util.py Outdated Show resolved Hide resolved
Copy link
Contributor

@fluix-dev fluix-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks great!

judge/models/tests/test_contest.py Outdated Show resolved Hide resolved
judge/models/tests/test_contest.py Outdated Show resolved Hide resolved
judge/models/tests/test_profile.py Show resolved Hide resolved
judge/models/tests/test_contest.py Show resolved Hide resolved
judge/models/tests/test_contest.py Show resolved Hide resolved
judge/models/tests/test_problem.py Show resolved Hide resolved
judge/models/tests/test_profile.py Show resolved Hide resolved
judge/models/tests/test_contest.py Show resolved Hide resolved

def test_basic_contest(self):
self.assertTrue(self.basic_contest.show_scoreboard)
self.assertIsInstance(self.basic_contest.contest_window_length, timezone.timedelta)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not assert the actual values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for this (since the timedelta is fixed). However, I don't think we should assert the actual values for the ones that are dependant on the current time (e.g time_remaining).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you not get an accurate calculation by using the Contest's _now cached property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't think it is worth it to check for the exact match in these cases. If you're using the Contest's _now property, you basically end up rewriting that method's calculation as a test, which doesn't really test what the method "should" return.

judge/models/tests/test_contest.py Outdated Show resolved Hide resolved
Copy link
Contributor

@fluix-dev fluix-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@quantum5 quantum5 merged commit 3126dca into DMOJ:master Jun 13, 2020
@Ninjaclasher Ninjaclasher deleted the models-testing branch June 28, 2020 23:24
outloudvi pushed a commit to SchOJ/site that referenced this pull request Oct 27, 2020
malbareda pushed a commit to malbareda/JOEL-web that referenced this pull request Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants