From 7647cfcc48688c8bd68955226de41ad6c7078820 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Sun, 22 Mar 2020 11:23:20 +0100 Subject: [PATCH] TT#43813 hotfix: split settings per application Using https://django-appconf.readthedocs.io/en/latest/ helps us to keep configs per application Change-Id: Id41f0f6ce6b008428a1136f85ecf3b9d86f3189f --- hotfix/conf.py | 24 ++++++++++++++++++++++++ hotfix/models.py | 18 +++++++----------- hotfix/test/test_conf.py | 27 +++++++++++++++++++++++++++ repoapi/settings/common.py | 2 -- 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 hotfix/conf.py create mode 100644 hotfix/test/test_conf.py diff --git a/hotfix/conf.py b/hotfix/conf.py new file mode 100644 index 0000000..a8f0ab6 --- /dev/null +++ b/hotfix/conf.py @@ -0,0 +1,24 @@ +# 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 . +from django.conf import settings # noqa +from appconf import AppConf + + +class HotfixConf(AppConf): + WF_REGEX = r"TT#(\d+)" + ARTIFACT = "debian_changelog.txt" + + class Meta: + prefix = "hotfix" diff --git a/hotfix/models.py b/hotfix/models.py index ea6fa9b..6e4111b 100644 --- a/hotfix/models.py +++ b/hotfix/models.py @@ -1,24 +1,24 @@ # 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 . -import logging import re from django.db import models -logger = logging.getLogger(__name__) -workfront_re = re.compile(r"TT#(\d+)") +from .conf import settings + +workfront_re = re.compile(settings.HOTFIX_WF_REGEX) class WorkfrontNoteInfo(models.Model): @@ -27,11 +27,7 @@ class WorkfrontNoteInfo(models.Model): version = models.CharField(max_length=50, null=False) class Meta: - unique_together = [ - "workfront_id", - "projectname", - "version" - ] + unique_together = ["workfront_id", "projectname", "version"] @staticmethod def getIds(change): diff --git a/hotfix/test/test_conf.py b/hotfix/test/test_conf.py new file mode 100644 index 0000000..1e01ff7 --- /dev/null +++ b/hotfix/test/test_conf.py @@ -0,0 +1,27 @@ +# 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 . +from django.test import TestCase + + +class TestHotfixConf(TestCase): + def test_django_settings(self): + from django.conf import settings + + self.assertEqual(settings.HOTFIX_ARTIFACT, "debian_changelog.txt") + + def test_hotfix_settings(self): + from hotfix.conf import settings + + self.assertEqual(settings.HOTFIX_ARTIFACT, "debian_changelog.txt") diff --git a/repoapi/settings/common.py b/repoapi/settings/common.py index 0abdd6f..9523902 100644 --- a/repoapi/settings/common.py +++ b/repoapi/settings/common.py @@ -135,5 +135,3 @@ CELERY_TASK_SERIALIZER = "json" CELERY_RESULT_SERIALIZER = "json" CELERY_ACCEPT_CONTENT = ["json"] CELERY_RESULT_BACKEND = "django-db" - -HOTFIX_ARTIFACT = "debian_changelog.txt"