From 5935f276943108686c88d71fad26dc101fd9d3b8 Mon Sep 17 00:00:00 2001 From: shijl0925 <1213970695@qq.com> Date: Sun, 4 Aug 2024 09:51:41 +0800 Subject: [PATCH] add pytest cases --- sonarqube/rest/issues.py | 2 -- sonarqube/rest/users.py | 2 -- tests/test_ce_api.py | 15 +++++++++++++++ tests/test_issue_api.py | 1 - tests/test_project_api.py | 15 +++++++++++++++ tests/test_project_tag_api.py | 12 ++++++++++++ tests/test_rule_api.py | 15 +++++++++++++++ tests/test_user_api.py | 11 +++++++++++ tests/test_user_group_api.py | 14 ++++++++++++++ 9 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 tests/test_ce_api.py create mode 100644 tests/test_project_api.py create mode 100644 tests/test_project_tag_api.py create mode 100644 tests/test_rule_api.py create mode 100644 tests/test_user_api.py create mode 100644 tests/test_user_group_api.py diff --git a/sonarqube/rest/issues.py b/sonarqube/rest/issues.py index 5e8119c..466265c 100644 --- a/sonarqube/rest/issues.py +++ b/sonarqube/rest/issues.py @@ -14,8 +14,6 @@ class SonarQubeIssues(RestClient): SonarQube issues Operations """ - MAX_SEARCH_NUM = 100 - def get_issue(self, key): result = self.search_issues(issues=key) issues = result.get("issues", []) diff --git a/sonarqube/rest/users.py b/sonarqube/rest/users.py index 59b95a8..dc62395 100644 --- a/sonarqube/rest/users.py +++ b/sonarqube/rest/users.py @@ -13,8 +13,6 @@ class SonarQubeUsers(RestClient): SonarQube users Operations """ - MAX_SEARCH_NUM = 200 - def get_user(self, login): result = self.search_users(q=login) users = result.get("users", []) diff --git a/tests/test_ce_api.py b/tests/test_ce_api.py new file mode 100644 index 0000000..45dad1e --- /dev/null +++ b/tests/test_ce_api.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# @Author: Jialiang Shi +import logging + +logger = logging.getLogger(__name__) + + +def test_search_tasks(sonar_client): + component = "shijl0925_python-gerrit-api" + tasks = sonar_client.ce.search_tasks( + component=component, status="IN_PROGRESS,SUCCESS,FAILED,CANCELED", p=1, ps=10 + ) + + assert len(tasks.get("tasks")) diff --git a/tests/test_issue_api.py b/tests/test_issue_api.py index dccbceb..5d54618 100644 --- a/tests/test_issue_api.py +++ b/tests/test_issue_api.py @@ -13,4 +13,3 @@ def test_search_issues(sonar_client): ) assert len(res.get("issues")) - diff --git a/tests/test_project_api.py b/tests/test_project_api.py new file mode 100644 index 0000000..196cd41 --- /dev/null +++ b/tests/test_project_api.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# @Author: Jialiang Shi +import logging + +logger = logging.getLogger(__name__) + + +def test_search_projects(sonar_client): + organization = "williamsedmond90" + resp = sonar_client.projects.search_projects(organization=organization) + + projects = [item["key"] for item in resp.get("components", [])] + + assert len(projects) >= 0 diff --git a/tests/test_project_tag_api.py b/tests/test_project_tag_api.py new file mode 100644 index 0000000..6cb6962 --- /dev/null +++ b/tests/test_project_tag_api.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# @Author: Jialiang Shi +import logging + +logger = logging.getLogger(__name__) + + +def test_search_project_tags(sonar_client): + res = sonar_client.project_tags.search_project_tags() + + assert "tags" in res diff --git a/tests/test_rule_api.py b/tests/test_rule_api.py new file mode 100644 index 0000000..6fd34d6 --- /dev/null +++ b/tests/test_rule_api.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# @Author: Jialiang Shi +import logging + +logger = logging.getLogger(__name__) + + +def test_search_rules(sonar_client): + res = sonar_client.rules.search_rules( + organization="shijl0925", + languages="py" + ) + + assert "rules" in res diff --git a/tests/test_user_api.py b/tests/test_user_api.py new file mode 100644 index 0000000..06b2c14 --- /dev/null +++ b/tests/test_user_api.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# @Author: Jialiang Shi +import logging + +logger = logging.getLogger(__name__) + + +def test_search_users(sonar_client): + res = sonar_client.users.search_users() + assert "users" in res diff --git a/tests/test_user_group_api.py b/tests/test_user_group_api.py new file mode 100644 index 0000000..1ff20aa --- /dev/null +++ b/tests/test_user_group_api.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# @Author: Jialiang Shi +import logging + +logger = logging.getLogger(__name__) + + +def test_search_user_groups(sonar_client): + res = sonar_client.user_groups.search_user_groups( + organization="shijl0925", + ) + + assert "groups" in res \ No newline at end of file