1515import os
1616import uuid
1717
18- from google .api_core . exceptions import NotFound
18+ from google .protobuf import timestamp_pb2
1919import pytest
2020
2121import create_cdn_key
22+ import create_cdn_key_akamai
2223import delete_cdn_key
2324import get_cdn_key
2425import list_cdn_keys
2526import update_cdn_key
27+ import update_cdn_key_akamai
28+ import utils
2629
2730location = "us-central1"
2831project_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 } "
3138
3239hostname = "cdn.example.com"
3340updated_hostname = "updated.example.com"
41+ key_name = "my-key"
3442
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
4051
4152
4253def test_cdn_key_operations (capsys : pytest .fixture ) -> None :
4354
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 )
4956
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
5758
5859 create_cdn_key .create_cdn_key (
5960 project_id ,
6061 location ,
61- gcdn_cdn_key_id ,
62+ media_cdn_key_id ,
6263 hostname ,
63- gcdn_key_name ,
64- gcdn_private_key ,
64+ key_name ,
65+ media_cdn_private_key ,
66+ False ,
6567 )
6668 out , _ = capsys .readouterr ()
67- assert gcdn_cdn_key_id in out
69+ assert media_cdn_key_id in out
6870
6971 list_cdn_keys .list_cdn_keys (project_id , location )
7072 out , _ = capsys .readouterr ()
71- assert gcdn_cdn_key_id in out
73+ assert media_cdn_key_id in out
7274
73- # Update the hostname only
75+ # Update the hostname and private key; the private key value
76+ # is not returned by the client
7477 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 ,
7685 )
7786 out , _ = capsys .readouterr ()
78- assert gcdn_cdn_key_id in out
87+ assert media_cdn_key_id in out
7988 assert updated_hostname in response .hostname
8089
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 (
83101 project_id ,
84102 location ,
85- gcdn_cdn_key_id ,
103+ cloud_cdn_key_id ,
86104 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 ,
89126 )
90127 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
92130
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 )
94132 out , _ = capsys .readouterr ()
95- assert gcdn_cdn_key_id in out
133+ assert cloud_cdn_key_id in out
96134
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 )
98136 out , _ = capsys .readouterr ()
99137 assert "Deleted CDN key" in out
100138
101139 # Akamai CDN key tests
102140
103- create_cdn_key . create_cdn_key (
141+ create_cdn_key_akamai . create_cdn_key_akamai (
104142 project_id ,
105143 location ,
106144 akamai_cdn_key_id ,
107145 hostname ,
108- akamai_token_key = akamai_key ,
146+ akamai_key ,
109147 )
110148 out , _ = capsys .readouterr ()
111149 assert akamai_cdn_key_id in out
@@ -114,24 +152,18 @@ def test_cdn_key_operations(capsys: pytest.fixture) -> None:
114152 out , _ = capsys .readouterr ()
115153 assert akamai_cdn_key_id in out
116154
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 (
127158 project_id ,
128159 location ,
129160 akamai_cdn_key_id ,
130- hostname ,
131- akamai_token_key = updated_akamai_key ,
161+ updated_hostname ,
162+ updated_akamai_key ,
132163 )
133164 out , _ = capsys .readouterr ()
134165 assert akamai_cdn_key_id in out
166+ assert updated_hostname in response .hostname
135167
136168 get_cdn_key .get_cdn_key (project_id , location , akamai_cdn_key_id )
137169 out , _ = capsys .readouterr ()
0 commit comments