|
1 | 1 | import unittest |
| 2 | +from datetime import datetime |
2 | 3 |
|
3 | 4 | from electionguard.election import ( |
4 | 5 | ContestDescriptionWithPlaceholders, |
|
9 | 10 | ) |
10 | 11 | import electionguardtest.election_factory as ElectionFactory |
11 | 12 | import electionguardtest.ballot_factory as BallotFactory |
| 13 | +from electionguard.serializable import read_json |
12 | 14 |
|
13 | 15 | election_factory = ElectionFactory.ElectionFactory() |
14 | 16 | ballot_factory = BallotFactory.BallotFactory() |
@@ -46,6 +48,25 @@ def test_election_has_deterministic_hash(self): |
46 | 48 | # Assert |
47 | 49 | self.assertEqual(subject1.crypto_hash(), subject2.crypto_hash()) |
48 | 50 |
|
| 51 | + def test_election_hash_is_consistent_regardless_of_format(self): |
| 52 | + |
| 53 | + # Act |
| 54 | + subject1 = election_factory.get_simple_election_from_file() |
| 55 | + subject1.start_date = read_json('"2020-03-01T08:00:00-05:00"', datetime) |
| 56 | + |
| 57 | + subject2 = election_factory.get_simple_election_from_file() |
| 58 | + subject2.start_date = read_json('"2020-03-01T13:00:00-00:00"', datetime) |
| 59 | + |
| 60 | + subject3 = election_factory.get_simple_election_from_file() |
| 61 | + subject3.start_date = read_json('"2020-03-01T13:00:00.000-00:00"', datetime) |
| 62 | + |
| 63 | + subjects = [subject1, subject2, subject3] |
| 64 | + |
| 65 | + # Assert |
| 66 | + hashes = [subject.crypto_hash() for subject in subjects] |
| 67 | + for other_hash in hashes[1:]: |
| 68 | + self.assertEqual(hashes[0], other_hash) |
| 69 | + |
49 | 70 | def test_election_from_file_generates_consistent_internal_description_contest_hashes( |
50 | 71 | self, |
51 | 72 | ): |
|
0 commit comments