mirror of https://github.com/sipwise/repoapi.git
Change-Id: I84020eefe644302bdd78929a17007aa1c4b7bd1echanges/45/2245/5
parent
32f88cdcfa
commit
0f49b45abc
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('repoapi', '0002_auto_20150714_0919'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='GerritRepoInfo',
|
||||
fields=[
|
||||
('id', models.AutoField(
|
||||
verbose_name='ID',
|
||||
serialize=False, auto_created=True,
|
||||
primary_key=True)),
|
||||
('param_ppa',
|
||||
models.CharField(unique=True, max_length=50)),
|
||||
('count', models.IntegerField(default=0)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,107 @@
|
||||
# Copyright (C) 2015 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.test import TestCase
|
||||
from repoapi.models import JenkinsBuildInfo, GerritRepoInfo
|
||||
from mock import patch, Mock
|
||||
|
||||
|
||||
class GerritRepoInfoTestCase(TestCase):
|
||||
|
||||
@patch('urllib2.urlopen', autospec=True)
|
||||
def test_creation(self, Mockclass):
|
||||
jbi = JenkinsBuildInfo.objects.create(
|
||||
tag="edc90cd9-37f3-4613-9748-ed05a32031c2",
|
||||
projectname="kamailio",
|
||||
jobname="kamailio-repos",
|
||||
buildnumber=897,
|
||||
result="SUCCESS",
|
||||
job_url="https://jenkins.mgm.sipwise.com/job/kamailio-repos/",
|
||||
gerrit_patchset="1",
|
||||
gerrit_change="2054",
|
||||
gerrit_eventtype="patchset-created",
|
||||
param_tag="none",
|
||||
param_branch="master",
|
||||
param_release="none",
|
||||
param_distribution="wheezy",
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
|
||||
gri = GerritRepoInfo.objects.get(param_ppa="gerrit_MT10339_review2054")
|
||||
self.assertEquals(gri.count, 1)
|
||||
|
||||
@patch('repoapi.utils.jenkins_remove_ppa')
|
||||
def test_creation_deletion(self, utils):
|
||||
jbi = JenkinsBuildInfo.objects.create(
|
||||
tag="edc90cd9-37f3-4613-9748-ed05a32031c2",
|
||||
projectname="kamailio",
|
||||
jobname="kamailio-repos",
|
||||
buildnumber=897,
|
||||
result="SUCCESS",
|
||||
job_url="https://jenkins.mgm.sipwise.com/job/kamailio-repos/",
|
||||
gerrit_patchset="1",
|
||||
gerrit_change="2054",
|
||||
gerrit_eventtype="patchset-created",
|
||||
param_tag="none",
|
||||
param_branch="master",
|
||||
param_release="none",
|
||||
param_distribution="wheezy",
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
|
||||
gri = GerritRepoInfo.objects.get(
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
self.assertEquals(gri.count, 1)
|
||||
|
||||
jbi = JenkinsBuildInfo.objects.create(
|
||||
tag="edc90cd9-37f3-4613-9748-ed05a32031c2",
|
||||
projectname="kamailio",
|
||||
jobname="kamailio-repos",
|
||||
buildnumber=897,
|
||||
result="SUCCESS",
|
||||
job_url="https://jenkins.mgm.sipwise.com/job/kamailio-repos/",
|
||||
gerrit_patchset="1",
|
||||
gerrit_change="2054",
|
||||
gerrit_eventtype="change-merged",
|
||||
param_tag="none",
|
||||
param_branch="master",
|
||||
param_release="none",
|
||||
param_distribution="wheezy",
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
|
||||
gri = GerritRepoInfo.objects.filter(
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
self.assertEquals(gri.count(), 0)
|
||||
utils.assert_called_with("gerrit_MT10339_review2054")
|
||||
|
||||
@patch('urllib2.urlopen', autospec=True)
|
||||
def test_no_creation(self, Mockclass):
|
||||
jbi = JenkinsBuildInfo.objects.create(
|
||||
tag="edc90cd9-37f3-4613-9748-ed05a32031c2",
|
||||
projectname="kamailio",
|
||||
jobname="kamailio-get-code",
|
||||
buildnumber=897,
|
||||
result="SUCCESS",
|
||||
job_url="https://jenkins.mgm.sipwise.com/job/kamailio-repos/",
|
||||
gerrit_patchset="1",
|
||||
gerrit_change="2054",
|
||||
gerrit_eventtype="patchset-created",
|
||||
param_tag="none",
|
||||
param_branch="master",
|
||||
param_release="none",
|
||||
param_distribution="wheezy",
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
|
||||
gri = GerritRepoInfo.objects.filter(
|
||||
param_ppa="gerrit_MT10339_review2054")
|
||||
self.assertEquals(gri.count(), 0)
|
||||
@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2015 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import urllib2
|
||||
import logging
|
||||
from django.conf import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def openurl(URL):
|
||||
req = urllib2.Request(URL)
|
||||
response = urllib2.urlopen(req)
|
||||
if response.code is 200:
|
||||
print "OK"
|
||||
return 0
|
||||
else:
|
||||
print "Error retrieving %s" % URL
|
||||
return 1
|
||||
|
||||
|
||||
def jenkins_remove_ppa(repo):
|
||||
url = "%s/job/remove-reprepro-codename/buildWithParameters?"\
|
||||
"token=%s&repository=%s" % \
|
||||
(settings.JENKINS_URL, settings.JENKINS_TOKEN, repo)
|
||||
if settings.DEBUG:
|
||||
logger.info("I would call %s" % url)
|
||||
else:
|
||||
openurl(url)
|
||||
Loading…
Reference in new issue