From 6355f31280ce591ab0263d88802d0f89cd641b4b Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 17 Jul 2017 17:38:43 +0200 Subject: [PATCH] TT#18821 don't set release_target for non-NGCP projects Change-Id: Ibfd4b3080a14d7cbe7bf6d4e18110106f1221f91 --- release_dashboard/test/test_utils_build.py | 24 +++++++++++++++++ release_dashboard/utils/build.py | 7 +++++ repoapi/models/wni.py | 5 ++++ repoapi/test/test_workfrontnote.py | 31 ++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 release_dashboard/test/test_utils_build.py diff --git a/release_dashboard/test/test_utils_build.py b/release_dashboard/test/test_utils_build.py new file mode 100644 index 0000000..6532942 --- /dev/null +++ b/release_dashboard/test/test_utils_build.py @@ -0,0 +1,24 @@ +# Copyright (C) 2017 The Sipwise Team - http://sipwise.com +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this prograproj. If not, see . + +from django.test import TestCase +from release_dashboard.utils import build + + +class UtilsBuildTestCase(TestCase): + + def test_is_ngcp_project(self): + self.assertFalse(build.is_ngcp_project('fake')) + self.assertTrue(build.is_ngcp_project('kamailio')) diff --git a/release_dashboard/utils/build.py b/release_dashboard/utils/build.py index 64cf9a3..b5b99dc 100644 --- a/release_dashboard/utils/build.py +++ b/release_dashboard/utils/build.py @@ -117,3 +117,10 @@ def get_gerrit_tags(project, regex=None): def get_gerrit_branches(project, regex=None): url = settings.GERRIT_URL.format("a/projects/%s/branches/" % project) return get_gerrit_info(url) + + +def is_ngcp_project(projectname): + ngcp_projects = settings.RELEASE_DASHBOARD_SETTINGS['projects'] + if projectname in ngcp_projects: + return True + return False diff --git a/repoapi/models/wni.py b/repoapi/models/wni.py index d3ecfb4..d04c601 100644 --- a/repoapi/models/wni.py +++ b/repoapi/models/wni.py @@ -18,6 +18,7 @@ import re from django.db import models from django.conf import settings from repoapi import utils +from release_dashboard.utils.build import is_ngcp_project logger = logging.getLogger(__name__) workfront_re = re.compile(r"TT#(\d+)") @@ -60,6 +61,10 @@ class WorkfrontNoteInfo(models.Model): def workfront_release_target(instance, wid): + if not is_ngcp_project(instance.projectname): + logger.info("%s not a NGCP project, skip release_target", + instance.projectname) + return branch = instance.param_branch if workfront_re_branch.search(branch): release = branch diff --git a/repoapi/test/test_workfrontnote.py b/repoapi/test/test_workfrontnote.py index 3206510..26ae7e0 100644 --- a/repoapi/test/test_workfrontnote.py +++ b/repoapi/test/test_workfrontnote.py @@ -272,3 +272,34 @@ class WorkfrontNoteTestCase(BaseTest): self.assertItemsEqual(wsrt.mock_calls, []) wsrt.assert_not_called() wns.assert_called_once_with("0001", msg) + + @patch('repoapi.utils.workfront_set_release_target') + @patch('repoapi.utils.get_next_release') + @patch('repoapi.utils.workfront_note_send') + def test_note_commit_non_ngcp(self, wns, gnr, wsrt): + param = self.get_non_gerrit_defaults() + param['projectname'] = 'fake' + param['jobname'] = 'fake-get-code' + param['param_branch'] = 'mr5.5.2' + JenkinsBuildInfo.objects.create(**param) + + gri = WorkfrontNoteInfo.objects.filter( + workfront_id="0001", + gerrit_change="7fg4567") + self.assertEquals(gri.count(), 1) + + param['jobname'] = "fake-binaries" + param['buildnumber'] = 897 + JenkinsBuildInfo.objects.create(**param) + + gri = WorkfrontNoteInfo.objects.filter( + workfront_id="0001", + gerrit_change="7fg4567") + self.assertEquals(gri.count(), 1) + msg = "%s.git[%s] commit created %s " % ( + param['projectname'], + param['param_branch'], + settings.GITWEB_URL.format("fake", "7fg4567")) + wsrt.assert_not_called() + gnr.assert_not_called() + wns.assert_called_once_with("0001", msg)