Compare commits

...

1 Commits

Author SHA1 Message Date
Hostea dashboard 0c52da08d6
feat: basic settings.py validation
ci/woodpecker/push/woodpecker Pipeline failed Details
2022-09-04 13:53:25 +05:30
4 changed files with 57 additions and 5 deletions

View File

@ -77,7 +77,9 @@ class LoginTest(TestCase):
Tests if login template renders
"""
resp = self.client.get(reverse("accounts.login"))
self.assertEqual(b"A free forge ecosystem for free developers" in resp.content, True)
self.assertEqual(
b"A free forge ecosystem for free developers" in resp.content, True
)
def test_login_works(self):
"""
@ -234,7 +236,9 @@ class RegistrationTest(TestCase):
Tests if register template renders
"""
resp = self.client.get(reverse("accounts.register"))
self.assertEqual(b"A free forge ecosystem for free developers." in resp.content, True)
self.assertEqual(
b"A free forge ecosystem for free developers." in resp.content, True
)
def test_register_works(self):
"""

View File

@ -24,8 +24,6 @@ from accounts.utils import gen_secret
from dash.models import Instance
from billing.utils import generate_invoice, payment_fullfilled
Application = get_application_model()
class Command(BaseCommand):
help = "Generate invoices, should be run from cronjob scheduled for daily execution"

View File

@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
from .utils import is_url, is_email
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -206,7 +208,7 @@ EMAIL_USE_SSL = False
EMAIL_PORT = 10025
EMAIL_HOST_USER = "admin"
EMAIL_HOST_PASSWORD = "password"
DEFAULT_FROM_EMAIL: "no-reply@hostea.org"
DEFAULT_FROM_EMAIL = "no-reply@hostea.org"
try:
from dashboard.local_settings import *
@ -214,3 +216,14 @@ try:
print("Found local_settings")
except ModuleNotFoundError:
pass
def verifiy_settings():
assert is_url(HOSTEA["META"]["GITEA_INSTANCE"])
assert is_url(PAYMENT_HOST)
assert is_email(DEFAULT_FROM_EMAIL)
assert is_email(HOSTEA["INSTANCE_MAINTAINER_CONTACT"])
verifiy_settings()

37
dashboard/utils.py Normal file
View File

@ -0,0 +1,37 @@
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.core.validators import URLValidator, EmailValidator
def is_url(val: str) -> bool:
"""
Validate if the given value is a URL
"""
try:
URLValidator()(val)
except:
return False
return True
def is_email(val: str) -> bool:
"""
Validate if the given value is an email
"""
try:
EmailValidator()(val)
except:
return False
return True