Skip to content

Commit

Permalink
Merge pull request #715 from alfrunes/acceptance-fixup
Browse files Browse the repository at this point in the history
Acceptance test fixup
  • Loading branch information
merlin-northern committed May 14, 2024
2 parents 121dd82 + 08bc32b commit 9538cb5
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 962 deletions.
47 changes: 5 additions & 42 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ def explode_jwt(token):


@pytest.fixture(scope="session")
def cli():
return CliClient()
def cli(request):
service = request.config.getoption("host").split(":")[0]
return CliClient(service)


@pytest.fixture(scope="session")
def mongo():
return MongoClient("mender-mongo:27017")
def mongo(request):
return MongoClient(request.config.getoption("mongo_url"))


def mongo_cleanup(mongo):
Expand All @@ -185,13 +186,6 @@ def clean_migrated_db(clean_db, cli):
yield clean_db


@pytest.fixture(scope="function")
def tenant_foobar_clean_migrated_db(clean_db, cli):
"""Clean 'foobar' database with migrations applied. Yields pymongo.MongoClient connected to the DB."""
cli.migrate(tenant="foobar")
yield clean_db


@pytest.fixture(scope="session")
def management_api(request):
yield SimpleManagementClient(
Expand Down Expand Up @@ -231,14 +225,6 @@ def make_fake_tenant_token(tenant):
return "fake." + enc + ".fake-sig"


@pytest.fixture
def tenant_foobar(request, tenant_foobar_clean_migrated_db):
"""Fixture that sets up a tenant with ID 'foobar', on top of a clean migrated
(with tenant support) DB.
"""
return make_fake_tenant_token("foobar")


def make_devices(device_api, devcount=1, tenant_token=""):
url = device_api.auth_requests_url

Expand Down Expand Up @@ -269,29 +255,6 @@ def devices(device_api, clean_migrated_db, request):
yield make_devices(device_api, devcount)


@pytest.fixture(scope="function")
def tenant_foobar_devices(device_api, management_api, tenant_foobar, request):
"""Make unauthorized devices owned by tenant with ID 'foobar'. The fixture can
be parametrized a number of devices to make. Yields a list of tuples:
(instance of Device, instance of DevAuthorizer)
"""
handlers = [
(
"POST",
"/api/internal/v1/tenantadm/tenants/verify",
lambda _: (200, {}, '{"id": "foobar", "plan": "os"}'),
),
]
with mockserver.run_fake(get_fake_tenantadm_addr(), handlers=handlers) as fake:

if not hasattr(request, "param"):
devcount = 1
else:
devcount = int(request.param)

yield make_devices(device_api, devcount, tenant_token=tenant_foobar)


def get_fake_tenantadm_addr():
return os.environ.get("FAKE_TENANTADM_ADDR", "0.0.0.0:9999")

Expand Down
21 changes: 12 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@
# limitations under the License.
import logging


def pytest_addoption(parser):
parser.addoption("--host", action="store", default="localhost",
help="host running API")
parser.addoption(
"--host", action="store", default="deviceauth", help="host running API"
)
parser.addoption(
"--mongo-url",
default="mongodb://mongo",
help="The MongoDB URL (connection string)",
)
parser.addoption("--spec", default="../docs/internal_api.yml")
parser.addoption("--management-spec", default="../docs/management_api.yml")


def pytest_configure(config):
lvl = logging.INFO
if config.getoption("verbose"):
lvl = logging.DEBUG
logging.basicConfig(level=lvl)
# configure bravado related loggers to be less verbose
logging.getLogger('swagger_spec_validator').setLevel(logging.INFO)
logging.getLogger('bravado_core').setLevel(logging.INFO)
host = config.getoption("host")
if not host:
print("you didn't pass all of the required arguments")
print(host)
sys.exit(1)
logging.getLogger("swagger_spec_validator").setLevel(logging.INFO)
logging.getLogger("bravado_core").setLevel(logging.INFO)
35 changes: 0 additions & 35 deletions tests/docker-compose-acceptance-enterprise.yml

This file was deleted.

1 change: 1 addition & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ HOST=${HOST="mender-device-auth:8080"}
}

py.test -s --tb=short --host $HOST \
--mongo-url "mongodb://mender-mongo" \
--spec $DIR/internal_api.yml \
--management-spec $DIR/management_api.yml \
--verbose --junitxml=$DIR/results.xml \
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def find_device_by_identity(self, identity, **kwargs):
class CliClient:
exec_path = "/usr/bin/deviceauth"

def __init__(self):
def __init__(self, service="deviceauth"):
self.docker = docker.from_env()
_self = self.docker.containers.list(filters={"id": socket.gethostname()})[0]

Expand All @@ -258,7 +258,7 @@ def __init__(self):
filters={
"label": [
f"com.docker.compose.project={project}",
"com.docker.compose.service=mender-device-auth",
f"com.docker.compose.service={service}",
]
},
limit=1,
Expand Down

0 comments on commit 9538cb5

Please sign in to comment.