mirror of https://github.com/sipwise/repoapi.git
settings.DEBUG doesn't have the proper value defined at settings.dev use override_settings in BaseTest to fix it and use it on all apps if necessary Add a test and mark as expectedFailure to document this Change-Id: I2017bf695469f4d98db9e5278e43a9e89b5a6be5changes/56/38756/2
parent
7647cfcc48
commit
772681bdf6
@ -1,107 +1,114 @@
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.test import TestCase
|
||||
from release_dashboard.models import Project, DockerImage, DockerTag
|
||||
import datetime
|
||||
|
||||
diobj = DockerImage.objects
|
||||
from release_dashboard.models import DockerImage
|
||||
from release_dashboard.models import DockerTag
|
||||
from release_dashboard.models import Project
|
||||
from repoapi.test.base import BaseTest
|
||||
|
||||
|
||||
class DockerImageTestCase(TestCase):
|
||||
|
||||
class DockerImageTestCase(BaseTest):
|
||||
def setUp(self):
|
||||
self.proj = Project.objects.create(name="fake")
|
||||
|
||||
def test_create(self):
|
||||
image = diobj.create(
|
||||
name='fake-jessie', project=self.proj)
|
||||
self.assertCountEqual(self.proj.dockerimage_set.all(),
|
||||
[image, ])
|
||||
image = DockerImage.objects.create(
|
||||
name="fake-jessie", project=self.proj
|
||||
)
|
||||
self.assertCountEqual(self.proj.dockerimage_set.all(), [image])
|
||||
|
||||
def test_remove_image(self):
|
||||
image = diobj.create(
|
||||
name='fake-jessie', project=self.proj)
|
||||
self.assertCountEqual(self.proj.dockerimage_set.all(),
|
||||
[image, ])
|
||||
image = DockerImage.objects.create(
|
||||
name="fake-jessie", project=self.proj
|
||||
)
|
||||
self.assertCountEqual(self.proj.dockerimage_set.all(), [image])
|
||||
image.delete()
|
||||
self.assertTrue(Project.objects.filter(name="fake").exists())
|
||||
|
||||
def test_remove_project(self):
|
||||
image = diobj.create(
|
||||
name='fake-jessie', project=self.proj)
|
||||
self.assertCountEqual(self.proj.dockerimage_set.all(), [image, ])
|
||||
image = DockerImage.objects.create(
|
||||
name="fake-jessie", project=self.proj
|
||||
)
|
||||
self.assertCountEqual(self.proj.dockerimage_set.all(), [image])
|
||||
self.proj.delete()
|
||||
self.assertFalse(Project.objects.filter(name="fake").exists())
|
||||
self.assertFalse(diobj.filter(name="fake").exists())
|
||||
self.assertFalse(DockerImage.objects.filter(name="fake").exists())
|
||||
|
||||
def test_filter_images(self):
|
||||
images = ['fake-jessie', 'other', 'ngcp-fake', 'fake-more']
|
||||
images_ok = ['fake-jessie', 'ngcp-fake', 'fake-more']
|
||||
images = ["fake-jessie", "other", "ngcp-fake", "fake-more"]
|
||||
images_ok = ["fake-jessie", "ngcp-fake", "fake-more"]
|
||||
self.assertCountEqual(
|
||||
self.proj.filter_docker_images(images), images_ok)
|
||||
self.proj.filter_docker_images(images), images_ok
|
||||
)
|
||||
|
||||
def test_image_tags(self):
|
||||
image = diobj.create(
|
||||
name='fake-jessie', project=self.proj)
|
||||
image = DockerImage.objects.create(
|
||||
name="fake-jessie", project=self.proj
|
||||
)
|
||||
self.assertCountEqual(image.tags, [])
|
||||
DockerTag.objects.create(name="latest", image=image, manifests="{}")
|
||||
self.assertCountEqual(image.tags, ["latest"])
|
||||
DockerTag.objects.create(
|
||||
name='latest',
|
||||
image=image,
|
||||
manifests='{}')
|
||||
self.assertCountEqual(image.tags, ['latest', ])
|
||||
DockerTag.objects.create(
|
||||
name='mr5.4',
|
||||
image=image,
|
||||
manifests='{}',
|
||||
reference='whatever')
|
||||
self.assertCountEqual(image.tags, ['latest', 'mr5.4'])
|
||||
name="mr5.4", image=image, manifests="{}", reference="whatever"
|
||||
)
|
||||
self.assertCountEqual(image.tags, ["latest", "mr5.4"])
|
||||
|
||||
|
||||
class DockerImageTest2Case(TestCase):
|
||||
fixtures = ['test_model_fixtures', ]
|
||||
class DockerImageTest2Case(BaseTest):
|
||||
fixtures = [
|
||||
"test_model_fixtures",
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
self.images_with_tags = [
|
||||
diobj.get(name='data-hal-jessie'),
|
||||
diobj.get(name='documentation-jessie'),
|
||||
diobj.get(name='ngcp-panel-selenium'),
|
||||
diobj.get(name='ngcp-panel-tests-rest-api-jessie'),
|
||||
diobj.get(name='ngcp-panel-tests-selenium-jessie'),
|
||||
DockerImage.objects.get(name="data-hal-jessie"),
|
||||
DockerImage.objects.get(name="documentation-jessie"),
|
||||
DockerImage.objects.get(name="ngcp-panel-selenium"),
|
||||
DockerImage.objects.get(name="ngcp-panel-tests-rest-api-jessie"),
|
||||
DockerImage.objects.get(name="ngcp-panel-tests-selenium-jessie"),
|
||||
]
|
||||
|
||||
def test_images_with_tags(self):
|
||||
self.assertCountEqual(
|
||||
diobj.images_with_tags(),
|
||||
self.images_with_tags)
|
||||
DockerImage.objects.images_with_tags(), self.images_with_tags
|
||||
)
|
||||
|
||||
def test_project_images_with_tags(self):
|
||||
self.assertCountEqual(
|
||||
diobj.images_with_tags('data-hal'),
|
||||
[diobj.get(name='data-hal-jessie'), ])
|
||||
DockerImage.objects.images_with_tags("data-hal"),
|
||||
[DockerImage.objects.get(name="data-hal-jessie")],
|
||||
)
|
||||
self.assertCountEqual(
|
||||
DockerImage.objects.images_with_tags("ngcp-panel"),
|
||||
[
|
||||
DockerImage.objects.get(name="ngcp-panel-selenium"),
|
||||
DockerImage.objects.get(
|
||||
name="ngcp-panel-tests-rest-api-jessie"
|
||||
),
|
||||
DockerImage.objects.get(
|
||||
name="ngcp-panel-tests-selenium-jessie"
|
||||
),
|
||||
],
|
||||
)
|
||||
self.assertCountEqual(
|
||||
diobj.images_with_tags('ngcp-panel'),
|
||||
[diobj.get(name='ngcp-panel-selenium'),
|
||||
diobj.get(name='ngcp-panel-tests-rest-api-jessie'),
|
||||
diobj.get(name='ngcp-panel-tests-selenium-jessie'), ])
|
||||
self.assertCountEqual(diobj.images_with_tags('libtcap'), [])
|
||||
DockerImage.objects.images_with_tags("libtcap"), []
|
||||
)
|
||||
|
||||
def test_date(self):
|
||||
tag = DockerTag.objects.get(
|
||||
name='latest',
|
||||
image__name='ngcp-panel-tests-selenium-jessie')
|
||||
self.assertEqual(
|
||||
tag.date,
|
||||
datetime.datetime(2017, 6, 21, 16, 3, 37))
|
||||
name="latest", image__name="ngcp-panel-tests-selenium-jessie"
|
||||
)
|
||||
self.assertEqual(tag.date, datetime.datetime(2017, 6, 21, 16, 3, 37))
|
||||
|
@ -1,34 +1,37 @@
|
||||
# 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)
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
|
||||
JBI_BASEDIR = mkdtemp(dir=os.environ.get("RESULTS"))
|
||||
|
||||
@override_settings(JBI_BASEDIR=JBI_BASEDIR)
|
||||
class BaseTest(TestCase):
|
||||
|
||||
@override_settings(DEBUG=True, JBI_BASEDIR=JBI_BASEDIR)
|
||||
class BaseTest(TestCase):
|
||||
def setUp(self):
|
||||
from django.conf import settings
|
||||
|
||||
if not os.path.exists(settings.JBI_BASEDIR):
|
||||
os.makedirs(settings.JBI_BASEDIR)
|
||||
|
||||
def tearDown(self):
|
||||
from django.conf import settings
|
||||
|
||||
if os.path.exists(settings.JBI_BASEDIR):
|
||||
shutil.rmtree(settings.JBI_BASEDIR)
|
||||
|
@ -0,0 +1,47 @@
|
||||
# Copyright (C) 2020 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 unittest
|
||||
|
||||
from django.test import override_settings
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
class SettingsTest(SimpleTestCase):
|
||||
def test_debug_from_test(self):
|
||||
from ..settings.test import DEBUG
|
||||
|
||||
self.assertTrue(DEBUG)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_debug(self):
|
||||
from django.conf import settings
|
||||
|
||||
self.assertTrue(settings.DEBUG)
|
||||
|
||||
@override_settings(DEBUG=False)
|
||||
def test_debug_override(self):
|
||||
from django.conf import settings
|
||||
|
||||
self.assertFalse(settings.DEBUG)
|
||||
|
||||
def test_common_value_from_django(self):
|
||||
from django.conf import settings
|
||||
|
||||
self.assertEqual(settings.LANGUAGE_CODE, "en-us")
|
||||
|
||||
def test_common_value(self):
|
||||
from django.conf import settings
|
||||
|
||||
self.assertEqual(settings.JENKINS_TOKEN, "sipwise_jenkins_ci")
|
Loading…
Reference in new issue