|
4 | 4 | from microsetta_private_api.exceptions import RepoException
|
5 | 5 | from microsetta_private_api.repo.transaction import Transaction
|
6 | 6 | from microsetta_private_api.repo.account_repo import AccountRepo
|
| 7 | +from microsetta_private_api.model.account import Account |
7 | 8 |
|
8 | 9 |
|
9 | 10 | ACCOUNT_ID = '607f6723-c704-4b52-bc26-556a9aec85f6'
|
10 | 11 | BAD_ACCOUNT_ID = 'badbadba-dbad-badb-adba-dbadbadbadba'
|
11 | 12 |
|
| 13 | +AUTH_ACCT_ID = '0004f77e-d3fd-404a-8f5c-3d548a5b0a3f' |
12 | 14 | ACCT_ID_1 = '7a98df6a-e4db-40f4-91ec-627ac315d881'
|
13 | 15 | DUMMY_ACCT_INFO_1 = {
|
14 | 16 | "address": {
|
|
25 | 27 | "language": "en_US",
|
26 | 28 | "kit_name": 'jb_qhxqe',
|
27 | 29 | "consent_privacy_terms": True,
|
| 30 | + "latitude": 32.8798916, |
| 31 | + "longitude": -117.2363115, |
| 32 | + "cannot_geocode": False, |
28 | 33 | "id": ACCT_ID_1
|
29 | 34 | }
|
30 | 35 | ACCT_MOCK_ISS_1 = "MrUnitTest.go"
|
31 | 36 | ACCT_MOCK_SUB_1 = "NotARealSub"
|
32 |
| -RESULT_LAT = 32.882274018668355 |
33 |
| -RESULT_LONG = -117.2353976693118 |
34 | 37 |
|
35 | 38 |
|
36 | 39 | class AccountTests(unittest.TestCase):
|
37 | 40 | def setUp(self):
|
38 | 41 | with Transaction() as t:
|
39 | 42 | ar = AccountRepo(t)
|
40 | 43 | self.untouched = ar.get_account(ACCOUNT_ID)
|
| 44 | + self.untouched_auth = ar.get_account(AUTH_ACCT_ID) |
41 | 45 |
|
42 | 46 | def test_scrub(self):
|
43 | 47 | with Transaction() as t:
|
@@ -86,6 +90,71 @@ def test_scrub_no_account(self):
|
86 | 90 | with self.assertRaises(RepoException):
|
87 | 91 | ar.scrub(BAD_ACCOUNT_ID)
|
88 | 92 |
|
| 93 | + def test_faulty_auth_status_insert(self): |
| 94 | + # none of the tests commit |
| 95 | + # success: both non-null |
| 96 | + with Transaction() as t: |
| 97 | + ar = AccountRepo(t) |
| 98 | + acct_1 = Account.from_dict( |
| 99 | + DUMMY_ACCT_INFO_1, |
| 100 | + ACCT_MOCK_ISS_1, |
| 101 | + ACCT_MOCK_SUB_1 |
| 102 | + ) |
| 103 | + self.assertTrue(ar.create_account(acct_1)) |
| 104 | + |
| 105 | + # success: both null |
| 106 | + with Transaction() as t: |
| 107 | + ar = AccountRepo(t) |
| 108 | + acct_2 = Account.from_dict(DUMMY_ACCT_INFO_1, None, None) |
| 109 | + self.assertTrue(ar.create_account(acct_2)) |
| 110 | + |
| 111 | + # fail: sub null |
| 112 | + with Transaction() as t: |
| 113 | + ar = AccountRepo(t) |
| 114 | + acct_3 = Account.from_dict( |
| 115 | + DUMMY_ACCT_INFO_1, |
| 116 | + ACCT_MOCK_ISS_1, |
| 117 | + None |
| 118 | + ) |
| 119 | + with self.assertRaises(RepoException): |
| 120 | + ar.create_account(acct_3) |
| 121 | + |
| 122 | + # fail: iss null |
| 123 | + with Transaction() as t: |
| 124 | + ar = AccountRepo(t) |
| 125 | + acct_4 = Account.from_dict( |
| 126 | + DUMMY_ACCT_INFO_1, |
| 127 | + None, |
| 128 | + ACCT_MOCK_SUB_1 |
| 129 | + ) |
| 130 | + with self.assertRaises(RepoException): |
| 131 | + ar.create_account(acct_4) |
| 132 | + |
| 133 | + def test_faulty_auth_status_update(self): |
| 134 | + # none of the tests commit |
| 135 | + # success: both non-null |
| 136 | + with Transaction() as t: |
| 137 | + ar = AccountRepo(t) |
| 138 | + self.untouched_auth.auth_issuer = ACCT_MOCK_ISS_1 |
| 139 | + self.untouched_auth.auth_sub = ACCT_MOCK_SUB_1 |
| 140 | + self.assertTrue(ar.update_account(self.untouched_auth)) |
| 141 | + |
| 142 | + # fail: sub null |
| 143 | + with Transaction() as t: |
| 144 | + ar = AccountRepo(t) |
| 145 | + self.untouched_auth.auth_issuer = ACCT_MOCK_ISS_1 |
| 146 | + self.untouched_auth.auth_sub = None |
| 147 | + with self.assertRaises(RepoException): |
| 148 | + ar.update_account(self.untouched_auth) |
| 149 | + |
| 150 | + # fail: iss null |
| 151 | + with Transaction() as t: |
| 152 | + ar = AccountRepo(t) |
| 153 | + self.untouched_auth.auth_issuer = None |
| 154 | + self.untouched_auth.auth_sub = ACCT_MOCK_SUB_1 |
| 155 | + with self.assertRaises(RepoException): |
| 156 | + ar.update_account(self.untouched_auth) |
| 157 | + |
89 | 158 |
|
90 | 159 | if __name__ == '__main__':
|
91 | 160 | unittest.main()
|
0 commit comments