Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

3scale-api

Package Overview
Dependencies
Maintainers
4
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3scale-api - npm Package Compare versions

Comparing version
0.34.2
to
0.35.0
+51
tests/integration/test_integration_backend_methods.py
import pytest
from threescale_api.errors import ApiClientError
from tests.integration import asserts
def test_list_methods(backend_hits_metric, backend_method):
assert len(backend_hits_metric.methods.list()) >= 1
def test_should_create_method(backend_method, method_params):
asserts.assert_resource(backend_method)
asserts.assert_resource_params(backend_method, method_params)
def test_should_not_create_method_for_custom_metric(backend_hits_metric, method_params):
resource = backend_hits_metric.methods.create(params=method_params, throws=False)
asserts.assert_errors_contains(resource, ['system_name'])
def test_should_friendly_name_be_required(backend_hits_metric):
resource = backend_hits_metric.methods.create(params={}, throws=False)
asserts.assert_errors_contains(resource, ['friendly_name'])
def test_should_raise_api_exception(backend_hits_metric):
with pytest.raises(ApiClientError):
backend_hits_metric.methods.create(params={})
def test_should_read_method(backend_method, method_params):
resource = backend_method.read()
asserts.assert_resource(resource)
asserts.assert_resource_params(resource, method_params)
def test_should_update_method(backend_method, updated_method_params):
resource = backend_method.update(params=updated_method_params)
asserts.assert_resource(resource)
asserts.assert_resource_params(resource, updated_method_params)
def test_should_delete_method(backend_hits_metric, updated_method_params):
resource = backend_hits_metric.methods.create(params=updated_method_params)
assert resource.exists()
resource.delete()
assert not resource.exists()
def test_should_list_methods(backend_hits_metric):
resources = backend_hits_metric.methods.list()
assert len(resources) == 1
+1
-1
Metadata-Version: 2.1
Name: 3scale-api
Version: 0.34.2
Version: 0.35.0
Summary: 3scale API python client

@@ -5,0 +5,0 @@ Home-page: https://github.com/pestanko/3scale-api-python

@@ -20,2 +20,3 @@ LICENSE

tests/integration/test_integration_backend_mapping_rules.py
tests/integration/test_integration_backend_methods.py
tests/integration/test_integration_backend_metrics.py

@@ -22,0 +23,0 @@ tests/integration/test_integration_backends.py

Metadata-Version: 2.1
Name: 3scale-api
Version: 0.34.2
Version: 0.35.0
Summary: 3scale API python client

@@ -5,0 +5,0 @@ Home-page: https://github.com/pestanko/3scale-api-python

import os
import secrets
import time
from distutils.util import strtobool
import string
import random

@@ -14,3 +15,4 @@ import pytest

BackendMappingRule, BackendUsage,
ActiveDoc, Webhooks, InvoiceState)
ActiveDoc, Webhooks, InvoiceState,
ApplicationKey)

@@ -50,3 +52,3 @@ load_dotenv()

ssl_verify = os.getenv('THREESCALE_SSL_VERIFY', 'false')
return bool(strtobool(ssl_verify))
return ssl_verify.lower() in ('y', 'yes', 't', 'true', 'on', '1')

@@ -146,2 +148,15 @@

@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) -> ApplicationKey:
resource = application.keys.create(params=app_key_params)
yield resource
cleanup(resource)
@pytest.fixture(scope='module')
def proxy(service, application, api_backend) -> Proxy:

@@ -215,2 +230,7 @@ params = {

@pytest.fixture(scope='module')
def backend_hits_metric(backend):
return backend.metrics.read_by(system_name=('hits.' + str(backend['id'])))
@pytest.fixture(scope='module')
def method_params(service):

@@ -240,2 +260,9 @@ suffix = get_suffix()

@pytest.fixture(scope='module')
def backend_method(backend_hits_metric, method_params):
resource = backend_hits_metric.methods.create(params=method_params)
yield resource
cleanup(resource)
def get_mapping_rule_pattern():

@@ -242,0 +269,0 @@ suffix = get_suffix()

@@ -0,3 +1,5 @@

import random
import string
import secrets
import pytest
import secrets

@@ -28,1 +30,17 @@ from tests.integration import asserts

asserts.assert_resource_params(updated_application, update_application_params)
def test_application_key_can_be_created(app_key, app_key_params):
asserts.assert_resource(app_key)
asserts.assert_resource_params(app_key, app_key_params)
def test_application_key_list(application, app_key):
keys = application.keys.list()
assert len(keys) > 0
def test_application_update_userkey(application):
new_key = "".join(random.choices(string.ascii_letters + string.digits + "-_.", k=100))
updated_application = application.update(params={"user_key": new_key})
asserts.assert_resource(updated_application)
assert updated_application["user_key"] == new_key

@@ -60,3 +60,3 @@ # pylint: disable=R0903

proxy["auth_app_id"]: self.app["application_id"],
proxy["auth_app_key"]: self.app.keys.list()["keys"][0]["key"]["value"]
proxy["auth_app_key"]: self.app.keys.list()[-1]["value"]
}

@@ -63,0 +63,0 @@

import logging
from enum import Enum
from typing import Dict, Union, List, Iterable
from urllib.parse import quote_plus

@@ -116,2 +117,9 @@ from threescale_api import auth

class BackendMethods(Methods):
def __init__(self, *args, entity_name='method', entity_collection='methods', per_page=None,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, per_page=per_page, **kwargs)
class ApplicationPlans(DefaultPlanClient):

@@ -320,3 +328,3 @@ def __init__(self, *args, entity_name='application_plan', entity_collection='plans', **kwargs):

class ApplicationKeys(DefaultClient):
def __init__(self, *args, entity_name='application', entity_collection='applications',
def __init__(self, *args, entity_name='key', entity_collection='keys',
**kwargs):

@@ -330,3 +338,27 @@ super().__init__(*args, entity_name=entity_name,

def create(self, params: dict = None, **kwargs) -> 'ApplicationKey':
"""Create a new instance of ApplicationKey. "keys" POST request
returns Application instead of newly create key.
Returns: Newly created key.
"""
super().create(params=params, **kwargs)
key = sorted(self.list(), key=lambda key: key["created_at"])[-1]
key.entity_id = quote_plus(key["value"])
return key
def list(self, **kwargs) -> List['ApplicationKey']:
"""List all entities of ApplicationKey.
There is no id in list response, so it needs to be assigned the value
to be able to work with key instance.
Args:
**kwargs: Optional parameters
Returns(List['ApplicationKey']): List of ApplicationKey resources
"""
key_list = super().list(**kwargs)
for key in key_list:
key.entity_id = quote_plus(key["value"])
return key_list
class Providers(DefaultClient):

@@ -1085,2 +1117,15 @@ def __init__(self, *args, entity_name='user', entity_collection='users', **kwargs):

class BackendMethod(Method):
def __init__(self, entity_name='system_name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
@property
def service(self) -> 'Service':
raise AttributeError("'BackendMethod' object has no attribute 'service'")
@property
def backend(self) -> 'Backend':
return self.metric.parent
class Metric(DefaultResource):

@@ -1327,3 +1372,3 @@ def __init__(self, entity_name='system_name', **kwargs):

"Application keys"
return ApplicationKeys(parent=self, instance_klass=DefaultResource)
return ApplicationKeys(parent=self, instance_klass=ApplicationKey)

@@ -1404,2 +1449,7 @@ def authobj(self, auth_mode=None, location=None):

class ApplicationKey(DefaultResource):
def __init__(self, entity_name='', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
class Account(DefaultResource):

@@ -1406,0 +1456,0 @@ def __init__(self, entity_name='org_name', **kwargs):