|
7 | 7 | from uid2_client.identity_tokens import IdentityTokens |
8 | 8 | from urllib.request import HTTPError |
9 | 9 |
|
10 | | -class PublisherIntegrationTests(unittest.TestCase): |
| 10 | + |
| 11 | +class PublisherEuidIntegrationTests(unittest.TestCase): |
| 12 | + |
| 13 | + EUID_SECRET_KEY = None |
| 14 | + EUID_API_KEY = None |
| 15 | + EUID_BASE_URL = None |
| 16 | + |
| 17 | + publisher_client = None |
| 18 | + |
| 19 | + @classmethod |
| 20 | + def setUpClass(cls): |
| 21 | + cls.EUID_BASE_URL = os.getenv("EUID_BASE_URL", "http://localhost:8888") |
| 22 | + cls.EUID_API_KEY = os.getenv("EUID_API_KEY", "LOCALfCXrMMfsR3mDqAXELtWWMS+xG1s7RdgRTMqdOH2qaAo=") |
| 23 | + cls.EUID_SECRET_KEY = os.getenv("EUID_SECRET_KEY", "DzBzbjTJcYL0swDtFs2krRNu+g1Eokm2tBU4dEuD0Wk=") |
| 24 | + |
| 25 | + print(cls.EUID_BASE_URL, cls.EUID_API_KEY, cls.EUID_SECRET_KEY) |
| 26 | + |
| 27 | + if cls.EUID_BASE_URL and cls.EUID_API_KEY and cls.EUID_SECRET_KEY: |
| 28 | + cls.publisher_client = Uid2PublisherClient(cls.EUID_BASE_URL, cls.EUID_API_KEY, cls.EUID_SECRET_KEY) |
| 29 | + |
| 30 | + def test_integration_tc_string(self): |
| 31 | + tc_string = "CPhJRpMPhJRpMABAMBFRACBoALAAAEJAAIYgAKwAQAKgArABAAqAAA" |
| 32 | + |
| 33 | + token_generate_response = self.publisher_client.generate_token( |
| 34 | + TokenGenerateInput. from_email( "[email protected]"). with_transparency_and_consent_string( tc_string)) |
| 35 | + self.assertFalse(token_generate_response.is_optout()) |
| 36 | + |
| 37 | + identity = token_generate_response.get_identity() |
| 38 | + self.assertIsNotNone(identity) |
| 39 | + self.assertFalse(identity.is_due_for_refresh()) |
| 40 | + self.assertIsNotNone(identity.get_advertising_token()) |
| 41 | + self.assertIsNotNone(identity.get_refresh_token()) |
| 42 | + self.assertIsNotNone(identity.get_json_string()) |
| 43 | + self.assertTrue(identity.is_refreshable()) |
| 44 | + |
| 45 | + def test_integration_tc_string_with_insufficient_consent(self): |
| 46 | + tc_string = "CPehXK9PehXK9ABAMBFRACBoADAAAEJAAIYgAKwAQAKgArABAAqAAA" |
| 47 | + with self.assertRaises(ValueError): |
| 48 | + self. publisher_client. generate_token( TokenGenerateInput. from_email( "[email protected]"). with_transparency_and_consent_string( tc_string)) |
| 49 | + |
| 50 | + |
| 51 | + def test_integration_optout_generate_token(self): |
| 52 | + publisher_client = Uid2PublisherClient(self.EUID_BASE_URL, self.EUID_API_KEY, self.EUID_SECRET_KEY) |
| 53 | + tc_string = "CPhJRpMPhJRpMABAMBFRACBoALAAAEJAAIYgAKwAQAKgArABAAqAAA" |
| 54 | + input = TokenGenerateInput. from_email( "[email protected]"). do_not_generate_tokens_for_opted_out(). with_transparency_and_consent_string( tc_string) |
| 55 | + print(input.get_as_json_string()) |
| 56 | + token_generate_response = publisher_client.generate_token(input) |
| 57 | + print(token_generate_response.get_identity_json_string()) |
| 58 | + self.assertTrue(token_generate_response.is_optout()) |
| 59 | + self.assertFalse(token_generate_response.is_success()) |
| 60 | + self.assertIsNone(token_generate_response.get_identity()) |
| 61 | + |
| 62 | +class PublisherUid2IntegrationTests(unittest.TestCase): |
11 | 63 |
|
12 | 64 | UID2_SECRET_KEY = None |
13 | 65 | UID2_API_KEY = None |
14 | 66 | UID2_BASE_URL = None |
| 67 | + |
15 | 68 | publisher_client = None |
16 | 69 |
|
17 | 70 | @classmethod |
18 | 71 | def setUpClass(cls): |
19 | | - cls.UID2_BASE_URL = os.getenv("UID2_BASE_URL", "http://localhost:8080") |
20 | | - cls.UID2_API_KEY = os.getenv("UID2_API_KEY", "trusted-partner-key") |
21 | | - cls.UID2_SECRET_KEY = os.getenv("UID2_SECRET_KEY", "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=") |
| 72 | + cls.UID2_BASE_URL = os.getenv("UID2_BASE_URL", "http://localhost:8888") |
| 73 | + cls.UID2_API_KEY = os.getenv("UID2_API_KEY", "LOCALfCXrMMfsR3mDqAXELtWWMS+xG1s7RdgRTMqdOH2qaAo=") |
| 74 | + cls.UID2_SECRET_KEY = os.getenv("UID2_SECRET_KEY", "DzBzbjTJcYL0swDtFs2krRNu+g1Eokm2tBU4dEuD0Wk=") |
22 | 75 |
|
23 | 76 | print(cls.UID2_BASE_URL, cls.UID2_API_KEY, cls.UID2_SECRET_KEY) |
24 | 77 |
|
@@ -136,50 +189,6 @@ def test_integration_bad_requests(self): |
136 | 189 | with self.assertRaises(HTTPError): |
137 | 190 | bad_secret_client. generate_token( TokenGenerateInput. from_email( "[email protected]")) |
138 | 191 |
|
139 | | - def test_integration_tc_string(self): |
140 | | - EUID_BASE_URL = os.getenv("EUID_BASE_URL", "http://localhost:8080"); |
141 | | - EUID_API_KEY = os.getenv("EUID_API_KEY", "trusted-partner-key"); |
142 | | - EUID_SECRET_KEY = os.getenv("EUID_SECRET_KEY", "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg="); |
143 | | - |
144 | | - publisher_client = Uid2PublisherClient(EUID_BASE_URL, EUID_API_KEY, EUID_SECRET_KEY) |
145 | | - tc_string = "CPhJRpMPhJRpMABAMBFRACBoALAAAEJAAIYgAKwAQAKgArABAAqAAA" |
146 | | - |
147 | | - token_generate_response = publisher_client. generate_token( TokenGenerateInput. from_email( "[email protected]"). with_transparency_and_consent_string( tc_string)) |
148 | | - self.assertFalse(token_generate_response.is_optout()) |
149 | | - identity = token_generate_response.get_identity() |
150 | | - self.assertIsNotNone(identity) |
151 | | - self.assertFalse(identity.is_due_for_refresh()) |
152 | | - self.assertIsNotNone(identity.get_advertising_token()) |
153 | | - self.assertIsNotNone(identity.get_refresh_token()) |
154 | | - self.assertIsNotNone(identity.get_json_string()) |
155 | | - self.assertTrue(identity.is_refreshable()) |
156 | | - |
157 | | - |
158 | | - |
159 | | - def test_integration_tc_string_with_insufficient_consent(self): |
160 | | - EUID_BASE_URL = os.getenv("EUID_BASE_URL", "http://localhost:8080") |
161 | | - EUID_API_KEY = os.getenv("EUID_API_KEY", "trusted-partner-key") |
162 | | - EUID_SECRET_KEY = os.getenv("EUID_SECRET_KEY", "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=") |
163 | | - |
164 | | - publisher_client = Uid2PublisherClient(EUID_BASE_URL, EUID_API_KEY, EUID_SECRET_KEY) |
165 | | - tc_string = "CPehXK9PehXK9ABAMBFRACBoADAAAEJAAIYgAKwAQAKgArABAAqAAA" |
166 | | - with self.assertRaises(ValueError): |
167 | | - publisher_client. generate_token( TokenGenerateInput. from_email( "[email protected]"). with_transparency_and_consent_string( tc_string)) |
168 | | - |
169 | | - def test_integration_optout_generate_token(self): |
170 | | - EUID_BASE_URL = os.getenv("EUID_BASE_URL", "http://localhost:8080") |
171 | | - EUID_API_KEY = os.getenv("EUID_API_KEY", "trusted-partner-key") |
172 | | - EUID_SECRET_KEY = os.getenv("EUID_SECRET_KEY", "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=") |
173 | | - |
174 | | - publisher_client = Uid2PublisherClient(EUID_BASE_URL, EUID_API_KEY, EUID_SECRET_KEY) |
175 | | - tc_string = "CPhJRpMPhJRpMABAMBFRACBoALAAAEJAAIYgAKwAQAKgArABAAqAAA" |
176 | | - input = TokenGenerateInput. from_email( "[email protected]"). do_not_generate_tokens_for_opted_out(). with_transparency_and_consent_string( tc_string) |
177 | | - print(input.get_as_json_string()) |
178 | | - token_generate_response = publisher_client.generate_token(input) |
179 | | - self.assertTrue(token_generate_response.is_optout()) |
180 | | - self.assertFalse(token_generate_response.is_success()) |
181 | | - self.assertIsNone(token_generate_response.get_identity()) |
182 | | - |
183 | 192 |
|
184 | 193 | if __name__ == '__main__': |
185 | 194 | unittest.main() |
0 commit comments