Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for ApplicationAuth CR + tests; small pylint fixes #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ see https://github.com/3scale/3scale-operator/blob/master/doc/backend-reference.
- ProxyConfigPromote
- Applications
- Methods
- ApplicationAuth

Command to run integration unit tests: `pipenv run pytest --log-cli-level=10 -vvvv -s ./tests/integration/ |& tee x`

Expand Down
193 changes: 118 additions & 75 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import secrets
import random
import string
from distutils.util import strtobool

import pytest
Expand All @@ -9,7 +11,6 @@

import threescale_api
import threescale_api_crd
from threescale_api.resources import Application

from threescale_api_crd.resources import (
Service,
Expand All @@ -24,6 +25,7 @@
ApplicationPlan,
Proxy,
PricingRule,
Application,
)

load_dotenv()
Expand Down Expand Up @@ -119,7 +121,7 @@ def apicast_http_client(application, proxy, ssl_verify):
@pytest.fixture(scope="module")
def service_params():
suffix = get_suffix()
return dict(name=f"test-{suffix}")
return {"name": f"test-{suffix}"}


@pytest.fixture(scope="module")
Expand All @@ -133,14 +135,14 @@ def service(service_params, api) -> Service:
def account_params():
suffix = get_suffix()
name = f"testacc{suffix}"
return dict(
name=name,
username=name,
org_name=name,
monthly_billing_enabled=False,
monthly_charging_enabled=False,
email=f"{name}@name.none",
)
return {
"name": name,
"username": name,
"org_name": name,
"monthly_billing_enabled": False,
"monthly_charging_enabled": False,
"email": f"{name}@name.none",
}


@pytest.fixture(scope="module")
Expand All @@ -159,12 +161,12 @@ def acc_user(account):
@pytest.fixture(scope="module")
def acc_user2_params(account, acc_user):
name = acc_user["username"] + "2"
return dict(
username=name,
email=f"{name}@name.none",
role="member",
account_name=account["name"],
)
return {
"username": name,
"email": f"{name}@name.none",
"role": "member",
"account_name": account["name"],
}


@pytest.fixture(scope="module")
Expand All @@ -175,12 +177,12 @@ def acc_user2(account, acc_user, acc_user2_params):
@pytest.fixture(scope="module")
def application_plan_params(service) -> dict:
suffix = get_suffix()
return dict(
name=f"test-{suffix}",
setup_fee="1.00",
state_event="publish",
cost_per_month="3.00",
)
return {
"name": f"test-{suffix}",
"setup_fee": "1.00",
"state_event": "publish",
"cost_per_month": "3.00",
}


@pytest.fixture(scope="module")
Expand All @@ -194,13 +196,13 @@ def application_plan(api, service, application_plan_params) -> ApplicationPlan:
def application_params(application_plan, service, account):
suffix = get_suffix()
name = f"test-{suffix}"
return dict(
name=name,
description=name,
plan_id=application_plan["id"],
service_id=service["id"],
account_id=account["id"],
)
return {
"name": name,
"description": name,
"plan_id": application_plan["id"],
"service_id": service["id"],
"account_id": account["id"],
}


@pytest.fixture(scope="module")
Expand All @@ -210,6 +212,30 @@ def application(service, application_plan, application_params, account) -> Appli
cleanup(resource)


@pytest.fixture(scope="module")
def app_key_params(account, application):
value = "".join(
random.choices(
string.ascii_uppercase
+ string.digits
+ "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
k=100,
)
)
return {
"application_id": application["id"],
"account_id": account["id"],
"key": value,
}


@pytest.fixture(scope="module")
def app_key(application, app_key_params) -> threescale_api.resources.ApplicationKey:
resource = application.keys.create(params=app_key_params)
yield resource
cleanup(resource)


@pytest.fixture(scope="module")
def proxy(service) -> Proxy:
return service.proxy.list()
Expand Down Expand Up @@ -244,15 +270,15 @@ def metric_params(service):
suffix = get_suffix()
friendly_name = f"test-metric-{suffix}"
name = f"{friendly_name}".replace("-", "_")
return dict(friendly_name=friendly_name, system_name=name, unit="count")
return {"friendly_name": friendly_name, "system_name": name, "unit": "count"}


@pytest.fixture(scope="module")
def backend_metric_params():
suffix = get_suffix()
friendly_name = f"test-metric-{suffix}"
name = f"{friendly_name}".replace("-", "")
return dict(friendly_name=friendly_name, system_name=name, unit="count")
return {"friendly_name": friendly_name, "system_name": name, "unit": "count"}


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -284,7 +310,7 @@ def method_params():
suffix = get_suffix()
friendly_name = f"test-method-{suffix}"
system_name = f"{friendly_name}".replace("-", "_")
return dict(friendly_name=friendly_name, system_name=system_name)
return {"friendly_name": friendly_name, "system_name": system_name}


# 'friendly_name' is id in CRD for methods
Expand Down Expand Up @@ -321,7 +347,12 @@ def mapping_rule_params(service):
Fixture for getting paramteres for mapping rule for product/service.
"""
hits_metric = service.metrics.read_by_name("hits")
return dict(http_method="GET", pattern="/get", metric_id=hits_metric["id"], delta=1)
return {
"http_method": "GET",
"pattern": "/get",
"metric_id": hits_metric["id"],
"delta": 1,
}


@pytest.fixture(scope="module")
Expand All @@ -330,7 +361,12 @@ def backend_mapping_rule_params(backend, backend_metric):
Fixture for getting paramteres for mapping rule for backend.
"""
back = backend_metric["id"]
return dict(http_method="GET", pattern="/anything/get/ida", metric_id=back, delta=1)
return {
"http_method": "GET",
"pattern": "/anything/get/ida",
"metric_id": back,
"delta": 1,
}


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -388,13 +424,13 @@ def create_mapping_rule(service):
rules = []

def _create(metric, http_method, path):
params = dict(
service_id=service["id"],
http_method=http_method,
pattern=f"/anything{path}",
delta=1,
metric_id=metric["id"],
)
params = {
"service_id": service["id"],
"http_method": http_method,
"pattern": f"/anything{path}",
"delta": 1,
"metric_id": metric["id"],
}
rule = service.mapping_rules.create(params=params)
rules.append(rule)
return rule
Expand All @@ -415,13 +451,13 @@ def create_backend_mapping_rule(backend):
rules = []

def _create(backend_metric, http_method, path):
params = dict(
backend_id=backend["id"],
http_method=http_method,
pattern=f"/anything{path}",
delta=1,
metric_id=backend_metric["id"],
)
params = {
"backend_id": backend["id"],
"http_method": http_method,
"pattern": f"/anything{path}",
"delta": 1,
"metric_id": backend_metric["id"],
}
rule = backend.mapping_rules.create(params=params)
rules.append(rule)
return rule
Expand All @@ -439,9 +475,11 @@ def backend_params(api_backend):
Fixture for getting backend parameters.
"""
suffix = get_suffix()
return dict(
name=f"test-backend-{suffix}", private_endpoint=api_backend, description="111"
)
return {
"name": f"test-backend-{suffix}",
"private_endpoint": api_backend,
"description": "111",
}


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -479,12 +517,12 @@ def tenant_params():
"""
Params for custom tenant
"""
return dict(
username=f"tenant{get_suffix()}",
admin_password="123456",
email=f"e{get_suffix()}@invalid.invalid",
org_name="org",
)
return {
"username": f"tenant{get_suffix()}",
"admin_password": "123456",
"email": f"e{get_suffix()}@invalid.invalid",
"org_name": "org",
}


@pytest.fixture(scope="module")
Expand All @@ -499,7 +537,7 @@ def active_docs_params(active_docs_body):
suffix = get_suffix()
name = f"test-{suffix}"
des = f"description-{suffix}"
return dict(name=name, body=active_docs_body, description=des)
return {"name": name, "body": active_docs_body, "description": des}


@pytest.fixture(scope="module")
Expand All @@ -518,17 +556,17 @@ def active_doc(api, service, active_docs_params) -> ActiveDoc:
def openapi_params(active_docs_body):
suffix = get_suffix()
name = f"test-{suffix}"
params = dict(
name=name,
productionPublicBaseURL="http://productionPublicBaseURL",
stagingPublicBaseURL="http://stagingPublicBaseURL",
productSystemName="PrOdUcTsYsTeMnAmE",
privateBaseURL="http://privateBaseURL",
prefixMatching=True,
privateAPIHostHeader="privateAPIHostHeader",
privateAPISecretToken="privateAPISecretToken",
body=active_docs_body,
)
params = {
"name": name,
"productionPublicBaseURL": "http://productionPublicBaseURL",
"stagingPublicBaseURL": "http://stagingPublicBaseURL",
"productSystemName": "PrOdUcTsYsTeMnAmE",
"privateBaseURL": "http://privateBaseURL",
"prefixMatching": True,
"privateAPIHostHeader": "privateAPIHostHeader",
"privateAPISecretToken": "privateAPISecretToken",
"body": active_docs_body,
}
return params


Expand Down Expand Up @@ -584,7 +622,7 @@ def policy_registry_params(policy_registry_schema):
"""Params for policy registry."""
suffix = get_suffix()
name = f"test-{suffix}"
return dict(name=name, version="0.1", schema=policy_registry_schema)
return {"name": name, "version": "0.1", "schema": policy_registry_schema}


@pytest.fixture(scope="module")
Expand All @@ -601,7 +639,7 @@ def policy_registry(api, policy_registry_params) -> PolicyRegistry:
@pytest.fixture(scope="module")
def limit_params(metric):
"""Params for limit."""
return dict(metric_id=metric["id"], period="minute", value=10)
return {"metric_id": metric["id"], "period": "minute", "value": 10}


@pytest.fixture(scope="module")
Expand All @@ -617,7 +655,7 @@ def limit(service, application, application_plan, metric, limit_params) -> Limit
@pytest.fixture(scope="module")
def backend_limit_params(backend_metric):
"""Params for limit."""
return dict(metric_id=backend_metric["id"], period="minute", value=10)
return {"metric_id": backend_metric["id"], "period": "minute", "value": 10}


@pytest.fixture(scope="module")
Expand All @@ -640,7 +678,7 @@ def backend_limit(
@pytest.fixture(scope="module")
def prule_params(metric):
"""Params for prule."""
return dict(metric_id=metric["id"], min=10, max=100, cost_per_unit="10")
return {"metric_id": metric["id"], "min": 10, "max": 100, "cost_per_unit": "10"}


@pytest.fixture(scope="module")
Expand All @@ -656,7 +694,12 @@ def prule(service, application, application_plan, metric, prule_params) -> Prici
@pytest.fixture(scope="module")
def backend_prule_params(backend_metric):
"""Params for prule."""
return dict(metric_id=backend_metric["id"], min=10, max=100, cost_per_unit=10)
return {
"metric_id": backend_metric["id"],
"min": 10,
"max": 100,
"cost_per_unit": 10,
}


@pytest.fixture(scope="module")
Expand All @@ -683,7 +726,7 @@ def promote_params(api, service):
"""
Promote params for service.
"""
return dict(productCRName=service.crd.as_dict()["metadata"]["name"])
return {"productCRName": service.crd.as_dict()["metadata"]["name"]}


@pytest.fixture(scope="module")
Expand Down
Loading
Loading