From 9e8f69c5aef7165cda63f48cf47c0dff575e28fc Mon Sep 17 00:00:00 2001 From: studioj <22102283+studioj@users.noreply.github.com> Date: Tue, 26 Dec 2023 20:22:54 +0000 Subject: [PATCH 01/14] fix: small fix for dev docker --- .devcontainer/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9b8963240..912b3cece 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,9 +1,9 @@ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/ubuntu/.devcontainer/base.Dockerfile # [Choice] Ubuntu version (use hirsuite or bionic on local arm64/Apple Silicon): hirsute, focal, bionic -ARG VARIANT="hirsute" +ARG VARIANT="focal" FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} # [Optional] Uncomment this section to install additional OS packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends \ +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends libkrb5-dev From 7b39544887df5e9380c45aad89698ed3a8ffc201 Mon Sep 17 00:00:00 2001 From: studioj <22102283+studioj@users.noreply.github.com> Date: Tue, 26 Dec 2023 21:13:06 +0000 Subject: [PATCH 02/14] fix: small sleep to stabilise project creation in tests --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index e493e7c30..df7d11d29 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ import re import string import sys +import time import unittest from time import sleep from typing import Any @@ -259,6 +260,7 @@ def _create_project( except JIRAError as e: if "A project with that name already exists" not in str(e): raise e + time.sleep(1) return self.jira_admin.project(project_key).id def create_some_data(self): From f9628a04da9fca521dc7a9944776192277516587 Mon Sep 17 00:00:00 2001 From: adehad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:01:48 +0000 Subject: [PATCH 03/14] use ubuntu-22.04 --- .devcontainer/Dockerfile | 8 ++++---- .devcontainer/devcontainer.json | 9 +++------ .devcontainer/post_create.sh | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 912b3cece..d6dab3556 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,8 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/ubuntu/.devcontainer/base.Dockerfile +# See here for image contents: https://github.com/devcontainers/images/blob/main/src/base-ubuntu/.devcontainer/Dockerfile -# [Choice] Ubuntu version (use hirsuite or bionic on local arm64/Apple Silicon): hirsute, focal, bionic -ARG VARIANT="focal" -FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} +# [Choice] Ubuntu version: https://github.com/devcontainers/images/tree/main/src/base-ubuntu +ARG VARIANT="ubuntu-22.04" +FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT} # [Optional] Uncomment this section to install additional OS packages. RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index dab6df3b5..3261f36c7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,13 +1,12 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/ubuntu +// https://mcr.microsoft.com/en-us/product/devcontainers/base/about { "name": "Ubuntu", "build": { "dockerfile": "Dockerfile", - // Update 'VARIANT' to pick an Ubuntu version: hirsute, focal, bionic - // Use hirsute or bionic on local arm64/Apple Silicon. + // Update 'VARIANT' to pick an Ubuntu version "args": { - "VARIANT": "focal" + "VARIANT": "ubuntu-22.04" } }, // Set *default* container specific settings.json values on container create. @@ -30,7 +29,6 @@ "color": "#ff000065" }, ], - "python.defaultInterpreterPath": "/usr/local/python/bin/python", "mypy-type-checker.args": [ // "--follow-imports=silent", @@ -84,7 +82,6 @@ ], } }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [ // The jira server instance we run via docker is exposed on: diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh index 5882eb626..aa277f83d 100755 --- a/.devcontainer/post_create.sh +++ b/.devcontainer/post_create.sh @@ -31,4 +31,4 @@ else fi # Install package in editable mode with test dependencies -pip install -e .[test] +pip install -e .[opt,test] From 52443a6ad331ab6fc10cf7e8bb09071b92b4abfb Mon Sep 17 00:00:00 2001 From: studioj <22102283+studioj@users.noreply.github.com> Date: Tue, 26 Dec 2023 21:13:06 +0000 Subject: [PATCH 04/14] fix: aim to stabilise project creation in tests --- tests/conftest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index df7d11d29..664f1d997 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ import getpass import hashlib +import json import logging import os import random @@ -105,10 +106,11 @@ def hashify(some_string, max_len=8): def get_unique_project_name(): user = re.sub("[^A-Z_]", "", getpass.getuser().upper()) - if "GITHUB_ACTION" in os.environ and "GITHUB_RUN_NUMBER" in os.environ: + if os.getenv("GITHUB_CONTEXT"): + run_number = json.loads(os.getenv("GITHUB_CONTEXT")).get("run_number") # please note that user underline (_) is not supported by # Jira even if it is documented as supported. - return "GH" + hashify(user + os.environ["GITHUB_RUN_NUMBER"]) + return "GH" + hashify(user + run_number) identifier = ( user + chr(ord("A") + sys.version_info[0]) + chr(ord("A") + sys.version_info[1]) ) From c33778d8c72c23ada37e232613f7e053fad03ef3 Mon Sep 17 00:00:00 2001 From: studioj <22102283+studioj@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:12:13 +0000 Subject: [PATCH 05/14] fix: bump dev container to jammy --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d6dab3556..ad2336bc2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,7 @@ # See here for image contents: https://github.com/devcontainers/images/blob/main/src/base-ubuntu/.devcontainer/Dockerfile # [Choice] Ubuntu version: https://github.com/devcontainers/images/tree/main/src/base-ubuntu -ARG VARIANT="ubuntu-22.04" +ARG VARIANT="jammy" FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT} # [Optional] Uncomment this section to install additional OS packages. From 35c745a1c04e2f45032a819f5fdf3cc0613c9f49 Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:55:48 +0000 Subject: [PATCH 06/14] also prevent undo in pytest style tests --- tests/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 2f088b1e0..b017891af 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -37,7 +37,7 @@ def slug(request, cl_admin): def remove_by_slug(): try: - cl_admin.delete_project(slug) + cl_admin.delete_project(slug, enable_undo=False) except (ValueError, JIRAError): # Some tests have project already removed, so we stay silent pass From 9bd6319ce0061b8811dbfd4129849b6fbc3437a4 Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:56:07 +0000 Subject: [PATCH 07/14] install cli by default so tests work --- .devcontainer/post_create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh index aa277f83d..272b6ba23 100755 --- a/.devcontainer/post_create.sh +++ b/.devcontainer/post_create.sh @@ -31,4 +31,4 @@ else fi # Install package in editable mode with test dependencies -pip install -e .[opt,test] +pip install -e .[cli,opt,test] From ad4e45b8e9d509c158ee5fdf39eea44d5d488086 Mon Sep 17 00:00:00 2001 From: studioj <22102283+studioj@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:07:00 +0100 Subject: [PATCH 08/14] Update .devcontainer/Dockerfile Co-authored-by: Adel Haddad <26027314+adehad@users.noreply.github.com> --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ad2336bc2..d6dab3556 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,7 @@ # See here for image contents: https://github.com/devcontainers/images/blob/main/src/base-ubuntu/.devcontainer/Dockerfile # [Choice] Ubuntu version: https://github.com/devcontainers/images/tree/main/src/base-ubuntu -ARG VARIANT="jammy" +ARG VARIANT="ubuntu-22.04" FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT} # [Optional] Uncomment this section to install additional OS packages. From 98f59998ea1afa80a09dab235ba6ced1c27443f3 Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:18:24 +0000 Subject: [PATCH 09/14] allow GITHUB env vars --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 2f6b49ae4..b398da265 100644 --- a/tox.ini +++ b/tox.ini @@ -57,6 +57,7 @@ passenv = REQUESTS_CA_BUNDLE SSL_CERT_FILE TWINE_* + GITHUB_* XDG_CACHE_HOME # For Windows users, getpass.get_user() needs USERNAME USERNAME From c279b5881497ad55ef71004a3e0a00d79c85569a Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:50:06 +0000 Subject: [PATCH 10/14] Use default CI vars --- tests/conftest.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 664f1d997..97ce650d2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,6 @@ import getpass import hashlib -import json import logging import os import random @@ -106,15 +105,14 @@ def hashify(some_string, max_len=8): def get_unique_project_name(): user = re.sub("[^A-Z_]", "", getpass.getuser().upper()) - if os.getenv("GITHUB_CONTEXT"): - run_number = json.loads(os.getenv("GITHUB_CONTEXT")).get("run_number") + if "GITHUB_ACTION" in os.environ and "GITHUB_RUN_NUMBER" in os.environ: + run_number = os.environ["GITHUB_RUN_NUMBER"] # please note that user underline (_) is not supported by # Jira even if it is documented as supported. - return "GH" + hashify(user + run_number) - identifier = ( - user + chr(ord("A") + sys.version_info[0]) + chr(ord("A") + sys.version_info[1]) - ) - return "Z" + hashify(identifier) + return f"CI{hashify(f'{user}{run_number}')}" + sep = chr(ord("A")) + identifier = f"{user}{sep}{sys.version_info[0]}{sep}{sys.version_info[1]}" + return f"Z{hashify(identifier)}" class JiraTestManager: From 20ba1feb45cb0348c5646becfe079f2406812550 Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:49:20 +0000 Subject: [PATCH 11/14] use shorter prefix --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 97ce650d2..b82b6d217 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -109,7 +109,7 @@ def get_unique_project_name(): run_number = os.environ["GITHUB_RUN_NUMBER"] # please note that user underline (_) is not supported by # Jira even if it is documented as supported. - return f"CI{hashify(f'{user}{run_number}')}" + return f"C{hashify(f'{user}{run_number}')}" sep = chr(ord("A")) identifier = f"{user}{sep}{sys.version_info[0]}{sep}{sys.version_info[1]}" return f"Z{hashify(identifier)}" From dcf86af11cf6d0857b57da5c389466c26bbff12f Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:50:29 +0000 Subject: [PATCH 12/14] use CI prefix but shorten hash --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b82b6d217..5cbee6af4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -100,7 +100,7 @@ def rndpassword(): def hashify(some_string, max_len=8): - return hashlib.sha256(some_string.encode("utf-8")).hexdigest()[:8].upper() + return hashlib.sha256(some_string.encode("utf-8")).hexdigest()[:max_len].upper() def get_unique_project_name(): @@ -109,7 +109,7 @@ def get_unique_project_name(): run_number = os.environ["GITHUB_RUN_NUMBER"] # please note that user underline (_) is not supported by # Jira even if it is documented as supported. - return f"C{hashify(f'{user}{run_number}')}" + return f"CI{hashify(f'{user}{run_number}',max_len=7)}" sep = chr(ord("A")) identifier = f"{user}{sep}{sys.version_info[0]}{sep}{sys.version_info[1]}" return f"Z{hashify(identifier)}" From 46beda376fb9be21d3476653de9628cdabce4d09 Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:10:48 +0000 Subject: [PATCH 13/14] clean up after tests more reliably --- tests/conftest.py | 15 +++++++++++++++ tests/test_client.py | 20 +++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5cbee6af4..013bd3cbc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,7 @@ import sys import time import unittest +import weakref from time import sleep from typing import Any @@ -72,6 +73,12 @@ def setUp(self) -> None: self.user_normal = self.test_manager.user_normal # use this user where possible self.project_b = self.test_manager.project_b self.project_a = self.test_manager.project_a + weakref.finalize( + self, + self._cleanup, + test_manager=self.test_manager, + projects=(self.project_a, self.project_b), + ) @property def identifying_user_property(self) -> str: @@ -83,6 +90,14 @@ def is_jira_cloud_ci(self) -> bool: """is running on Jira Cloud""" return self.test_manager._cloud_ci + def _cleanup(self, test_manager: JiraTestManager, projects: list[str]) -> None: + """This is called when the object is set to be garbage collected.""" + for proj in projects: + try: + test_manager._remove_project(proj) + except Exception: + LOGGER.exception(f"Failed to remove project {proj}") + def rndstr(): return "".join(random.sample(string.ascii_lowercase, 6)) diff --git a/tests/test_client.py b/tests/test_client.py index b017891af..ddfb278fe 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -32,18 +32,9 @@ def cl_normal(test_manager: JiraTestManager) -> jira.client.JIRA: @pytest.fixture(scope="function") -def slug(request, cl_admin): +def slug(request: pytest.FixtureRequest, cl_admin: jira.client.JIRA): """Project slug.""" - - def remove_by_slug(): - try: - cl_admin.delete_project(slug, enable_undo=False) - except (ValueError, JIRAError): - # Some tests have project already removed, so we stay silent - pass - slug = get_unique_project_name() - project_name = f"Test user={getpass.getuser()} key={slug} A" try: @@ -52,9 +43,12 @@ def remove_by_slug(): proj = cl_admin.create_project(slug, project_name) assert proj - request.addfinalizer(remove_by_slug) - - return slug + yield slug + try: + cl_admin.delete_project(slug, enable_undo=False) + except (ValueError, JIRAError): + # Some tests have project already removed, so we stay silent + pass def test_delete_project(cl_admin, cl_normal, slug): From d3d4037dbb4cd3cc7755787339452ed2091b07c3 Mon Sep 17 00:00:00 2001 From: Adel Haddad <26027314+adehad@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:34:41 +0000 Subject: [PATCH 14/14] mypy fix --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 013bd3cbc..140cb07d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,7 +77,7 @@ def setUp(self) -> None: self, self._cleanup, test_manager=self.test_manager, - projects=(self.project_a, self.project_b), + projects=[self.project_a, self.project_b], ) @property