Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
b0bf287f7f07c727c498deaa199f2629a3aac5a9 # black 24.1.1 changes
9261b5ae4bf0d53058e6adf2e5d2544011360ba7 # Change regarding flake8 check for python 3.12
d499948418f6e1dc432dabf11f158e58d9a0b0d8 # black 25.1.0 changes
5083c776e66ae613558918342ecf9f0a368f6e99 # isort --profile black
7619a4c61d7914b16088f585e2bceacebf26ec88 # reduce new lines to one after import block
a5deb34f80c6644936cb192686ded29a292d1e8f # unpacking tuple does not need () on lhs
80bb9d6d9f11ac33d6c9287261d2ce44aadd3f87 # fix type ignore comment
1894935618597e2d219e17fa7b1fd0b0fa919515 # isort --profile black
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ ifeq ($(filter-out --store --load,$(flags)),$(flags))
endif

commit-acceptance: ## Run all linters, checks, formatters
commit-acceptance: pylint flake8 mypy all-is-package black-check
commit-acceptance: pylint flake8 mypy all-is-package black-check isort-check

pylint flake8 mypy: pipenv-dev
pipenv run $@ $(flags) testsuite

black-check: pipenv-dev
pipenv run black --check testsuite

isort-check: pipenv-dev
pipenv run isort -c --profile black testsuite

all-is-package:
@echo
@echo "Searching for dirs missing __init__.py"
Expand Down
5 changes: 4 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ types-braintree = "*"
types-stripe = "*"
types-Pillow = "*"
black = "*"
isort = "*"
# this will use system ca-bundle
pip-system-certs = "*"
# Have commented out python-language-server to make it available quickly
# for the development
#python-language-server = "*"
Expand All @@ -30,7 +33,7 @@ pytest-asyncio = "==0.21.2"
requests = "*"
dynaconf = "*"
python-keycloak = ">=4.7.3" # this fix needed: https://github.com/marcospereirampj/python-keycloak/pull/622/files
backoff = "*"
python-backoff = "*"
websocket_client = "==1.5.1"
httpx = {version = "*", extras = ["http2"]}
selenium = ">=4.0.0"
Expand Down
6 changes: 4 additions & 2 deletions scripts/junit2reportportal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ token = os.environ[args.token_variable]
reportportal = args.reportportal.rstrip("/")

auth = {"Authorization": f"Bearer {token}"}
launch_import = f"{reportportal}/api/v1/{args.project}/launch/import"
launch_import = f"{reportportal}/api/v1/plugin/{args.project}/junit/import"

print(requests.post(launch_import, files={"file": (f"{args.launch_name}.zip", stream.getbuffer(), "application/zip")}, headers=auth).text)
print(requests.post(launch_import, files={"file": (f"{args.launch_name}.zip", stream.getbuffer(), "application/zip"),
"launchImportRq": (None, f'{{"name": "{args.launch_name}"}}', "application/json")},
headers=auth).text)
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
max-line-length = 120
ignore = E203,W503

[isort]
profile = "black"

[mypy]
ignore_missing_imports = True
7 changes: 4 additions & 3 deletions testsuite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
handler.setFormatter(formatter)
logger.addHandler(handler)

from pathlib import Path # noqa
from packaging.version import Version # noqa
from weakget import weakget
from pathlib import Path

import importlib_resources as resources
from packaging.version import Version
from weakget import weakget

from testsuite.config import settings # noqa

Expand Down
23 changes: 11 additions & 12 deletions testsuite/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,34 @@
import stripe
from braintree.exceptions.request_timeout_error import RequestTimeoutError
from braintree.exceptions.service_unavailable_error import ServiceUnavailableError

from threescale_api.resources import InvoiceState


class Stripe:
"""API for Stripe"""

def __init__(self, api_key):
def __init__(self, api_key, provider_account_id):
# Due to fact that we can set up only one Stripe per 3scale and we use same api_key everytime this
# is not disruptive even if it looks like it is.
stripe.api_key = api_key
self.provider_account_id = provider_account_id

@staticmethod
@backoff.on_predicate(backoff.fibo, lambda x: x == [], max_tries=10, jitter=None)
def read_charge(customer):
"""Retrieves the details of the charge"""
return stripe.Charge.search(query=f"customer:'{customer['id']}'").get("data")
return stripe.Charge.search(query=f"customer:'{customer['id']}'").data

@staticmethod
@backoff.on_exception(backoff.expo, IndexError, max_tries=4, jitter=None)
def read_customer_by_account(account):
def read_customer_by_account(self, account):
"""
Read Stripe customer.
Different 3scale deployments can have customers with the same id, which is reflected to the
`3scale_account_reference` Stripe Customer variable. This method reads just the last one.
"""
return stripe.Customer.search(
query=f"metadata['3scale_account_reference']:'3scale-2-{str(account.entity_id)}'"
).get("data")[0]
query=f"metadata['3scale_account_reference']:'3scale-{self.provider_account_id}-{str(account.entity_id)}'"
).data[0]

def assert_payment(self, invoice, account):
"""Compare 3scale and Stripe invoices"""
Expand All @@ -51,7 +50,7 @@ def assert_payment(self, invoice, account):
class Braintree:
"""API for braintree"""

def __init__(self, merchant_id, public_key, private_key):
def __init__(self, merchant_id, public_key, private_key, provider_account_id):
self.gateway = braintree.BraintreeGateway(
braintree.Configuration(
environment=braintree.Environment.Sandbox,
Expand All @@ -60,6 +59,7 @@ def __init__(self, merchant_id, public_key, private_key):
private_key=private_key,
)
)
self.provider_account_id = provider_account_id

@backoff.on_exception(backoff.fibo, (ServiceUnavailableError, RequestTimeoutError), max_tries=8, jitter=None)
def get_customer_transactions(self, account):
Expand All @@ -76,10 +76,9 @@ def merchant_currency(self):
merchant_accounts = list(self.gateway.merchant_account.all().merchant_accounts.items)
return [x for x in merchant_accounts if x.default is True][0].currency_iso_code

@staticmethod
def customer_id(account):
"""Returns Braintree customer id. It is in a form `3scale-2-{account_id}-1`"""
return f"3scale-2-{account.entity_id}-1"
def customer_id(self, account):
"""Returns Braintree customer id. It is in a form `3scale-{provider_id}-{account_id}-1`"""
return f"3scale-{self.provider_account_id}-{account.entity_id}-1"

@staticmethod
def _assert_transaction(invoice, transaction):
Expand Down
2 changes: 1 addition & 1 deletion testsuite/capabilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import enum
from typing import Set, Callable, Any, Tuple, List
from typing import Any, Callable, List, Set, Tuple

# Users should have access only to these public methods/decorators
__all__ = ["CapabilityRegistry", "Capability"]
Expand Down
4 changes: 2 additions & 2 deletions testsuite/capabilities/providers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""This module is where most of the capability providers should be to not have them scattered around"""

from testsuite import gateways
from testsuite.capabilities import CapabilityRegistry, Capability
from testsuite.configuration import openshift
from testsuite.capabilities import Capability, CapabilityRegistry
from testsuite.config import settings
from testsuite.configuration import openshift


def gateway_capabilities():
Expand Down
2 changes: 1 addition & 1 deletion testsuite/certificates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Collection of classes for working with different ssl certificate tools."""

from abc import ABC, abstractmethod
from typing import List, Optional, Tuple, Dict
from typing import Dict, List, Optional, Tuple

from testsuite.certificates.persist import TmpFilePersist

Expand Down
9 changes: 7 additions & 2 deletions testsuite/certificates/cfssl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import json
import os
import subprocess
from typing import Optional, List, Tuple, Dict, Any
from typing import Any, Dict, List, Optional, Tuple

import importlib_resources as resources

from testsuite.certificates import KeyProvider, SigningProvider, Certificate, UnsignedKey
from testsuite.certificates import (
Certificate,
KeyProvider,
SigningProvider,
UnsignedKey,
)
from testsuite.certificates.cfssl import CFSSLException


Expand Down
2 changes: 1 addition & 1 deletion testsuite/certificates/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABC
from typing import Dict

from testsuite.certificates import CertificateStore, Certificate
from testsuite.certificates import Certificate, CertificateStore


def _persist(path, name: str, ext: str, content: str):
Expand Down
4 changes: 2 additions & 2 deletions testsuite/configuration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Module responsible for processing configuration"""

import inspect
from typing import Dict, Any, Mapping
from typing import Any, Dict, Mapping

from weakget import weakget

from testsuite.config import settings
from testsuite.capabilities import Singleton
from testsuite.config import settings
from testsuite.openshift.client import OpenShiftClient


Expand Down
6 changes: 3 additions & 3 deletions testsuite/dynaconf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
load() is doubled.
"""

from pathlib import Path
import logging
import os
import os.path
import re
from pathlib import Path

from packaging.version import Version, InvalidVersion
from openshift_client import OpenShiftPythonException
from packaging.version import InvalidVersion, Version
from weakget import weakget

from openshift_client import OpenShiftPythonException
from testsuite.openshift.client import OpenShiftClient

log = logging.getLogger(__name__) # pylint: disable=invalid-name
Expand Down
2 changes: 1 addition & 1 deletion testsuite/gateway_logs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Pytest plugin for collecting gateway logs"""

from datetime import datetime, timezone
import logging
from datetime import datetime, timezone

import pytest
from _pytest.outcomes import Skipped
Expand Down
7 changes: 3 additions & 4 deletions testsuite/gateways/apicast/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"""Module containing all APIcast gateways"""

import logging
from abc import ABC, abstractmethod
from datetime import datetime
from typing import Optional, List, Dict, Tuple
import logging
from typing import Dict, List, Optional, Tuple

from openshift_client import OpenShiftPythonException

from threescale_api.resources import Service

from testsuite import utils
from testsuite.capabilities import Capability
from testsuite.gateways import AbstractGateway
from testsuite import utils
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift.deployments import Deployment
from testsuite.openshift.env import Properties
Expand Down
3 changes: 1 addition & 2 deletions testsuite/gateways/apicast/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import re
import time
from typing import Dict, Callable, Pattern, Any, Match, Union
from typing import Any, Callable, Dict, Match, Pattern, Union

from openshift_client import OpenShiftPythonException

from weakget import weakget

from testsuite import settings
Expand Down
4 changes: 2 additions & 2 deletions testsuite/gateways/apicast/selfmanaged.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import inspect
import logging
from typing import Union, Type
from typing import Type, Union

from weakget import weakget

from testsuite.capabilities import Capability
from testsuite.gateways.gateways import Gateway, new_gateway
from testsuite.gateways.apicast import AbstractApicast, OpenshiftApicast
from testsuite.gateways.gateways import Gateway, new_gateway
from testsuite.openshift.client import OpenShiftClient

LOGGER = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion testsuite/gateways/apicast/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import TYPE_CHECKING

import backoff

from openshift_client import OpenShiftPythonException

from testsuite.capabilities import Capability
Expand Down
3 changes: 2 additions & 1 deletion testsuite/gateways/apicast/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import importlib_resources as resources

from testsuite.openshift.objects import SecretTypes
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift.objects import SecretTypes

from . import OpenshiftApicast

LOGGER = logging.getLogger(__name__)
Expand Down
7 changes: 4 additions & 3 deletions testsuite/gateways/apicast/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from threescale_api.resources import Application, Service

from testsuite.openshift.objects import Routes, SecretKinds
from . import AbstractApicast, OpenshiftApicast
from .selfmanaged import SelfManagedApicast
from .. import new_gateway

from ... import settings
from ...capabilities import Capability
from ...certificates import Certificate
from ...openshift.env import Properties
from .. import new_gateway
from . import AbstractApicast, OpenshiftApicast
from .selfmanaged import SelfManagedApicast

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion testsuite/gateways/service_mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Dict

from threescale_api.resources import Service, Application
from threescale_api.resources import Application, Service

from testsuite.capabilities import Capability
from testsuite.gateways.gateways import AbstractGateway
Expand Down
2 changes: 1 addition & 1 deletion testsuite/gateways/wasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from urllib.parse import urlparse

import importlib_resources as resources
from threescale_api.resources import Service, Application
from threescale_api.resources import Application, Service

from testsuite.capabilities import Capability
from testsuite.gateways import AbstractGateway
Expand Down
16 changes: 12 additions & 4 deletions testsuite/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import functools
import logging
from typing import Iterable, Generator
from typing import Generator, Iterable

from httpx import Client, Request, Response, URL, Auth, create_ssl_context, USE_CLIENT_DEFAULT
from threescale_api.resources import Application, Service
from threescale_api.utils import response2str, request2curl
import backoff
import httpx
from httpx import (
URL,
USE_CLIENT_DEFAULT,
Auth,
Client,
Request,
Response,
create_ssl_context,
)
from threescale_api.resources import Application, Service
from threescale_api.utils import request2curl, response2str

from testsuite.lifecycle_hook import LifecycleHook

Expand Down
3 changes: 2 additions & 1 deletion testsuite/jaeger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from string import Template
from urllib.parse import urlparse

import backoff
import requests
import importlib_resources as resources
import requests


class Jaeger:
Expand Down
Loading
Loading