diff --git a/docs/source/config-file.rst b/docs/source/config-file.rst index 37de6c7..f83a48d 100644 --- a/docs/source/config-file.rst +++ b/docs/source/config-file.rst @@ -47,26 +47,6 @@ The config file is made up of multiple parts * This is the default JIRA instance to be used if none is provided in the project. -.. code-block:: python - - 'confluence_statistics': False - -* Adds the ability to post statistics to confluence. See note below. - -.. note:: Optional: Confluence Statistic Support - - a. What is it? If :code:`confluence_statistics` is set to `True` in the config file (default `False`) you can set up a Confluence page and space to post statistic too (i.e. how many comments synced etc) - - b. Set up the following variables: - 1. :code:`CONFLUENCE_SPACE` :: The Confluence space we're posting too - 2. :code:`CONFLUENCE_PAGE_TITLE` :: The Confluence page we're posting too - 3. :code:`CONFLUENCE_URL` :: The Confluence URL - 4. :code:`CONFLUENCE_USERNAME` :: Confluence username data - 5. :code:`CONFLUENCE_PASSWORD` :: Confluence password data - - c. Create the related confluence page and space. Make sure to add the template (use :code:`sync2jira/confluence_stat.jinja` and replace the JINJA code with 0's - - .. code-block:: python 'jira': { diff --git a/docs/source/confluence_client.rst b/docs/source/confluence_client.rst deleted file mode 100644 index 7e9734f..0000000 --- a/docs/source/confluence_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -Confluence Client -================= - -.. automodule:: sync2jira.confluence_client - :members: - :private-members: - - diff --git a/docs/source/index.rst b/docs/source/index.rst index 8976992..a100e50 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -29,5 +29,4 @@ Sync2Jira documentation downstream_pr downstream_issue intermediary - mailer - confluence_client \ No newline at end of file + mailer \ No newline at end of file diff --git a/docs/source/sync_page.rst b/docs/source/sync_page.rst index 0e17bf8..7308e55 100644 --- a/docs/source/sync_page.rst +++ b/docs/source/sync_page.rst @@ -9,13 +9,12 @@ Related to OpenShift: 2. :code:`DEFAULT_SERVER` :: Default server to use for mailing 3. :code:`DEFAULT_FROM` :: Default from to use for mailing 4. :code:`USER` :: JIRA username - 5. :code:`CONFLUENCE_SPACE` :: Confluence space (should be set to "mock_confluence_space" as we don't want any confluence syncing) - 6. :code:`INITIALIZE` :: True/False Initialize our repos on startup (Should be set to "0") - 7. :code:`IMAGE_URL` :: Image URL:TAG to pull from - 8. :code:`JIRA_PNT_PASS` :: PNT password in base64 - 9. :code:`JIRA_OMEGAPRIME_PASS` :: Omegaprime password in base64 - 10. :code:`GITHUB_TOKEN` :: GitHub token in base64 - 11. :code:`PAAS_DOMAIN` :: Domain to use for the service + 5. :code:`INITIALIZE` :: True/False Initialize our repos on startup (Should be set to "0") + 6. :code:`IMAGE_URL` :: Image URL:TAG to pull from + 7. :code:`JIRA_PNT_PASS` :: PNT password in base64 + 8. :code:`JIRA_OMEGAPRIME_PASS` :: Omegaprime password in base64 + 9. :code:`GITHUB_TOKEN` :: GitHub token in base64 + 10. :code:`PAAS_DOMAIN` :: Domain to use for the service You can also use the OpenShift template to quickly deploy this service (it can be found in the repo under :code:`openshift/sync2jira-sync-page-template.yaml`) diff --git a/sync2jira/confluence_client.py b/sync2jira/confluence_client.py deleted file mode 100644 index 376975a..0000000 --- a/sync2jira/confluence_client.py +++ /dev/null @@ -1,245 +0,0 @@ -#!/usr/bin/python3 -""" -This script acts as a client to confluence, connects to confluence and create -pages -""" -import logging -import os -import re -import requests -from requests.auth import HTTPBasicAuth -import jinja2 -import datetime - -# Global Variables -log = logging.getLogger('sync2jira') - - -class ConfluenceClient: - - """ A conflence component used to connect to confluence and perform - confluence related tasks - """ - - def __init__( - self, - confluence_space=os.environ.get("CONFLUENCE_SPACE"), - confluence_page_title=os.environ.get("CONFLUENCE_PAGE_TITLE"), - confluence_url=os.environ.get("CONFLUENCE_URL"), - username=os.environ.get("CONFLUENCE_USERNAME"), - password=os.environ.get("CONFLUENCE_PASSWORD"), - auth_type="basic", - ): - """ Returns confluence client object - :param string confluence_space : space to be used in confluence - :param string confluence_page_title : Title of page to be created in - confluence - :param string confluence_url : url to connect confluence - :param string username : optional username for basic auth - :param string password : optional password for basic auth - :param string auth_type : indicate auth scheme (basic/kerberos) - """ - self.confluence_space = confluence_space - self.confluence_page_title = confluence_page_title - self.confluence_url = confluence_url - self.confluence_rest_url = self.confluence_url + "/rest/api/content/" - self.username = username - self.password = password - self.authtype = auth_type - self.update_stat = False - self._req_kwargs = None - - # Find our page ID and save it - resp = self.find_page() - if not resp: - raise ValueError("Invalid page name") - self.page_id = resp - - def update_stat_value(self, new_value): - """ Update the 'update_stat' attribute. - :param Bool new_value: Bool value - """ - self.update_stat = new_value - - @property - def req_kwargs(self): - """ Set the key-word arguments for python-requests depending on the - auth type. This code should run on demand exactly once, which is - why it is a property. - :return dict _req_kwargs: dict with the right options to pass in - """ - if self._req_kwargs is None: - if self.authtype == "basic": - self._req_kwargs = {"auth": self.get_auth_object()} - return self._req_kwargs - - def update_stat_page(self, confluence_data): - """ - Updates the statistic page with more data - :param dict confluence_data: Variable amount of new data - """ - try: - # Get the HTML to update - page_info = self.get_page_info(self.page_id) - page_html = page_info['body']['storage']['value'] - # Maintain and update our final data - confluence_data_update = { - 'Created Issues': 0, - 'Descriptions': 0, - 'Comments': 0, - 'Reporters': 0, - 'Status': 0, - 'Assignees': 0, - 'Transitions': 0, - 'Title': 0, - 'Tags': 0, - 'FixVersion': 0, - 'Misc. Fields': 0, - 'Total': 0 - } - confluence_data_times = { - 'Created Issues': 60, - 'Descriptions': 30, - 'Comments': 30, - 'Reporters': 30, - 'Assignees': 15, - 'Status': 30, - 'Transitions': 30, - 'Title': 15, - 'Tags': 10, - 'FixVersion': 10, - 'Misc. Fields': 15, - } - # Use these HTML patterns to search for previous values - confluence_html_patterns = { - 'Created Issues': "Created Issues", - 'Descriptions': "Descriptions", - 'Comments': "Comments", - 'Reporters': "Reporters", - 'Assignees': "Assignees", - 'Status': "Status", - 'Transitions': "Transitions", - 'Title': "Titles", - 'Tags': "Tags", - 'FixVersion': "Fix Version", - 'Misc. Fields': "Misc. Fields", - } - # Update all our data - total = 0 - for topic, html in confluence_html_patterns.items(): - # Search for previous data - try: - ret = re.search(html, page_html) - start_index = ret.span()[1] - new_val = "" - while page_html[start_index] != "<": - new_val += page_html[start_index] - start_index += 1 - confluence_data_update[topic] = int(new_val) - total += int(new_val) - except AttributeError: - log.warning(f"Confluence failed on parsing {topic}") - total += 0 - confluence_data_update[topic] = 0 - - # Now add new data - for topic in confluence_html_patterns.keys(): - if topic in confluence_data: - confluence_data_update[topic] += confluence_data[topic] - total += confluence_data[topic] - confluence_data_update["Total"] = total - - # Calculate Total Time - total_time = 0 - for topic in confluence_data_times.keys(): - total_time += confluence_data_update[topic] * confluence_data_times[topic] - total_time = datetime.timedelta(seconds=total_time) - confluence_data_update["Total Time"] = str(total_time) + " (HR:MIN:SEC)" - - # Build our updated HTML page - templateLoader = jinja2.FileSystemLoader( - searchpath='usr/local/src/sync2jira/sync2jira/') - templateEnv = jinja2.Environment(loader=templateLoader) - template = templateEnv.get_template('confluence_stat.jinja') - html_text = template.render(confluence_data=confluence_data_update) - - # Finally update our page - if html_text.replace(" ", "") != page_html.replace(" ", ""): - self.update_page(self.page_id, html_text) - except: # noqa E722 - log.exception("Something went wrong updating confluence!") - - def find_page(self): - """ finds the page with confluence_page_title in confluence_space - return string page_id : id of the page if found, otherwise None - """ - search_url = ( - self.confluence_url - + "/rest/api/content/search?cql=title='" - + self.confluence_page_title - + "' and " - + "space=" - + self.confluence_space - ) - resp = requests.get(search_url, **self.req_kwargs) - if len(resp.json()["results"]) > 0: - return resp.json()["results"][0].get("id", None) - else: - return None - - def get_page_info(self, page_id): - """Gives information like ancestors,version of a page - :param string page_id: id of the confluence page - :return json conf_resp: response from the confluence - """ - conf_rest_url = ( - self.confluence_url - + "/rest/api/content/" - + page_id - + "?expand=ancestors,version,body.storage" - ) - resp = requests.get(conf_rest_url, **self.req_kwargs) - return resp.json() - - def update_page(self, page_id, html_str): - """ - Updates the page with id page_id - :param string page_id: id of the page - :param string html_str : html_str content of the page - :return json conf_resp: response from the confluence - """ - rest_url = self.confluence_rest_url + page_id - info = self.get_page_info(page_id) - updated_page_version = int(info["version"]["number"] + 1) - - data = { - "id": str(page_id), - "type": "page", - "title": info["title"], - "version": {"number": updated_page_version}, - "body": {"storage": {"representation": "storage", "value": html_str}}, - } - resp = requests.put(rest_url, json=data, **self.req_kwargs) - if not resp.ok: - log.error("Error updating confluence page!\nConfluence response: %s\n", resp.json()) - - return resp.json() - - def get_auth_object(self): - """Returns Auth object based on auth type - :return : Auth Object - """ - if self.authtype == "basic": - return HTTPBasicAuth(self.username, self.password) - - -if os.environ.get('CONFLUENCE_SPACE') != 'mock_confluence_space': - confluence_client = ConfluenceClient() -else: - # Else we are testing, and create a mock_client - class mock_confluence_client(object): - mock_data = False - update_stat = False - def update_stat_value(self, *args, **kwargs): return - def update_stat_page(self, *args, **kwargs): return - confluence_client = mock_confluence_client() diff --git a/sync2jira/confluence_stat.jinja b/sync2jira/confluence_stat.jinja deleted file mode 100644 index 9c9d55b..0000000 --- a/sync2jira/confluence_stat.jinja +++ /dev/null @@ -1,55 +0,0 @@ -

-
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Type of SyncNumber of SyncsAvg. Time (Seconds)
Created Issues{{ confluence_data['Created Issues'] }}60
Descriptions{{ confluence_data['Descriptions'] }}30
Comments{{ confluence_data['Comments'] }}30
Reporters{{ confluence_data['Reporters'] }}30
Assignees{{ confluence_data['Assignees'] }}15
Status{{ confluence_data['Status'] }}30
Transitions{{ confluence_data['Transitions'] }}30
Titles{{ confluence_data['Title'] }}15
Tags{{ confluence_data['Tags'] }}5
Fix Version{{ confluence_data['FixVersion'] }}5
Misc. Fields{{ confluence_data['Misc. Fields'] }}15
Total{{ confluence_data['Total'] }}{{ confluence_data['Total Time'] }}
-

-
-

\ No newline at end of file diff --git a/sync2jira/downstream_issue.py b/sync2jira/downstream_issue.py index 4e4e4cf..a93d1dc 100644 --- a/sync2jira/downstream_issue.py +++ b/sync2jira/downstream_issue.py @@ -34,7 +34,6 @@ # Local Modules from sync2jira.intermediary import Issue, PR from sync2jira.mailer import send_mail -from sync2jira.confluence_client import confluence_client # The date the service was upgraded # This is used to ensure legacy comments are not touched @@ -542,9 +541,6 @@ def change_status(client, downstream, status, issue): try: client.transition_issue(downstream, id) log.info('Updated downstream to %s status for issue %s' % (status, issue.title)) - if confluence_client.update_stat: - confluence_data = {'Transition': 1} - confluence_client.update_stat_page(confluence_data) except JIRAError: log.error('Updating downstream issue failed for %s: %s' % (status, issue.title)) else: @@ -570,12 +566,9 @@ def _create_jira_issue(client, issue, config): custom_fields = issue.downstream.get('custom_fields', {}) default_type = issue.downstream.get('type', "Bug") - confluence_data = {'Misc. Fields': 0, 'Created Issues': 1} - # Build the description of the JIRA issue if 'description' in issue.downstream.get('issue_updates', {}): description = "Upstream description: {quote}%s{quote}" % issue.content - confluence_data['Descriptions'] = 1 else: description = '' @@ -583,7 +576,6 @@ def _create_jira_issue(client, issue, config): # Just add it to the top of the description formatted_status = "Upstream issue status: %s" % issue.status description = formatted_status + '\n' + description - confluence_data['Status'] = 1 if issue.reporter: # Add to the description @@ -592,7 +584,6 @@ def _create_jira_issue(client, issue, config): issue.reporter['fullname'], description ) - confluence_data['Reporters'] = 1 # Add the url if requested if 'url' in issue.downstream.get('issue_updates', {}): @@ -638,13 +629,11 @@ def _create_jira_issue(client, issue, config): downstream.update({custom_field: issue.downstream.get('epic-link')}) except JIRAError: client.add_comment(downstream, f"Error adding Epic-Link: {issue.downstream.get('epic-link')}") - confluence_data['Misc. Fields'] += 1 if issue.downstream.get('qa-contact'): # Try to get and update the custom field custom_field = name_map.get('QA Contact', None) if custom_field: downstream.update({custom_field: issue.downstream.get('qa-contact')}) - confluence_data['Misc. Fields'] += 1 if issue.downstream.get('EXD-Service'): # Try to update the custom field exd_service_info = issue.downstream.get('EXD-Service') @@ -659,14 +648,12 @@ def _create_jira_issue(client, issue, config): f"Error adding EXD-Service field.\n" f"Project: {exd_service_info['guild']}\n" f"Value: {exd_service_info['value']}") - confluence_data['Misc. Fields'] += 1 # Add upstream issue ID in comment if required if 'upstream_id' in issue.downstream.get('issue_updates', []): comment = f"Creating issue for " \ f"[{issue.upstream}-#{issue.upstream_id}|{issue.url}]" client.add_comment(downstream, comment) - confluence_data['Misc. Fields'] = 1 remote_link = dict(url=issue.url, title=remote_link_title) attach_link(client, downstream, remote_link) @@ -674,11 +661,6 @@ def _create_jira_issue(client, issue, config): default_status = issue.downstream.get('default_status', None) if default_status is not None: change_status(client, downstream, default_status, issue) - confluence_data['Transitions'] = 1 - - # Update Confluence Page - if confluence_client.update_stat: - confluence_client.update_stat_page(confluence_data) # Update relevant information (i.e. tags, assignees etc.) if the # User opted in @@ -795,9 +777,6 @@ def _update_url(existing, issue): data = {'description': new_description} existing.update(data) log.info('Updated description') - if confluence_client.update_stat: - confluence_data = {'Misc. Fields': 1} - confluence_client.update_stat_page(confluence_data) def _update_transition(client, existing, issue): @@ -809,7 +788,6 @@ def _update_transition(client, existing, issue): :param sync2jira.intermediary.Issue issue: Upstream issue :returns: Nothing """ - confluence_data = {} # Update the issue status in the JIRA description # Format the status formatted_status = "Upstream issue status: %s" % issue.status @@ -846,9 +824,6 @@ def _update_transition(client, existing, issue): data = {'description': new_description} existing.update(data) log.info('Updated transition') - confluence_data['Status'] = 1 - if confluence_client.update_stat and confluence_data: - confluence_client.update_stat_page(confluence_data) # If the user just inputted True, only update the description # If the user added a custom closed status, attempt to close the @@ -918,9 +893,6 @@ def _update_title(issue, existing): data = {'summary': issue.title} existing.update(data) log.info('Updated title') - if confluence_client.update_stat: - confluence_data = {'Title': 1} - confluence_client.update_stat_page(confluence_data) def _update_comments(client, existing, issue): @@ -943,9 +915,6 @@ def _update_comments(client, existing, issue): client.add_comment(existing, comment_body) if len(comments_d) > 0: log.info("Comments synchronization done on %i comments." % len(comments_d)) - if confluence_client.update_stat: - confluence_data = {'Comments': len(comments_d)} - confluence_client.update_stat_page(confluence_data) def _update_fixVersion(updates, existing, issue, client): @@ -998,9 +967,6 @@ def _update_fixVersion(updates, existing, issue, client): try: existing.update(data) log.info('Updated %s fixVersion(s)' % len(fix_version)) - if confluence_client.update_stat: - confluence_data = {'FixVersion': len(fix_version)} - confluence_client.update_stat_page(confluence_data) except JIRAError: log.warning('Error updating the fixVersion. %s is an invalid fixVersion.' % issue.fixVersion) # Add a comment to indicate there was an issue @@ -1041,27 +1007,18 @@ def _update_assignee(client, existing, issue, updates): # Update the assignee assign_user(client, issue, existing) log.info('Updated assignee') - if confluence_client.update_stat: - confluence_data = {'Assignee': 1} - confluence_client.update_stat_page(confluence_data) return else: # Update the assignee if we have someone to assignee it too if update: assign_user(client, issue, existing) log.info('Updated assignee') - if confluence_client.update_stat: - confluence_data = {'Assignee': 1} - confluence_client.update_stat_page(confluence_data) else: if existing.fields.assignee and not issue.assignee: # Else we should remove all assignees # Set removeAll flag to true assign_user(client, issue, existing, remove_all=True) log.info('Updated assignee') - if confluence_client.update_stat: - confluence_data = {'Assignee': 1} - confluence_client.update_stat_page(confluence_data) def _update_jira_labels(issue, labels): @@ -1080,9 +1037,6 @@ def _update_jira_labels(issue, labels): data = {'labels': _labels} issue.update(data) log.info('Updated %s tag(s)' % len(_labels)) - if confluence_client.update_stat: - confluence_data = {'Tags': len(_labels)} - confluence_client.update_stat_page(confluence_data) def _update_tags(updates, existing, issue): @@ -1193,9 +1147,6 @@ def _update_description(existing, issue): data = {'description': new_description} existing.update(data) log.info('Updated description') - if confluence_client.update_stat: - confluence_data = {'Description': 1} - confluence_client.update_stat_page(confluence_data) def _update_on_close(existing, issue, updates): diff --git a/sync2jira/downstream_pr.py b/sync2jira/downstream_pr.py index e01ecec..81375ca 100644 --- a/sync2jira/downstream_pr.py +++ b/sync2jira/downstream_pr.py @@ -25,7 +25,6 @@ # Local Modules import sync2jira.downstream_issue as d_issue from sync2jira.intermediary import Issue, matcher -from sync2jira.confluence_client import confluence_client log = logging.getLogger('sync2jira') @@ -122,9 +121,6 @@ def update_jira_issue(existing, pr, client): # Attach remote link remote_link = dict(url=pr.url, title=f"[PR] {pr.title}") d_issue.attach_link(client, existing, remote_link) - if confluence_client.update_stat: - confluence_data = {'Comments': 1} - confluence_client.update_stat_page(confluence_data) # Only synchronize link_transition for listings that op-in if any('merge_transition' in item for item in updates) and 'merged' in pr.suffix: diff --git a/sync2jira/main.py b/sync2jira/main.py index 198afe2..04744c4 100644 --- a/sync2jira/main.py +++ b/sync2jira/main.py @@ -43,7 +43,6 @@ import sync2jira.downstream_pr as d_pr from sync2jira.mailer import send_mail from sync2jira.intermediary import matcher -from sync2jira.confluence_client import confluence_client # Set up our logging FORMAT = "[%(asctime)s] %(levelname)s: %(message)s" @@ -425,9 +424,6 @@ def main(runtime_test=False, runtime_config=None): else: config = runtime_config - if config['sync2jira']['confluence_statistics']: - confluence_client.update_stat_value(True) - logging.basicConfig(level=logging.INFO) warnings.simplefilter("ignore") config['validate_signatures'] = False diff --git a/tests/integration_tests/runtime_config.py b/tests/integration_tests/runtime_config.py index 6737ada..dfba7e1 100644 --- a/tests/integration_tests/runtime_config.py +++ b/tests/integration_tests/runtime_config.py @@ -16,7 +16,6 @@ 'initialize': True, 'testing': False, 'develop': True, - 'confluence_statistics': False, # We don't need legacy mode anymore. Not for a long time. Let's # remove it soon. diff --git a/tests/test_confluence_client.py b/tests/test_confluence_client.py deleted file mode 100644 index a979555..0000000 --- a/tests/test_confluence_client.py +++ /dev/null @@ -1,306 +0,0 @@ -import unittest - -import mock - -try: - # Python 3.3 > - from unittest.mock import MagicMock # noqa: F401 -except ImportError: - from mock import MagicMock # noqa: F401 - -PATH = 'sync2jira.confluence_client.' - -from sync2jira.confluence_client import ConfluenceClient - - -class TestConfluenceClient(unittest.TestCase): - """ - This class tests the confluence_client.py file - """ - - @mock.patch(PATH + 'ConfluenceClient.find_page') - def setUp(self, - mock_find_page): - mock_find_page.return_value = "mock_page_id" - self.confluence_client = ConfluenceClient() - - self.mock_resp_bad = MagicMock() - self.mock_resp_bad.ok = False - - def test_update_state_value(self): - """ - This function tests the 'update_stat_value' function - """ - # Call the function - self.confluence_client.update_stat_value(True) - - # Assert Everything was called correctly - self.assertEqual(self.confluence_client.update_stat, True) - - @mock.patch(PATH + 'ConfluenceClient.get_auth_object') - @mock.patch(PATH + 'requests') - def test_req_kwargs_basic(self, - mock_requests, - mock_get_auth_object): - """ - This function tests 'req_kwargs' property with a basic client - """ - # Set up return values - mock_get_auth_object.return_value = 'mock_auth_object' - - # Call the function - response = self.confluence_client.req_kwargs - - # Assert everything was called correctly - mock_requests.get.assert_not_called() - mock_get_auth_object.assert_called() - self.assertEqual(response, {'auth': 'mock_auth_object'}) - - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_find_page_found(self, - mock_req_kwargs, - mock_requests): - """ - This function tests the 'find_page' function where we find a page - """ - # Set up return values - mock_resp = MagicMock() - mock_resp.json.return_value = {'results': [{'id': 'mock_id'}]} - mock_requests.get.return_value = mock_resp - - # Call the function - response = self.confluence_client.find_page() - - # Assert everything was called correctly - mock_requests.get.assert_called_with( - "http://mock_confluence_url/rest/api/content/search?cql=title='mock_confluence_page_title' and space=mock_confluence_space") - mock_resp.json.assert_called() - self.assertEqual(response, 'mock_id') - - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_find_page_not_found(self, - mock_req_kwargs, - mock_requests): - """ - This function tests the 'find_page' function where we don't find a page - """ - # Set up return values - mock_resp = MagicMock() - mock_resp.json.return_value = {'results': []} - mock_requests.get.return_value = mock_resp - - # Call the function - response = self.confluence_client.find_page() - - # Assert everything was called correctly - mock_requests.get.assert_called_with( - "http://mock_confluence_url/rest/api/content/search?cql=title='mock_confluence_page_title' and space=mock_confluence_space") - mock_resp.json.assert_called() - self.assertEqual(response, None) - - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_find_page_error(self, - mock_req_kwargs, - mock_requests): - """ - This function tests the 'find_page' function where we get an Error - """ - # Set up return values - mock_resp = MagicMock() - mock_resp.json.return_value = {'results': []} - mock_requests.get.return_value = self.mock_resp_bad - - # Call the function - self.confluence_client.find_page() - - # Assert everything was called correctly - mock_requests.get.assert_called_with( - "http://mock_confluence_url/rest/api/content/search?cql=title='mock_confluence_page_title' and space=mock_confluence_space") - - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_get_page_info(self, - mock_req_kwargs, - mock_requests): - """ - This function tests the 'get_page_info' function where we have no Errors - """ - # Set up return values - mock_resp = MagicMock() - mock_resp.json.return_value = 'mock_json' - mock_requests.get.return_value = mock_resp - - # Call the function - response = self.confluence_client.get_page_info('mock_page_id') - - # Assert everything was called correctly - mock_requests.get.assert_called_with( - 'http://mock_confluence_url/rest/api/content/mock_page_id?expand=ancestors,version,body.storage') - self.assertEqual(response, 'mock_json') - - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_get_page_info_error(self, - mock_req_kwargs, - mock_requests): - """ - This function tests the 'get_page_info' function where we have Errors - """ - # Set up return values - mock_resp = MagicMock() - mock_resp.json.return_value = 'mock_json' - mock_requests.get.return_value = self.mock_resp_bad - - # Call the function - self.confluence_client.get_page_info('mock_page_id') - - # Assert everything was called correctly - mock_requests.get.assert_called_with( - 'http://mock_confluence_url/rest/api/content/mock_page_id?expand=ancestors,version,body.storage') - - @mock.patch(PATH + 'ConfluenceClient.get_page_info') - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_update_page(self, - mock_req_kwargs, - mock_requests, - mock_get_page_info): - """ - This function tests the 'update_page' function where we have no Errors - """ - # Set up return values - mock_get_page_info.return_value = { - 'version': {'number': 1}, - 'title': 'mock_title'} - mock_resp = MagicMock() - mock_resp.ok = True - mock_resp.json.return_value = 'mock_json' - mock_requests.put.return_value = mock_resp - - # Call the function - response = self.confluence_client.update_page( - page_id='mock_page_id', - html_str='mock_html_str', - ) - - # Assert everything was called correctly - mock_requests.put.assert_called_with( - 'http://mock_confluence_url/rest/api/content/mock_page_id', - json={'id': 'mock_page_id', 'type': 'page', - 'title': 'mock_title', 'version': {'number': 2}, - 'body': {'storage': - {'representation': 'storage', 'value': 'mock_html_str'}}}) - self.assertEqual(response, 'mock_json') - - @mock.patch(PATH + 'ConfluenceClient.get_page_info') - @mock.patch(PATH + 'requests') - @mock.patch(PATH + 'ConfluenceClient.req_kwargs') - def test_update_page_error(self, - mock_req_kwargs, - mock_requests, - mock_get_page_info): - """ - This function tests the 'update_page' function where we have Errors - """ - # Set up return values - mock_get_page_info.return_value = { - 'version': {'number': 1}, - 'title': 'mock_title'} - mock_requests.put.return_value = self.mock_resp_bad - - # Call the function - self.confluence_client.update_page( - page_id='mock_page_id', - html_str='mock_html_str', - ) - - # Assert everything was called correctly - mock_requests.put.assert_called_with( - 'http://mock_confluence_url/rest/api/content/mock_page_id', - json={ - 'id': 'mock_page_id', - 'type': 'page', - 'title': 'mock_title', - 'version': {'number': 2}, - 'body': - {'storage': {'representation': 'storage', 'value': 'mock_html_str'}}}) - - @mock.patch(PATH + 'HTTPBasicAuth') - def test_get_auth_object_basic(self, - mock_basic,): - """ - This function tests 'get_auth_object' with basic auth - """ - # Set up return values - mock_basic.return_value = 'mock_basic_auth' - - # Call the function - response = self.confluence_client.get_auth_object() - - # Assert everything was called correctly - self.assertEqual(response, 'mock_basic_auth') - mock_basic.assert_called_with('mock_confluence_username', 'mock_confluence_password') - - @mock.patch(PATH + 'ConfluenceClient.update_page') - @mock.patch(PATH + 'jinja2') - @mock.patch(PATH + 'ConfluenceClient.get_page_info') - def test_update_stat_page(self, - mock_get_page_info, - mock_jinja2, - mock_update_page): - """ - This function tests 'update_stat_page' function - """ - # Set up return values - mock_html = """ - Created Issues1< - Descriptions1< - Comments1< - Reporters1< - Assignees1< - Status1< - Transitions1< - Titles1< - Tags1< - Fix Version1< - Misc. Fields1< - Total1< - """ - mock_get_page_info.return_value = {'body': {'storage': {'value': mock_html}}} - mock_confluence_data = { - 'Created Issues': 10, - 'Descriptions': 10, - 'Comments': 10, - 'Reporters': 10, - 'Status': 10, - 'Assignees': 10, - 'Transitions': 10, - 'Title': 10, - 'Tags': 10, - 'FixVersion': 10, - 'Misc. Fields': 10, - } - mock_templateLoader = MagicMock() - mock_templateEnv = MagicMock() - mock_template = MagicMock() - mock_template.render.return_value = 'mock_render' - mock_templateEnv.get_template.return_value = mock_template - mock_jinja2.FileSystemLoader.return_value = mock_templateLoader - mock_jinja2.Environment.return_value = mock_templateEnv - - # Call the function - self.confluence_client.update_stat_page(mock_confluence_data) - - # Assert Everything was called correctly - mock_jinja2.FileSystemLoader.assert_called_with(searchpath='usr/local/src/sync2jira/sync2jira/') - mock_jinja2.Environment.assert_called_with(loader=mock_templateLoader) - mock_templateEnv.get_template.assert_called_with('confluence_stat.jinja') - mock_template.render.assert_called_with(confluence_data={ - 'Created Issues': 11, 'Descriptions': 11, 'Comments': 11, - 'Reporters': 11, 'Status': 11, 'Assignees': 11, 'Transitions': 11, - 'Title': 11, 'Tags': 11, 'FixVersion': 11, 'Misc. Fields': 11, - 'Total': 121, 'Total Time': '0:50:25 (HR:MIN:SEC)'}) - mock_update_page.assert_called_with('mock_page_id', 'mock_render') diff --git a/tests/test_downstream_issue.py b/tests/test_downstream_issue.py index c05777a..3b49c25 100644 --- a/tests/test_downstream_issue.py +++ b/tests/test_downstream_issue.py @@ -329,15 +329,13 @@ def test_assign_user_remove_all(self, mock_client): mock_client.assign_issue.assert_not_called() mock_client.search_assignable_users_for_issues.assert_not_called() - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + '_update_jira_issue') @mock.patch(PATH + 'attach_link') @mock.patch('jira.client.JIRA') def test_create_jira_issue(self, mock_client, mock_attach_link, - mock_update_jira_issue, - mock_confluence_client): + mock_update_jira_issue): """ Tests '_create_jira_issue' function """ @@ -348,7 +346,6 @@ def test_create_jira_issue(self, {'name': 'QA Contact', 'id': 'customfield_2'}, {'name': 'EXD-Service', 'id': 'customfield_3'}, ] - mock_confluence_client.update_stat = True # Call the function response = d._create_jira_issue( @@ -384,19 +381,14 @@ def test_create_jira_issue(self, {"customfield_3": {"value": "EXD-Project", "child": {"value": "EXD-Value"}}}) self.assertEqual(response, self.mock_downstream) mock_client.add_comment.assert_not_called() - mock_confluence_client.update_stat_page.assert_called_with( - {'Misc. Fields': 3, 'Created Issues': 1, 'Descriptions': 1, 'Status': 1, 'Reporters': 1} - ) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + '_update_jira_issue') @mock.patch(PATH + 'attach_link') @mock.patch('jira.client.JIRA') def test_create_jira_issue_failed_epic_link(self, mock_client, mock_attach_link, - mock_update_jira_issue, - mock_confluence_client): + mock_update_jira_issue): """ Tests '_create_jira_issue' function where we fail updating the epic link """ @@ -408,7 +400,6 @@ def test_create_jira_issue_failed_epic_link(self, {'name': 'EXD-Service', 'id': 'customfield_3'}, ] self.mock_downstream.update.side_effect = [JIRAError, 'success', 'success'] - mock_confluence_client.update_stat = True # Call the function response = d._create_jira_issue( @@ -445,18 +436,14 @@ def test_create_jira_issue_failed_epic_link(self, {"customfield_3": {"value": "EXD-Project", "child": {"value": "EXD-Value"}}}) self.assertEqual(response, self.mock_downstream) mock_client.add_comment.assert_called_with(self.mock_downstream, f"Error adding Epic-Link: DUMMY-1234") - mock_confluence_client.update_stat_page.assert_called_with( - {'Misc. Fields': 3, 'Created Issues': 1, 'Descriptions': 1, 'Status': 1, 'Reporters': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + '_update_jira_issue') @mock.patch(PATH + 'attach_link') @mock.patch('jira.client.JIRA') def test_create_jira_issue_failed_exd_service(self, mock_client, mock_attach_link, - mock_update_jira_issue, - mock_confluence_client): + mock_update_jira_issue): """ Tests '_create_jira_issue' function where we fail updating the EXD-Service field """ @@ -468,7 +455,6 @@ def test_create_jira_issue_failed_exd_service(self, {'name': 'EXD-Service', 'id': 'customfield_3'}, ] self.mock_downstream.update.side_effect = ['success', 'success', JIRAError] - mock_confluence_client.update_stat = True # Call the function response = d._create_jira_issue( @@ -508,18 +494,14 @@ def test_create_jira_issue_failed_exd_service(self, f"Error adding EXD-Service field.\n" f"Project: {self.mock_issue.downstream['EXD-Service']['guild']}\n" f"Value: {self.mock_issue.downstream['EXD-Service']['value']}") - mock_confluence_client.update_stat_page.assert_called_with( - {'Misc. Fields': 3, 'Created Issues': 1, 'Descriptions': 1, 'Status': 1, 'Reporters': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + '_update_jira_issue') @mock.patch(PATH + 'attach_link') @mock.patch('jira.client.JIRA') def test_create_jira_issue_no_updates(self, mock_client, mock_attach_link, - mock_update_jira_issue, - mock_confluence_client): + mock_update_jira_issue): """ Tests '_create_jira_issue' function where we have no updates @@ -527,7 +509,6 @@ def test_create_jira_issue_no_updates(self, # Set up return values mock_client.create_issue.return_value = self.mock_downstream self.mock_issue.downstream['issue_updates'] = [] - mock_confluence_client.update_stat = True # Call the function response = d._create_jira_issue( @@ -559,7 +540,6 @@ def test_create_jira_issue_no_updates(self, ) self.assertEqual(response, self.mock_downstream) mock_client.add_comment.assert_not_called() - mock_confluence_client.update_stat_page.assert_called_with({'Misc. Fields': 1, 'Created Issues': 1, 'Reporters': 1}) @mock.patch(PATH + 'get_jira_client') @@ -731,11 +711,9 @@ def test_update_jira_issue(self, ) mock_update_on_close.assert_called_once() - @mock.patch(PATH + 'confluence_client') @mock.patch('jira.client.JIRA') def test_update_transition_JIRAError(self, - mock_client, - mock_confluence_client): + mock_client): """ This function tests the '_update_transition' function where Upstream issue status s not in existing.fields.description and transitioning the issue throws an error @@ -745,7 +723,6 @@ def test_update_transition_JIRAError(self, self.mock_downstream.fields.description = '' mock_client.transitions.return_value = [{'name': 'CUSTOM TRANSITION', 'id': '1234'}] mock_client.transition_issue.side_effect = JIRAError - mock_confluence_client.update_stat = True # Call the function d._update_transition( @@ -758,14 +735,11 @@ def test_update_transition_JIRAError(self, self.mock_downstream.update.assert_called_with({'description': 'Upstream issue status: Closed\n'}) mock_client.transitions.assert_called_with(self.mock_downstream) mock_client.transition_issue.assert_called_with(self.mock_downstream, 1234) - mock_confluence_client.update_stat_page.assert_called_with({'Status': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch('jira.client.JIRA') def test_update_transition_not_found(self, - mock_client, - mock_confluence_client): + mock_client): """ This function tests the '_update_transition' function where Upstream issue status not in existing.fields.description and we can't find the appropriate closed status @@ -775,7 +749,6 @@ def test_update_transition_not_found(self, self.mock_issue.downstream['transition'] = 'bad_transition' self.mock_downstream.fields.description = '' mock_client.transitions.return_value = [{'name': 'CUSTOM TRANSITION', 'id': '1234'}] - mock_confluence_client.update_stat = True # Call the function d._update_transition( @@ -788,13 +761,10 @@ def test_update_transition_not_found(self, self.mock_downstream.update.assert_called_with({'description': 'Upstream issue status: Closed\n'}) mock_client.transitions.assert_called_with(self.mock_downstream) mock_client.transition_issue.assert_called_with(self.mock_downstream, 1234) - mock_confluence_client.update_stat_page.assert_called_with({'Transition': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch('jira.client.JIRA') def test_update_transition_successful(self, - mock_client, - mock_confluence_client): + mock_client): """ This function tests the '_update_transition' function where everything goes smoothly! """ @@ -802,7 +772,6 @@ def test_update_transition_successful(self, self.mock_issue.status = 'Closed' self.mock_downstream.fields.description = '[test] Upstream issue status: Open' mock_client.transitions.return_value = [{'name': 'CUSTOM TRANSITION', 'id': '1234'}] - mock_confluence_client.update_stat = True # Call the function d._update_transition( @@ -815,17 +784,14 @@ def test_update_transition_successful(self, self.mock_downstream.update.assert_called_with({'description': 'Upstream issue status: Closed'}) mock_client.transitions.assert_called_with(self.mock_downstream) mock_client.transition_issue.assert_called_with(self.mock_downstream, 1234) - mock_confluence_client.update_stat_page.assert_called_with({'Transition': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + '_comment_format') @mock.patch(PATH + '_comment_matching') @mock.patch('jira.client.JIRA') def test_update_comments(self, mock_client, mock_comment_matching, - mock_comment_format, - mock_confluence_client): + mock_comment_format): """ This function tests the 'update_comments' function """ @@ -833,7 +799,6 @@ def test_update_comments(self, mock_client.comments.return_value = 'mock_comments' mock_comment_matching.return_value = ['mock_comments_d'] mock_comment_format.return_value = 'mock_comment_body' - mock_confluence_client.update_stat = True # Call the function d._update_comments( @@ -847,7 +812,6 @@ def test_update_comments(self, mock_comment_matching.assert_called_with(self.mock_issue.comments, 'mock_comments') mock_comment_format.assert_called_with('mock_comments_d') mock_client.add_comment.assert_called_with(self.mock_downstream, 'mock_comment_body') - mock_confluence_client.update_stat_page.assert_called_with({'Comments': 1}) def test_update_fixVersion_JIRAError(self): """ @@ -892,16 +856,13 @@ def test_update_fixVersion_no_api_call(self): self.mock_downstream.update.assert_not_called() mock_client.add_comment.assert_not_called() - @mock.patch(PATH + 'confluence_client') - def test_update_fixVersion_successful(self, - mock_confluence_client): + def test_update_fixVersion_successful(self): """ This function tests the 'update_fixVersion' function where everything goes smoothly! """ # Set up return values self.mock_downstream.fields.fixVersions = [] mock_client = MagicMock() - mock_confluence_client.update_stat = True # Call the function d._update_fixVersion( @@ -914,15 +875,12 @@ def test_update_fixVersion_successful(self, self.mock_downstream.update.assert_called_with( {'fixVersions': [{'name': 'fixVersion3'}, {'name': 'fixVersion4'}]}) mock_client.add_comment.assert_not_called() - mock_confluence_client.update_stat_page.assert_called_with({'FixVersion': 2}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'assign_user') @mock.patch('jira.client.JIRA') def test_update_assignee_assignee(self, mock_client, - mock_assign_user, - mock_confluence_client): + mock_assign_user): """ This function tests the 'update_assignee' function where issue.assignee exists """ @@ -940,15 +898,12 @@ def test_update_assignee_assignee(self, self.mock_issue, self.mock_downstream ) - mock_confluence_client.update_stat_page.assert_called_with({'Assignee': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'assign_user') @mock.patch('jira.client.JIRA') def test_update_assignee_no_assignee(self, mock_client, - mock_assign_user, - mock_confluence_client): + mock_assign_user): """ This function tests the '_update_assignee' function where issue.assignee does not exist """ @@ -970,21 +925,17 @@ def test_update_assignee_no_assignee(self, self.mock_downstream, remove_all=True ) - mock_confluence_client.update_stat_page.assert_called_with({'Assignee': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'assign_user') @mock.patch('jira.client.JIRA') def test_update_assignee_no_overwrite(self, mock_client, - mock_assign_user, - mock_confluence_client): + mock_assign_user): """ This function tests the '_update_assignee' function where overwrite is false """ # Set up return values self.mock_downstream.fields.assignee = None - mock_confluence_client.update_stat = True # Call the function d._update_assignee( @@ -1000,23 +951,19 @@ def test_update_assignee_no_overwrite(self, self.mock_issue, self.mock_downstream ) - mock_confluence_client.update_stat_page.assert_called_with({'Assignee': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'verify_tags') @mock.patch(PATH + '_label_matching') def test_update_tags(self, mock_label_matching, - mock_verify_tags, - mock_confluence_client): + mock_verify_tags): """ This function tests the '_update_tags' function """ # Set up return values mock_label_matching.return_value = 'mock_updated_labels' mock_verify_tags.return_value = ['mock_verified_tags'] - mock_confluence_client.update_stat = True # Call the function d._update_tags( @@ -1032,7 +979,6 @@ def test_update_tags(self, ) mock_verify_tags.assert_called_with('mock_updated_labels') self.mock_downstream.update.assert_called_with({'labels': ['mock_verified_tags']}) - mock_confluence_client.update_stat_page.assert_called_with({'Tags': 1}) @mock.patch(PATH + 'verify_tags') @mock.patch(PATH + '_label_matching') @@ -1062,15 +1008,12 @@ def test_update_tags_no_api_call(self, mock_verify_tags.assert_called_with('mock_updated_labels') self.mock_downstream.update.assert_not_called() - @mock.patch(PATH + 'confluence_client') - def test_update_description_update(self, - mock_confluence_client): + def test_update_description_update(self): """ This function tests '_update_description' where we just have to update the contents of the description """ # Set up return values self.mock_downstream.fields.description = 'Upstream description: {quote} test {quote}' - mock_confluence_client.update_stat = True # Call the function d._update_description( @@ -1081,11 +1024,8 @@ def test_update_description_update(self, # Assert all calls were made correctly self.mock_downstream.update.assert_called_with( {'description': 'Upstream description: {quote}mock_content{quote}'}) - mock_confluence_client.update_stat_page.assert_called_with({'Description': 1}) - @mock.patch(PATH + 'confluence_client') - def test_update_description_add_field(self, - mock_confluence_client): + def test_update_description_add_field(self): """ This function tests '_update_description' where we just have to add a description field """ @@ -1103,13 +1043,10 @@ def test_update_description_add_field(self, self.mock_downstream.update.assert_called_with( {'description': '[123] Upstream Reporter: mock_user \n' 'Upstream description: {quote}mock_content{quote}'}) - mock_confluence_client.update_stat_page.assert_called_with({'Description': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'datetime') def test_update_description_add_reporter(self, - mock_datetime, - mock_confluence_client): + mock_datetime): """ This function tests '_update_description' where we have to add a description and upstream reporter field """ @@ -1119,7 +1056,6 @@ def test_update_description_add_reporter(self, self.mock_issue.id = '123' self.mock_issue.reporter = {'fullname': 'mock_user'} mock_datetime.today.return_value = self.mock_today - mock_confluence_client.update_stat = True # Call the function d._update_description( @@ -1131,17 +1067,13 @@ def test_update_description_add_reporter(self, {'description': '[mock_today] Upstream issue status: Open\n[123]' ' Upstream Reporter: mock_user\nUpstream description:' ' {quote}mock_content{quote}\n'}) - mock_confluence_client.update_stat_page.assert_called_with({'Description': 1}) - @mock.patch(PATH + 'confluence_client') - def test_update_description_add_reporter_no_status(self, - mock_confluence_client): + def test_update_description_add_reporter_no_status(self): """ This function tests '_update_description' where we have to add reporter and description without status """ # Set up return values self.mock_downstream.fields.description = '' - mock_confluence_client.update_stat = True # Call the function d._update_description( @@ -1153,13 +1085,10 @@ def test_update_description_add_reporter_no_status(self, self.mock_downstream.update.assert_called_with( {'description': '[1234] Upstream Reporter: mock_user \n' 'Upstream description: {quote}mock_content{quote} \n '}) - mock_confluence_client.update_stat_page.assert_called_with({'Description': 1}) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'datetime') def test_update_description_add_description(self, - mock_datetime, - mock_confluence_client): + mock_datetime): """ This function tests '_update_description' where we have a reporter and status already """ @@ -1182,7 +1111,6 @@ def test_update_description_add_description(self, {'description': '[mock_today] Upstream issue status: Open\n' '[123] Upstream Reporter: mock_user\n' 'Upstream description: {quote}mock_content{quote}\n'}) - mock_confluence_client.update_stat_page.assert_called_with({'Description': 1}) def test_verify_tags(self): """ @@ -1694,14 +1622,11 @@ def test_update_url_no_update(self): # Assert everything was called correctly self.mock_downstream.update.assert_not_called() - @mock.patch(PATH + 'confluence_client') - def test_update_url_update(self, - mock_confluence_client): + def test_update_url_update(self): """ This function tests '_update_url' where we already have the URL """ # Set up return values - mock_confluence_client.update_stat = True self.mock_downstream.fields.description = "" # Call the function @@ -1712,15 +1637,12 @@ def test_update_url_update(self, {'description': f"\nUpstream URL: {self.mock_issue.url}\n"}) - @mock.patch(PATH + 'confluence_client') - def test_update_on_close_update(self, - mock_confluence_client): + def test_update_on_close_update(self): """ This function tests '_update_on_close' where there is an "apply_labels" configuration, and labels need to be updated. """ # Set up return values - mock_confluence_client.update_stat = True self.mock_downstream.fields.description = "" self.mock_issue.status = 'Closed' updates = [{"on_close": {"apply_labels": ["closed-upstream"]}}] diff --git a/tests/test_downstream_pr.py b/tests/test_downstream_pr.py index 82b6d0b..1ff9c81 100644 --- a/tests/test_downstream_pr.py +++ b/tests/test_downstream_pr.py @@ -145,7 +145,6 @@ def test_sync_with_jira_testing(self, mock_client.search_issues.assert_not_called() mock_d_issue.get_jira_client.assert_not_called() - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'comment_exists') @mock.patch(PATH + 'format_comment') @mock.patch(PATH + 'd_issue.attach_link') @@ -154,8 +153,7 @@ def test_update_jira_issue_link(self, mock_issue_link_exists, mock_attach_link, mock_format_comment, - mock_comment_exists, - mock_confluence_client): + mock_comment_exists): """ This function tests 'update_jira_issue' """ @@ -163,7 +161,6 @@ def test_update_jira_issue_link(self, mock_format_comment.return_value = 'mock_formatted_comment' mock_comment_exists.return_value = False mock_issue_link_exists.return_value = False - mock_confluence_client.update_stat = True # Call the function d.update_jira_issue('mock_existing', self.mock_pr, self.mock_client) @@ -172,7 +169,6 @@ def test_update_jira_issue_link(self, self.mock_client.add_comment.assert_called_with('mock_existing', 'mock_formatted_comment') mock_format_comment.assert_called_with(self.mock_pr, self.mock_pr.suffix, self.mock_client) mock_comment_exists.assert_called_with(self.mock_client, 'mock_existing', 'mock_formatted_comment') - mock_confluence_client.update_stat_page.assert_called_with({'Comments': 1}) mock_attach_link.assert_called_with(self.mock_client, 'mock_existing', {'url': 'mock_url', 'title': '[PR] mock_title'}) def test_issue_link_exists_false(self): diff --git a/tests/test_main.py b/tests/test_main.py index 0c76be6..f2ef5c0 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -26,7 +26,6 @@ def setUp(self): 'jira': { 'mock_jira_instance': {'mock_jira': 'mock_jira'} }, - 'confluence_statistics': True, 'testing': {}, 'legacy_matching': False, 'map': { @@ -145,7 +144,6 @@ def test_list_managed(self, @mock.patch(PATH + 'initialize_recent') @mock.patch(PATH + 'report_failure') @mock.patch(PATH + 'INITIALIZE', 1) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'initialize_issues') @mock.patch(PATH + 'initialize_pr') @mock.patch(PATH + 'load_config') @@ -155,7 +153,6 @@ def test_main_initialize(self, mock_load_config, mock_initialize_pr, mock_initialize_issues, - mock_confluence_client, mock_report_failure, mock_initialize_recent): """ @@ -163,7 +160,6 @@ def test_main_initialize(self, """ # Set up return values mock_load_config.return_value = self.mock_config - self.mock_config['sync2jira']['confluence_statistics'] = True # Call the function m.main() @@ -176,9 +172,7 @@ def test_main_initialize(self, mock_initialize_pr.assert_called_with(self.mock_config) mock_report_failure.assert_not_called() mock_initialize_recent.assert_not_called() - mock_confluence_client.update_stat_value.assert_called_with(True) - @mock.patch(PATH + 'confluence_client') @mock.patch(PATH + 'initialize_recent') @mock.patch(PATH + 'report_failure') @mock.patch(PATH + 'INITIALIZE', 0) @@ -192,8 +186,7 @@ def test_main_no_initialize(self, mock_initialize_pr, mock_initialize_issues, mock_report_failure, - mock_initialize_recent, - mock_confluence_client,): + mock_initialize_recent): """ This tests the 'main' function """ @@ -211,7 +204,6 @@ def test_main_no_initialize(self, mock_initialize_pr.assert_not_called() mock_report_failure.assert_not_called() mock_initialize_recent.assert_called_with(self.mock_config) - mock_confluence_client.update_stat_value.assert_called_with(True) @mock.patch(PATH + 'u_issue') @mock.patch(PATH + 'd_issue') diff --git a/tox.ini b/tox.ini index d265d8b..c608fa1 100644 --- a/tox.ini +++ b/tox.ini @@ -6,11 +6,6 @@ setenv = DEFAULT_FROM = mock_email@mock.com DEFAULT_SERVER = mock_server INITIALIZE=1 - CONFLUENCE_SPACE=mock_confluence_space - CONFLUENCE_PAGE_TITLE=mock_confluence_page_title - CONFLUENCE_URL=http://mock_confluence_url - CONFLUENCE_USERNAME=mock_confluence_username - CONFLUENCE_PASSWORD=mock_confluence_password basepython = py311: python3.11 deps =