TT#11544 test: fix test due common JBI_BASEDIR

* create BaseTest class to deal with jbi_files

Change-Id: Id6efb78ef003b8b6e6b044be846cd4af14ea2c2a
changes/30/11630/3
Victor Seva 9 years ago
parent 8ae736c960
commit 2bb4b42916

@ -17,6 +17,7 @@ from django.test import TestCase, override_settings
from mock import patch, call, mock_open
from hotfix import tasks, utils, models
from repoapi.models import JenkinsBuildInfo
from repoapi.test.base import BaseTest
debian_changelog = """ngcp-fake (3.8.7.4+0~mr3.8.7.4) unstable; urgency=medium
@ -34,7 +35,7 @@ debian_changelog = """ngcp-fake (3.8.7.4+0~mr3.8.7.4) unstable; urgency=medium
@override_settings(CELERY_EAGER_PROPAGATES_EXCEPTIONS=True)
class TestHotfixReleased(TestCase):
class TestHotfixReleased(BaseTest):
def get_defaults(self):
defaults = {

@ -0,0 +1,34 @@
# 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 program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
from tempfile import mkdtemp
from django.test import TestCase, override_settings
from django.conf import settings
JBI_BASEDIR = mkdtemp(dir=settings.RESULTS_DIR)
@override_settings(JBI_BASEDIR=JBI_BASEDIR)
class BaseTest(TestCase):
def setUp(self):
if not os.path.exists(settings.JBI_BASEDIR):
os.makedirs(settings.JBI_BASEDIR)
def tearDown(self):
if os.path.exists(settings.JBI_BASEDIR):
shutil.rmtree(settings.JBI_BASEDIR)

@ -15,9 +15,10 @@
from django.test import TestCase
from repoapi.models import JenkinsBuildInfo
from repoapi.test.base import BaseTest
class JenkinsBuildInfoTestCase(TestCase):
class JenkinsBuildInfoTestCase(BaseTest):
def test_creation_no_tag(self):
jbi = JenkinsBuildInfo.objects.create(

@ -15,10 +15,11 @@
from django.test import TestCase
from repoapi.models import JenkinsBuildInfo, GerritRepoInfo
from repoapi.test.base import BaseTest
from mock import patch
class GerritRepoInfoTestCase(TestCase):
class GerritRepoInfoTestCase(BaseTest):
def get_defaults(self):
defaults = {

@ -14,7 +14,6 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
from django.test import TestCase, override_settings
from django.conf import settings
@ -22,7 +21,7 @@ from repoapi.models import JenkinsBuildInfo
from repoapi.utils import JBI_CONSOLE_URL, JBI_BUILD_URL, JBI_ARTIFACT_URL
from repoapi.utils import JBI_ENVVARS_URL
from mock import patch, call, mock_open
from repoapi.test.base import BaseTest
artifacts_json = """{
"artifacts": [
@ -36,7 +35,7 @@ artifacts_json = """{
@override_settings(CELERY_EAGER_PROPAGATES_EXCEPTIONS=True)
class TestJBICelery(TestCase):
class TestJBICelery(BaseTest):
def get_defaults(self):
defaults = {
@ -55,14 +54,6 @@ class TestJBICelery(TestCase):
}
return defaults
def setUp(self):
if not os.path.exists(settings.JBI_BASEDIR):
os.makedirs(settings.JBI_BASEDIR)
def tearDown(self):
if os.path.exists(settings.JBI_BASEDIR):
shutil.rmtree(settings.JBI_BASEDIR)
@patch('__builtin__.open', mock_open(read_data=artifacts_json))
@patch('repoapi.utils.dlfile')
def test_jbi_path_creation(self, dlfile):

@ -16,9 +16,10 @@
from django.test import TestCase
from django.utils.dateparse import parse_datetime
from repoapi.models import JenkinsBuildInfo
from repoapi.test.base import BaseTest
class JBIQueriesTestCase(TestCase):
class JBIQueriesTestCase(BaseTest):
fixtures = ['test_model_queries.json']
def test_releases(self):

@ -16,11 +16,13 @@
from django.core.urlresolvers import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from repoapi.test.base import BaseTest
class TestRest(APITestCase):
class TestRest(BaseTest, APITestCase):
def setUp(self):
super(TestRest, self).setUp()
self.url = dict()
self.url['jbi'] = reverse('jenkinsbuildinfo-list')

@ -16,10 +16,11 @@
from django.test import TestCase
from django.conf import settings
from repoapi.models import JenkinsBuildInfo, WorkfrontNoteInfo
from repoapi.test.base import BaseTest
from mock import patch
class WorkfrontNoteTestCase(TestCase):
class WorkfrontNoteTestCase(BaseTest):
def test_getID(self):
res = WorkfrontNoteInfo.getIds("jojo TT#0891 whatever")

Loading…
Cancel
Save