summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-10-17 22:01:12 +0200
committerJohn Villalovos <john@sodarock.com>2022-10-18 00:04:38 -0700
commit01d5f68295b62c0a8bd431a9cd31bf9e4e91e7d9 (patch)
tree97809862e518656fb5d4f3f0412c7c5e2de8af9b /tests
parent88c2505b05dbcfa41b9e0458d4f2ec7dcc6f8169 (diff)
downloadgitlab-01d5f68295b62c0a8bd431a9cd31bf9e4e91e7d9.tar.gz
test: enable skipping tests per GitLab plan
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/api/test_epics.py2
-rw-r--r--tests/functional/api/test_gitlab.py2
-rw-r--r--tests/functional/api/test_groups.py11
-rw-r--r--tests/functional/api/test_merge_requests.py7
-rw-r--r--tests/functional/api/test_push_rules.py1
-rw-r--r--tests/functional/conftest.py35
-rw-r--r--tests/functional/helpers.py14
7 files changed, 49 insertions, 23 deletions
diff --git a/tests/functional/api/test_epics.py b/tests/functional/api/test_epics.py
index 67b9d38..073ca2a 100644
--- a/tests/functional/api/test_epics.py
+++ b/tests/functional/api/test_epics.py
@@ -1,5 +1,7 @@
import pytest
+pytestmark = pytest.mark.gitlab_premium
+
def test_epics(group):
epic = group.epics.create({"title": "Test epic"})
diff --git a/tests/functional/api/test_gitlab.py b/tests/functional/api/test_gitlab.py
index dbc001b..55e029a 100644
--- a/tests/functional/api/test_gitlab.py
+++ b/tests/functional/api/test_gitlab.py
@@ -82,6 +82,7 @@ def test_sidekiq_compound_metrics(gl):
assert "queues" in out
+@pytest.mark.gitlab_premium
def test_geo_nodes(gl):
# Very basic geo nodes tests because we only have 1 node.
nodes = gl.geonodes.list()
@@ -91,6 +92,7 @@ def test_geo_nodes(gl):
assert isinstance(status, list)
+@pytest.mark.gitlab_premium
def test_gitlab_license(gl):
license = gl.get_license()
assert "user_limit" in license
diff --git a/tests/functional/api/test_groups.py b/tests/functional/api/test_groups.py
index e414eda..0210a32 100644
--- a/tests/functional/api/test_groups.py
+++ b/tests/functional/api/test_groups.py
@@ -138,6 +138,7 @@ def test_group_labels(group):
assert label not in group.labels.list()
+@pytest.mark.gitlab_premium
@pytest.mark.xfail(reason="/ldap/groups endpoint is gone")
def test_group_ldap_links(gl, group):
ldap_cn = "common-name"
@@ -234,9 +235,8 @@ def test_group_subgroups_projects(gl, user):
group4.delete()
-def test_group_wiki(gitlab_ee, group):
- if not gitlab_ee:
- pytest.skip("Requires GitLab EE to run")
+@pytest.mark.gitlab_premium
+def test_group_wiki(group):
content = "Group Wiki page content"
wiki = group.wikis.create({"title": "groupwikipage", "content": content})
assert wiki in group.wikis.list()
@@ -251,9 +251,8 @@ def test_group_wiki(gitlab_ee, group):
assert wiki not in group.wikis.list()
-def test_group_hooks(gitlab_ee, group):
- if not gitlab_ee:
- pytest.skip("Requires GitLab EE to run")
+@pytest.mark.gitlab_premium
+def test_group_hooks(group):
hook = group.hooks.create({"url": "http://hook.url"})
assert hook in group.hooks.list()
diff --git a/tests/functional/api/test_merge_requests.py b/tests/functional/api/test_merge_requests.py
index 18ed296..da5284e 100644
--- a/tests/functional/api/test_merge_requests.py
+++ b/tests/functional/api/test_merge_requests.py
@@ -41,11 +41,10 @@ def test_merge_requests_get(project, merge_request):
assert mr.iid == mr_iid
-def test_merge_requests_list_approver_ids(project, gitlab_ee):
+@pytest.mark.gitlab_premium
+def test_merge_requests_list_approver_ids(project):
# show https://github.com/python-gitlab/python-gitlab/issues/1698 is now
# fixed
- if not gitlab_ee:
- pytest.skip("Requires GitLab EE to run")
project.mergerequests.list(
all=True,
state="opened",
@@ -117,6 +116,7 @@ def test_merge_request_rebase(project):
assert mr.rebase()
+@pytest.mark.gitlab_premium
@pytest.mark.xfail(reason="project /approvers endpoint is gone")
def test_project_approvals(project):
mr = project.mergerequests.list()[0]
@@ -149,6 +149,7 @@ def test_project_approvals(project):
assert approval.approvers[0]["user"]["id"] == 1
+@pytest.mark.gitlab_premium
def test_project_merge_request_approval_rules(group, project):
approval_rules = project.approvalrules.list(get_all=True)
assert not approval_rules
diff --git a/tests/functional/api/test_push_rules.py b/tests/functional/api/test_push_rules.py
index 572b20d..f82a873 100644
--- a/tests/functional/api/test_push_rules.py
+++ b/tests/functional/api/test_push_rules.py
@@ -1,6 +1,7 @@
import pytest
+@pytest.mark.gitlab_premium
@pytest.mark.xfail(reason="need to relax RESTObject init for non-dict responses")
def test_project_push_rules(project):
push_rules = project.pushrules.get()
diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py
index 6acd9d5..343b608 100644
--- a/tests/functional/conftest.py
+++ b/tests/functional/conftest.py
@@ -5,6 +5,7 @@ import tempfile
import time
import uuid
from subprocess import check_output
+from typing import Optional
import pytest
import requests
@@ -66,7 +67,7 @@ def gitlab_url(docker_ip: str, gitlab_docker_port: int) -> str:
def reset_gitlab(gl: gitlab.Gitlab) -> None:
"""Delete resources (such as projects, groups, users) that shouldn't
exist."""
- if is_gitlab_ee(gl):
+ if helpers.get_gitlab_plan(gl):
logging.info("GitLab EE detected")
# NOTE(jlvillal): By default in GitLab EE it will wait 7 days before
# deleting a group. Disable delayed group/project deletion.
@@ -280,21 +281,27 @@ def gl(gitlab_config):
return instance
-def is_gitlab_ee(gl: gitlab.Gitlab) -> bool:
- """Determine if we are running with GitLab EE as opposed to GitLab CE"""
- try:
- license = gl.get_license()
- except gitlab.exceptions.GitlabLicenseError:
- license = None
- # If we have a license then we assume we are running on GitLab EE
- if license:
- return True
- return False
+@pytest.fixture(scope="session")
+def gitlab_plan(gl: gitlab.Gitlab) -> Optional[str]:
+ return helpers.get_gitlab_plan(gl)
-@pytest.fixture(scope="session")
-def gitlab_ee(gl) -> bool:
- return is_gitlab_ee(gl=gl)
+@pytest.fixture(autouse=True)
+def gitlab_premium(gitlab_plan, request) -> None:
+ if gitlab_plan in ("premium", "ultimate"):
+ return
+
+ if request.node.get_closest_marker("gitlab_ultimate"):
+ pytest.skip("Test requires GitLab Premium plan")
+
+
+@pytest.fixture(autouse=True)
+def gitlab_ultimate(gitlab_plan, request) -> None:
+ if gitlab_plan == "ultimate":
+ return
+
+ if request.node.get_closest_marker("gitlab_ultimate"):
+ pytest.skip("Test requires GitLab Ultimate plan")
@pytest.fixture(scope="session")
diff --git a/tests/functional/helpers.py b/tests/functional/helpers.py
index 972ca2f..840b71f 100644
--- a/tests/functional/helpers.py
+++ b/tests/functional/helpers.py
@@ -1,15 +1,29 @@
import logging
import time
+from typing import Optional
import pytest
+import gitlab
import gitlab.base
+import gitlab.exceptions
SLEEP_INTERVAL = 0.5
TIMEOUT = 60 # seconds before timeout will occur
MAX_ITERATIONS = int(TIMEOUT / SLEEP_INTERVAL)
+def get_gitlab_plan(gl: gitlab.Gitlab) -> Optional[str]:
+ """Determine the license available on the GitLab instance"""
+ try:
+ license = gl.get_license()
+ except gitlab.exceptions.GitlabLicenseError:
+ # Without a license we assume only Free features are available
+ return
+
+ return license["plan"]
+
+
def safe_delete(
object: gitlab.base.RESTObject,
*,