Mercurial > kallithea
annotate kallithea/tests/models/test_changeset_status.py @ 5912:7483b3f3bea5
pytest migration: models: switch to standard assert statements
Use unittest2pytest to replace unittest-style assert statements (e.g.
assertEqual) with standard Python assert statements to benefit from pytest's
improved reporting on assert failures.
The conversion by unittest2pytest was correct except for:
- 'import pytest' is not automatically added when needed
- line wrapping in string formatting caused a syntax error in the
transformed code. Reported upstream at
https://github.com/pytest-dev/unittest2pytest/issues/3 .
- in assertRaises with a lambda, the lambda needs to be removed
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Mon, 09 May 2016 17:44:34 +0200 |
parents | be1d20bfd2dd |
children | 7f2aa3ec2931 |
rev | line source |
---|---|
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
1 from kallithea.tests import * |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
2 from kallithea.model.changeset_status import ChangesetStatusModel |
5067
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
3 from kallithea.model.db import ChangesetStatus as CS |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
4 |
5067
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
5 class CSM(object): # ChangesetStatusMock |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
6 |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
7 def __init__(self, status): |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
8 self.status = status |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
9 |
5805
be1d20bfd2dd
pytest migration: model: convert all tests to TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5067
diff
changeset
|
10 class TestChangesetStatusCalculation(TestControllerPytest): |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
11 |
5805
be1d20bfd2dd
pytest migration: model: convert all tests to TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5067
diff
changeset
|
12 def setup_method(self, method): |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
13 self.m = ChangesetStatusModel() |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
14 |
5805
be1d20bfd2dd
pytest migration: model: convert all tests to TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5067
diff
changeset
|
15 @parametrize('name,expected_result,statuses', [ |
5067
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
16 ('empty list', CS.STATUS_UNDER_REVIEW, []), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
17 ('approve', CS.STATUS_APPROVED, [CSM(CS.STATUS_APPROVED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
18 ('approve2', CS.STATUS_APPROVED, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_APPROVED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
19 ('approve_reject', CS.STATUS_REJECTED, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_REJECTED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
20 ('approve_underreview', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_UNDER_REVIEW)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
21 ('approve_notreviewed', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_NOT_REVIEWED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
22 ('underreview', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_UNDER_REVIEW), CSM(CS.STATUS_UNDER_REVIEW)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
23 ('reject', CS.STATUS_REJECTED, [CSM(CS.STATUS_REJECTED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
24 ('reject_underreview', CS.STATUS_REJECTED, [CSM(CS.STATUS_REJECTED), CSM(CS.STATUS_UNDER_REVIEW)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
25 ('reject_notreviewed', CS.STATUS_REJECTED, [CSM(CS.STATUS_REJECTED), CSM(CS.STATUS_NOT_REVIEWED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
26 ('notreviewed', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_NOT_REVIEWED)]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
27 ('approve_none', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
28 ('approve2_none', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_APPROVED), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
29 ('approve_reject_none', CS.STATUS_REJECTED, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_REJECTED), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
30 ('approve_underreview_none', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_UNDER_REVIEW), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
31 ('approve_notreviewed_none', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_NOT_REVIEWED), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
32 ('underreview_none', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_UNDER_REVIEW), CSM(CS.STATUS_UNDER_REVIEW), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
33 ('reject_none', CS.STATUS_REJECTED, [CSM(CS.STATUS_REJECTED), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
34 ('reject_underreview_none', CS.STATUS_REJECTED, [CSM(CS.STATUS_REJECTED), CSM(CS.STATUS_UNDER_REVIEW), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
35 ('reject_notreviewed_none', CS.STATUS_REJECTED, [CSM(CS.STATUS_REJECTED), CSM(CS.STATUS_NOT_REVIEWED), None]), |
481a484b1d69
tests: simplify changeset_status unit tests
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5047
diff
changeset
|
36 ('notreviewed_none', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_NOT_REVIEWED), None]), |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
37 ]) |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
38 def test_result(self, name, expected_result, statuses): |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
diff
changeset
|
39 result = self.m._calculate_status(statuses) |
5912
7483b3f3bea5
pytest migration: models: switch to standard assert statements
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5805
diff
changeset
|
40 assert result == expected_result |