11import os
22import secrets
3+ import random
4+ import string
35from distutils .util import strtobool
46
57import pytest
911
1012import threescale_api
1113import threescale_api_crd
12- from threescale_api .resources import Application
1314
1415from threescale_api_crd .resources import (
1516 Service ,
2425 ApplicationPlan ,
2526 Proxy ,
2627 PricingRule ,
28+ Application ,
2729)
2830
2931load_dotenv ()
@@ -119,7 +121,7 @@ def apicast_http_client(application, proxy, ssl_verify):
119121@pytest .fixture (scope = "module" )
120122def service_params ():
121123 suffix = get_suffix ()
122- return dict ( name = f"test-{ suffix } " )
124+ return { " name" : f"test-{ suffix } " }
123125
124126
125127@pytest .fixture (scope = "module" )
@@ -133,14 +135,14 @@ def service(service_params, api) -> Service:
133135def account_params ():
134136 suffix = get_suffix ()
135137 name = f"testacc{ suffix } "
136- return dict (
137- name = name ,
138- username = name ,
139- org_name = name ,
140- monthly_billing_enabled = False ,
141- monthly_charging_enabled = False ,
142- email = f"{ name } @name.none" ,
143- )
138+ return {
139+ " name" : name ,
140+ " username" : name ,
141+ " org_name" : name ,
142+ " monthly_billing_enabled" : False ,
143+ " monthly_charging_enabled" : False ,
144+ " email" : f"{ name } @name.none" ,
145+ }
144146
145147
146148@pytest .fixture (scope = "module" )
@@ -159,12 +161,12 @@ def acc_user(account):
159161@pytest .fixture (scope = "module" )
160162def acc_user2_params (account , acc_user ):
161163 name = acc_user ["username" ] + "2"
162- return dict (
163- username = name ,
164- email = f"{ name } @name.none" ,
165- role = "member" ,
166- account_name = account ["name" ],
167- )
164+ return {
165+ " username" : name ,
166+ " email" : f"{ name } @name.none" ,
167+ " role" : "member" ,
168+ " account_name" : account ["name" ],
169+ }
168170
169171
170172@pytest .fixture (scope = "module" )
@@ -175,12 +177,12 @@ def acc_user2(account, acc_user, acc_user2_params):
175177@pytest .fixture (scope = "module" )
176178def application_plan_params (service ) -> dict :
177179 suffix = get_suffix ()
178- return dict (
179- name = f"test-{ suffix } " ,
180- setup_fee = "1.00" ,
181- state_event = "publish" ,
182- cost_per_month = "3.00" ,
183- )
180+ return {
181+ " name" : f"test-{ suffix } " ,
182+ " setup_fee" : "1.00" ,
183+ " state_event" : "publish" ,
184+ " cost_per_month" : "3.00" ,
185+ }
184186
185187
186188@pytest .fixture (scope = "module" )
@@ -194,13 +196,13 @@ def application_plan(api, service, application_plan_params) -> ApplicationPlan:
194196def application_params (application_plan , service , account ):
195197 suffix = get_suffix ()
196198 name = f"test-{ suffix } "
197- return dict (
198- name = name ,
199- description = name ,
200- plan_id = application_plan ["id" ],
201- service_id = service ["id" ],
202- account_id = account ["id" ],
203- )
199+ return {
200+ " name" : name ,
201+ " description" : name ,
202+ " plan_id" : application_plan ["id" ],
203+ " service_id" : service ["id" ],
204+ " account_id" : account ["id" ],
205+ }
204206
205207
206208@pytest .fixture (scope = "module" )
@@ -210,6 +212,30 @@ def application(service, application_plan, application_params, account) -> Appli
210212 cleanup (resource )
211213
212214
215+ @pytest .fixture (scope = "module" )
216+ def app_key_params (account , application ):
217+ value = "" .join (
218+ random .choices (
219+ string .ascii_uppercase
220+ + string .digits
221+ + "!\" #$%&'()*+,-./:;<=>?@[\\ ]^_`{|}~" ,
222+ k = 100 ,
223+ )
224+ )
225+ return {
226+ "application_id" : application ["id" ],
227+ "account_id" : account ["id" ],
228+ "key" : value ,
229+ }
230+
231+
232+ @pytest .fixture (scope = "module" )
233+ def app_key (application , app_key_params ) -> threescale_api .resources .ApplicationKey :
234+ resource = application .keys .create (params = app_key_params )
235+ yield resource
236+ cleanup (resource )
237+
238+
213239@pytest .fixture (scope = "module" )
214240def proxy (service ) -> Proxy :
215241 return service .proxy .list ()
@@ -244,15 +270,15 @@ def metric_params(service):
244270 suffix = get_suffix ()
245271 friendly_name = f"test-metric-{ suffix } "
246272 name = f"{ friendly_name } " .replace ("-" , "_" )
247- return dict ( friendly_name = friendly_name , system_name = name , unit = " count")
273+ return { " friendly_name" : friendly_name , " system_name" : name , " unit" : " count"}
248274
249275
250276@pytest .fixture (scope = "module" )
251277def backend_metric_params ():
252278 suffix = get_suffix ()
253279 friendly_name = f"test-metric-{ suffix } "
254280 name = f"{ friendly_name } " .replace ("-" , "" )
255- return dict ( friendly_name = friendly_name , system_name = name , unit = " count")
281+ return { " friendly_name" : friendly_name , " system_name" : name , " unit" : " count"}
256282
257283
258284@pytest .fixture (scope = "module" )
@@ -284,7 +310,7 @@ def method_params():
284310 suffix = get_suffix ()
285311 friendly_name = f"test-method-{ suffix } "
286312 system_name = f"{ friendly_name } " .replace ("-" , "_" )
287- return dict ( friendly_name = friendly_name , system_name = system_name )
313+ return { " friendly_name" : friendly_name , " system_name" : system_name }
288314
289315
290316# 'friendly_name' is id in CRD for methods
@@ -321,7 +347,12 @@ def mapping_rule_params(service):
321347 Fixture for getting paramteres for mapping rule for product/service.
322348 """
323349 hits_metric = service .metrics .read_by_name ("hits" )
324- return dict (http_method = "GET" , pattern = "/get" , metric_id = hits_metric ["id" ], delta = 1 )
350+ return {
351+ "http_method" : "GET" ,
352+ "pattern" : "/get" ,
353+ "metric_id" : hits_metric ["id" ],
354+ "delta" : 1 ,
355+ }
325356
326357
327358@pytest .fixture (scope = "module" )
@@ -330,7 +361,12 @@ def backend_mapping_rule_params(backend, backend_metric):
330361 Fixture for getting paramteres for mapping rule for backend.
331362 """
332363 back = backend_metric ["id" ]
333- return dict (http_method = "GET" , pattern = "/anything/get/ida" , metric_id = back , delta = 1 )
364+ return {
365+ "http_method" : "GET" ,
366+ "pattern" : "/anything/get/ida" ,
367+ "metric_id" : back ,
368+ "delta" : 1 ,
369+ }
334370
335371
336372@pytest .fixture (scope = "module" )
@@ -388,13 +424,13 @@ def create_mapping_rule(service):
388424 rules = []
389425
390426 def _create (metric , http_method , path ):
391- params = dict (
392- service_id = service ["id" ],
393- http_method = http_method ,
394- pattern = f"/anything{ path } " ,
395- delta = 1 ,
396- metric_id = metric ["id" ],
397- )
427+ params = {
428+ " service_id" : service ["id" ],
429+ " http_method" : http_method ,
430+ " pattern" : f"/anything{ path } " ,
431+ " delta" : 1 ,
432+ " metric_id" : metric ["id" ],
433+ }
398434 rule = service .mapping_rules .create (params = params )
399435 rules .append (rule )
400436 return rule
@@ -415,13 +451,13 @@ def create_backend_mapping_rule(backend):
415451 rules = []
416452
417453 def _create (backend_metric , http_method , path ):
418- params = dict (
419- backend_id = backend ["id" ],
420- http_method = http_method ,
421- pattern = f"/anything{ path } " ,
422- delta = 1 ,
423- metric_id = backend_metric ["id" ],
424- )
454+ params = {
455+ " backend_id" : backend ["id" ],
456+ " http_method" : http_method ,
457+ " pattern" : f"/anything{ path } " ,
458+ " delta" : 1 ,
459+ " metric_id" : backend_metric ["id" ],
460+ }
425461 rule = backend .mapping_rules .create (params = params )
426462 rules .append (rule )
427463 return rule
@@ -439,9 +475,11 @@ def backend_params(api_backend):
439475 Fixture for getting backend parameters.
440476 """
441477 suffix = get_suffix ()
442- return dict (
443- name = f"test-backend-{ suffix } " , private_endpoint = api_backend , description = "111"
444- )
478+ return {
479+ "name" : f"test-backend-{ suffix } " ,
480+ "private_endpoint" : api_backend ,
481+ "description" : "111" ,
482+ }
445483
446484
447485@pytest .fixture (scope = "module" )
@@ -479,12 +517,12 @@ def tenant_params():
479517 """
480518 Params for custom tenant
481519 """
482- return dict (
483- username = f"tenant{ get_suffix ()} " ,
484- admin_password = "123456" ,
485- email = f"e{ get_suffix ()} @invalid.invalid" ,
486- org_name = "org" ,
487- )
520+ return {
521+ " username" : f"tenant{ get_suffix ()} " ,
522+ " admin_password" : "123456" ,
523+ " email" : f"e{ get_suffix ()} @invalid.invalid" ,
524+ " org_name" : "org" ,
525+ }
488526
489527
490528@pytest .fixture (scope = "module" )
@@ -499,7 +537,7 @@ def active_docs_params(active_docs_body):
499537 suffix = get_suffix ()
500538 name = f"test-{ suffix } "
501539 des = f"description-{ suffix } "
502- return dict ( name = name , body = active_docs_body , description = des )
540+ return { " name" : name , " body" : active_docs_body , " description" : des }
503541
504542
505543@pytest .fixture (scope = "module" )
@@ -518,17 +556,17 @@ def active_doc(api, service, active_docs_params) -> ActiveDoc:
518556def openapi_params (active_docs_body ):
519557 suffix = get_suffix ()
520558 name = f"test-{ suffix } "
521- params = dict (
522- name = name ,
523- productionPublicBaseURL = "http://productionPublicBaseURL" ,
524- stagingPublicBaseURL = "http://stagingPublicBaseURL" ,
525- productSystemName = "PrOdUcTsYsTeMnAmE" ,
526- privateBaseURL = "http://privateBaseURL" ,
527- prefixMatching = True ,
528- privateAPIHostHeader = "privateAPIHostHeader" ,
529- privateAPISecretToken = "privateAPISecretToken" ,
530- body = active_docs_body ,
531- )
559+ params = {
560+ " name" : name ,
561+ " productionPublicBaseURL" : "http://productionPublicBaseURL" ,
562+ " stagingPublicBaseURL" : "http://stagingPublicBaseURL" ,
563+ " productSystemName" : "PrOdUcTsYsTeMnAmE" ,
564+ " privateBaseURL" : "http://privateBaseURL" ,
565+ " prefixMatching" : True ,
566+ " privateAPIHostHeader" : "privateAPIHostHeader" ,
567+ " privateAPISecretToken" : "privateAPISecretToken" ,
568+ " body" : active_docs_body ,
569+ }
532570 return params
533571
534572
@@ -584,7 +622,7 @@ def policy_registry_params(policy_registry_schema):
584622 """Params for policy registry."""
585623 suffix = get_suffix ()
586624 name = f"test-{ suffix } "
587- return dict ( name = name , version = " 0.1" , schema = policy_registry_schema )
625+ return { " name" : name , " version" : " 0.1" , " schema" : policy_registry_schema }
588626
589627
590628@pytest .fixture (scope = "module" )
@@ -601,7 +639,7 @@ def policy_registry(api, policy_registry_params) -> PolicyRegistry:
601639@pytest .fixture (scope = "module" )
602640def limit_params (metric ):
603641 """Params for limit."""
604- return dict ( metric_id = metric ["id" ], period = " minute" , value = 10 )
642+ return { " metric_id" : metric ["id" ], " period" : " minute" , " value" : 10 }
605643
606644
607645@pytest .fixture (scope = "module" )
@@ -617,7 +655,7 @@ def limit(service, application, application_plan, metric, limit_params) -> Limit
617655@pytest .fixture (scope = "module" )
618656def backend_limit_params (backend_metric ):
619657 """Params for limit."""
620- return dict ( metric_id = backend_metric ["id" ], period = " minute" , value = 10 )
658+ return { " metric_id" : backend_metric ["id" ], " period" : " minute" , " value" : 10 }
621659
622660
623661@pytest .fixture (scope = "module" )
@@ -640,7 +678,7 @@ def backend_limit(
640678@pytest .fixture (scope = "module" )
641679def prule_params (metric ):
642680 """Params for prule."""
643- return dict ( metric_id = metric ["id" ], min = 10 , max = 100 , cost_per_unit = " 10")
681+ return { " metric_id" : metric ["id" ], " min" : 10 , " max" : 100 , " cost_per_unit" : " 10"}
644682
645683
646684@pytest .fixture (scope = "module" )
@@ -656,7 +694,12 @@ def prule(service, application, application_plan, metric, prule_params) -> Prici
656694@pytest .fixture (scope = "module" )
657695def backend_prule_params (backend_metric ):
658696 """Params for prule."""
659- return dict (metric_id = backend_metric ["id" ], min = 10 , max = 100 , cost_per_unit = 10 )
697+ return {
698+ "metric_id" : backend_metric ["id" ],
699+ "min" : 10 ,
700+ "max" : 100 ,
701+ "cost_per_unit" : 10 ,
702+ }
660703
661704
662705@pytest .fixture (scope = "module" )
@@ -683,7 +726,7 @@ def promote_params(api, service):
683726 """
684727 Promote params for service.
685728 """
686- return dict ( productCRName = service .crd .as_dict ()["metadata" ]["name" ])
729+ return { " productCRName" : service .crd .as_dict ()["metadata" ]["name" ]}
687730
688731
689732@pytest .fixture (scope = "module" )
0 commit comments