-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_bidstream_client_e2e.py
More file actions
105 lines (81 loc) · 4.28 KB
/
test_bidstream_client_e2e.py
File metadata and controls
105 lines (81 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import unittest
from uid2_client import BidstreamClient, Uid2PublisherClient, TokenGenerateInput, DecryptionStatus
@unittest.skipIf(
os.getenv("UID2_BASE_URL") is None
or os.getenv("UID2_API_KEY") is None
or os.getenv("UID2_SECRET_KEY") is None,
"Environment variables UID2_BASE_URL, UID2_API_KEY, and UID2_SECRET_KEY must be set",
)
class BidstreamClientIntegrationTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.UID2_BASE_URL = os.getenv("UID2_BASE_URL")
cls.UID2_API_KEY = os.getenv("UID2_API_KEY")
cls.UID2_SECRET_KEY = os.getenv("UID2_SECRET_KEY")
if cls.UID2_BASE_URL and cls.UID2_API_KEY and cls.UID2_SECRET_KEY:
cls.bidstream_client = BidstreamClient(cls.UID2_BASE_URL, cls.UID2_API_KEY, cls.UID2_SECRET_KEY)
cls.publisher_client = Uid2PublisherClient(cls.UID2_BASE_URL, cls.UID2_API_KEY, cls.UID2_SECRET_KEY)
else:
raise Exception("set the required UID2_BASE_URL/UID2_API_KEY/UID2_SECRET_KEY environment variables first")
def test_bidstream_client_key_refresh(self):
refresh_response = self.bidstream_client.refresh()
self.assertTrue(refresh_response.success)
def test_bidstream_client_with_generated_token(self):
token_response = self.publisher_client.generate_token(
TokenGenerateInput.from_email("hopefully-not-opted-out@example.com").do_not_generate_tokens_for_opted_out()
)
identity = token_response.get_identity()
advertising_token = identity.get_advertising_token()
self.assertIsNotNone(advertising_token)
refresh_response = self.bidstream_client.refresh()
self.assertTrue(refresh_response.success)
decryption_response = self.bidstream_client.decrypt_token_into_raw_uid(
advertising_token, "example.com"
)
self.assertTrue(decryption_response.success)
self.assertIsNotNone(decryption_response.uid)
self.assertIsNotNone(decryption_response.established)
self.assertIsNotNone(decryption_response.site_id)
def test_bidstream_client_with_invalid_token(self):
refresh_response = self.bidstream_client.refresh()
self.assertTrue(refresh_response.success)
invalid_token = "invalid-token"
decryption_response = self.bidstream_client.decrypt_token_into_raw_uid(
invalid_token, "example.com"
)
self.assertFalse(decryption_response.success)
def test_bidstream_client_without_refresh(self):
token_response = self.publisher_client.generate_token(
TokenGenerateInput.from_email("hopefully-not-opted-out@example.com").do_not_generate_tokens_for_opted_out()
)
identity = token_response.get_identity()
advertising_token = identity.get_advertising_token()
fresh_client = BidstreamClient(self.UID2_BASE_URL, self.UID2_API_KEY, self.UID2_SECRET_KEY)
decryption_response = fresh_client.decrypt_token_into_raw_uid(
advertising_token, "example.com"
)
self.assertFalse(decryption_response.success)
def test_bidstream_client_error_handling(self):
bad_client = BidstreamClient(self.UID2_BASE_URL, "bad-api-key", self.UID2_SECRET_KEY)
refresh_response = bad_client.refresh()
self.assertFalse(refresh_response.success)
bad_client = BidstreamClient(self.UID2_BASE_URL, self.UID2_API_KEY, "bad-secret-key")
refresh_response = bad_client.refresh()
self.assertFalse(refresh_response.success)
def test_bidstream_client_phone_token_decryption(self):
token_response = self.publisher_client.generate_token(
TokenGenerateInput.from_phone("+12345678901").do_not_generate_tokens_for_opted_out()
)
self.assertFalse(token_response.is_optout())
identity = token_response.get_identity()
advertising_token = identity.get_advertising_token()
refresh_response = self.bidstream_client.refresh()
self.assertTrue(refresh_response.success)
decryption_response = self.bidstream_client.decrypt_token_into_raw_uid(
advertising_token, "example.com"
)
self.assertTrue(decryption_response.success)
self.assertIsNotNone(decryption_response.uid)
if __name__ == '__main__':
unittest.main()