15
15
import os
16
16
import uuid
17
17
18
- from google .api_core . exceptions import NotFound
18
+ from google .protobuf import timestamp_pb2
19
19
import pytest
20
20
21
21
import create_cdn_key
22
+ import create_cdn_key_akamai
22
23
import delete_cdn_key
23
24
import get_cdn_key
24
25
import list_cdn_keys
25
26
import update_cdn_key
27
+ import update_cdn_key_akamai
28
+ import utils
26
29
27
30
location = "us-central1"
28
31
project_id = os .environ ["GOOGLE_CLOUD_PROJECT" ]
29
- gcdn_cdn_key_id = f"my-python-test-cdn-key-{ uuid .uuid4 ()} "
30
- akamai_cdn_key_id = f"my-python-test-cdn-key-{ uuid .uuid4 ()} "
32
+ now = timestamp_pb2 .Timestamp ()
33
+ now .GetCurrentTime ()
34
+
35
+ media_cdn_key_id = f"python-test-media-key-{ uuid .uuid4 ().hex [:5 ]} -{ now .seconds } "
36
+ cloud_cdn_key_id = f"python-test-cloud-key-{ uuid .uuid4 ().hex [:5 ]} -{ now .seconds } "
37
+ akamai_cdn_key_id = f"python-test-akamai-key-{ uuid .uuid4 ().hex [:5 ]} -{ now .seconds } "
31
38
32
39
hostname = "cdn.example.com"
33
40
updated_hostname = "updated.example.com"
41
+ key_name = "my-key"
34
42
35
- gcdn_key_name = "gcdn-key"
36
- gcdn_private_key = "VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=="
37
- updated_gcdn_private_key = "VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg=="
38
- akamai_key = gcdn_private_key
39
- updated_akamai_key = updated_gcdn_private_key
43
+ media_cdn_private_key = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNA"
44
+ updated_media_cdn_private_key = (
45
+ "ZZZzNDU2Nzg5MDEyMzQ1Njc4OTAxzg5MDEyMzQ1Njc4OTAxMjM0NTY3DkwMTIZZZ"
46
+ )
47
+ cloud_cdn_private_key = "VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=="
48
+ updated_cloud_cdn_private_key = "VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg=="
49
+ akamai_key = cloud_cdn_private_key
50
+ updated_akamai_key = updated_cloud_cdn_private_key
40
51
41
52
42
53
def test_cdn_key_operations (capsys : pytest .fixture ) -> None :
43
54
44
- try :
45
- delete_cdn_key .delete_cdn_key (project_id , location , gcdn_cdn_key_id )
46
- except NotFound as e :
47
- print (f"Ignoring NotFound, details: { e } " )
48
- out , _ = capsys .readouterr ()
55
+ utils .delete_stale_cdn_keys (project_id , location )
49
56
50
- try :
51
- delete_cdn_key .delete_cdn_key (project_id , location , akamai_cdn_key_id )
52
- except NotFound as e :
53
- print (f"Ignoring NotFound, details: { e } " )
54
- out , _ = capsys .readouterr ()
55
-
56
- # GCDN CDN key tests
57
+ # Media CDN key tests
57
58
58
59
create_cdn_key .create_cdn_key (
59
60
project_id ,
60
61
location ,
61
- gcdn_cdn_key_id ,
62
+ media_cdn_key_id ,
62
63
hostname ,
63
- gcdn_key_name ,
64
- gcdn_private_key ,
64
+ key_name ,
65
+ media_cdn_private_key ,
66
+ False ,
65
67
)
66
68
out , _ = capsys .readouterr ()
67
- assert gcdn_cdn_key_id in out
69
+ assert media_cdn_key_id in out
68
70
69
71
list_cdn_keys .list_cdn_keys (project_id , location )
70
72
out , _ = capsys .readouterr ()
71
- assert gcdn_cdn_key_id in out
73
+ assert media_cdn_key_id in out
72
74
73
- # Update the hostname only
75
+ # Update the hostname and private key; the private key value
76
+ # is not returned by the client
74
77
response = update_cdn_key .update_cdn_key (
75
- project_id , location , gcdn_cdn_key_id , updated_hostname
78
+ project_id ,
79
+ location ,
80
+ media_cdn_key_id ,
81
+ updated_hostname ,
82
+ key_name ,
83
+ updated_media_cdn_private_key ,
84
+ False ,
76
85
)
77
86
out , _ = capsys .readouterr ()
78
- assert gcdn_cdn_key_id in out
87
+ assert media_cdn_key_id in out
79
88
assert updated_hostname in response .hostname
80
89
81
- # Update the private key; the private key value is not returned by the client
82
- response = update_cdn_key .update_cdn_key (
90
+ get_cdn_key .get_cdn_key (project_id , location , media_cdn_key_id )
91
+ out , _ = capsys .readouterr ()
92
+ assert media_cdn_key_id in out
93
+
94
+ delete_cdn_key .delete_cdn_key (project_id , location , media_cdn_key_id )
95
+ out , _ = capsys .readouterr ()
96
+ assert "Deleted CDN key" in out
97
+
98
+ # Cloud CDN key tests
99
+
100
+ create_cdn_key .create_cdn_key (
83
101
project_id ,
84
102
location ,
85
- gcdn_cdn_key_id ,
103
+ cloud_cdn_key_id ,
86
104
hostname ,
87
- gcdn_key_name ,
88
- updated_gcdn_private_key ,
105
+ key_name ,
106
+ cloud_cdn_private_key ,
107
+ True ,
108
+ )
109
+ out , _ = capsys .readouterr ()
110
+ assert cloud_cdn_key_id in out
111
+
112
+ list_cdn_keys .list_cdn_keys (project_id , location )
113
+ out , _ = capsys .readouterr ()
114
+ assert cloud_cdn_key_id in out
115
+
116
+ # Update the hostname and private key; the private key value
117
+ # is not returned by the client
118
+ response = update_cdn_key .update_cdn_key (
119
+ project_id ,
120
+ location ,
121
+ cloud_cdn_key_id ,
122
+ updated_hostname ,
123
+ key_name ,
124
+ updated_cloud_cdn_private_key ,
125
+ True ,
89
126
)
90
127
out , _ = capsys .readouterr ()
91
- assert gcdn_cdn_key_id in out
128
+ assert cloud_cdn_key_id in out
129
+ assert updated_hostname in response .hostname
92
130
93
- get_cdn_key .get_cdn_key (project_id , location , gcdn_cdn_key_id )
131
+ get_cdn_key .get_cdn_key (project_id , location , cloud_cdn_key_id )
94
132
out , _ = capsys .readouterr ()
95
- assert gcdn_cdn_key_id in out
133
+ assert cloud_cdn_key_id in out
96
134
97
- delete_cdn_key .delete_cdn_key (project_id , location , gcdn_cdn_key_id )
135
+ delete_cdn_key .delete_cdn_key (project_id , location , cloud_cdn_key_id )
98
136
out , _ = capsys .readouterr ()
99
137
assert "Deleted CDN key" in out
100
138
101
139
# Akamai CDN key tests
102
140
103
- create_cdn_key . create_cdn_key (
141
+ create_cdn_key_akamai . create_cdn_key_akamai (
104
142
project_id ,
105
143
location ,
106
144
akamai_cdn_key_id ,
107
145
hostname ,
108
- akamai_token_key = akamai_key ,
146
+ akamai_key ,
109
147
)
110
148
out , _ = capsys .readouterr ()
111
149
assert akamai_cdn_key_id in out
@@ -114,24 +152,18 @@ def test_cdn_key_operations(capsys: pytest.fixture) -> None:
114
152
out , _ = capsys .readouterr ()
115
153
assert akamai_cdn_key_id in out
116
154
117
- # Update the hostname only
118
- response = update_cdn_key .update_cdn_key (
119
- project_id , location , akamai_cdn_key_id , updated_hostname
120
- )
121
- out , _ = capsys .readouterr ()
122
- assert akamai_cdn_key_id in out
123
- assert updated_hostname in response .hostname
124
-
125
- # Update the private key; the private key value is not returned by the client
126
- response = update_cdn_key .update_cdn_key (
155
+ # Update the hostname and private key; the private key value
156
+ # is not returned by the client
157
+ response = update_cdn_key_akamai .update_cdn_key_akamai (
127
158
project_id ,
128
159
location ,
129
160
akamai_cdn_key_id ,
130
- hostname ,
131
- akamai_token_key = updated_akamai_key ,
161
+ updated_hostname ,
162
+ updated_akamai_key ,
132
163
)
133
164
out , _ = capsys .readouterr ()
134
165
assert akamai_cdn_key_id in out
166
+ assert updated_hostname in response .hostname
135
167
136
168
get_cdn_key .get_cdn_key (project_id , location , akamai_cdn_key_id )
137
169
out , _ = capsys .readouterr ()
0 commit comments