-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [#4320] Add unit tests for the cosign state
- Loading branch information
1 parent
6b62c56
commit efa8791
Showing
2 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
from django.test import TestCase | ||
|
||
from ..cosigning import CosignState | ||
from .factories import SubmissionFactory | ||
|
||
|
||
class CosignStateTests(TestCase): | ||
|
||
def test_string_representation(self): | ||
submission = SubmissionFactory.build(public_registration_reference="OF-123") | ||
cosign = CosignState(submission=submission) | ||
|
||
str_repr = str(cosign) | ||
|
||
self.assertEqual( | ||
str_repr, "<CosignState submission=<Submission reference=OF-123>>" | ||
) | ||
|
||
def test_cosign_required_state(self): | ||
submissions = ( | ||
( | ||
SubmissionFactory.create(cosigned=False), | ||
False, | ||
), | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": False}, | ||
} | ||
], | ||
cosigned=False, | ||
), | ||
False, | ||
), | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": True}, | ||
} | ||
], | ||
cosigned=True, | ||
), | ||
True, | ||
), | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": False}, | ||
} | ||
], | ||
submitted_data={"cosign": "[email protected]"}, | ||
cosigned=False, | ||
), | ||
True, | ||
), | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": False}, | ||
} | ||
], | ||
submitted_data={"cosign": "[email protected]"}, | ||
cosigned=True, | ||
), | ||
True, | ||
), | ||
) | ||
|
||
for index, (submission, expected) in enumerate(submissions): | ||
with self.subTest(f"submission at index {index}"): | ||
cosign = CosignState(submission=submission) | ||
|
||
self.assertEqual(cosign.is_required, expected) | ||
|
||
def test_is_waiting(self): | ||
submissions = ( | ||
# without cosign | ||
( | ||
SubmissionFactory.create(cosigned=False), | ||
False, | ||
), | ||
# not signed yet | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": True}, | ||
} | ||
], | ||
cosigned=False, | ||
), | ||
True, | ||
), | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": False}, | ||
} | ||
], | ||
submitted_data={"cosign": "[email protected]"}, | ||
cosigned=False, | ||
), | ||
True, | ||
), | ||
# signed | ||
( | ||
SubmissionFactory.from_components( | ||
[ | ||
{ | ||
"type": "cosign", | ||
"key": "cosign", | ||
"hidden": False, | ||
"validate": {"required": False}, | ||
} | ||
], | ||
submitted_data={"cosign": "[email protected]"}, | ||
cosigned=True, | ||
), | ||
False, | ||
), | ||
) | ||
|
||
for index, (submission, expected) in enumerate(submissions): | ||
with self.subTest(f"submission at index {index}"): | ||
cosign = CosignState(submission=submission) | ||
|
||
self.assertEqual(cosign.is_waiting, expected) |