Skip to content

Commit

Permalink
Merge pull request #9 from fblacklight-organization/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
aottr authored Apr 13, 2024
2 parents 2f4f29d + 8fa1ec3 commit b4524d0
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 3,876 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,35 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies
run: |
poetry install
- name: Run tests
env:
SECRET_KEY: 'asdf'
DEBUG: 'True'
ALLOWED_HOSTS: 'localhost'
run: |
poetry run python manage.py test
build:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write # might need to use PAT instead
Expand Down
4 changes: 2 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def get_template(cls, event, language='en'):
template = cls.objects.filter(event=event, language='en').first()
return template

def send_mail(self, to, context):
def send_mail(self, to_list: list[str], context):
try:
send_mail(
self.subject.format(**context),
self.content.format(**context),
settings.DEFAULT_FROM_EMAIL,
[to],
to_list,
fail_silently=False,
)
except Exception as e:
Expand Down
107 changes: 106 additions & 1 deletion core/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,108 @@
from django.test import TestCase
from django.contrib.auth.models import Group
from django.urls import reverse
from .utils.initial_data import populate_groups
from .utils.general import sainitize_username
from .models import PawUser
from django.conf import settings

# Create your tests here.

class PopulateGroupTestCase(TestCase):
def setUp(self):
populate_groups(None, None)

def test_groups_created(self):
self.assertEqual(Group.objects.count(), 2)
self.assertEqual(Group.objects.filter(name="Client").count(), 1)
self.assertEqual(Group.objects.filter(name="Supporter").count(), 1)

class UsernameSainitizationTestCase(TestCase):
def test_sainitize_username(self):
self.assertEqual(sainitize_username("test"), "test")
self.assertEqual(sainitize_username("test !!"), "test")

class LoginViewTestCase(TestCase):
def setUp(self):
self.username = "testuser"
self.password = "testpassword"
self.user = PawUser.objects.create_user(username=self.username, password=self.password)

def test_login_view(self):
url = reverse("login")
response = self.client.post(url, {"username": self.username, "password": self.password})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse("home"))

def test_login_view_invalid(self):
url = reverse("login")
response = self.client.post(url, {"username": self.username, "password": "invalid"})
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Please enter a correct username and password")

def test_user_language(self):
url = reverse("home")
self.client.force_login(self.user)
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.client.cookies.load(response.cookies)
self.assertEqual(self.client.cookies[settings.LANGUAGE_COOKIE_NAME].value, self.user.language)
self.assertEqual(response.url, reverse("all_tickets"))

class RegisterViewTestCase(TestCase):

def test_register_view(self):
url = reverse("register")
response = self.client.post(url, {"username": "test", "email": "[email protected]", "password": "testtesttesttest", "password_confirm": "testtesttesttest"})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse("login"))
self.assertEqual(PawUser.objects.count(), 1)
user = PawUser.objects.first()
self.assertEqual(user.username, "test")
self.assertEqual(user.email, "[email protected]")
self.assertTrue(user.check_password("testtesttesttest"))
self.assertEqual(user.groups.count(), 0) # No group assigned, might want to give Client group by default

def test_register_view_password_too_short(self):
url = reverse("register")
response = self.client.post(url, {"username": "test", "email": "[email protected]", "password": "123456789", "password_confirm": "123456789"})
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Password must be at least 10 characters long.")

def test_register_view_password_mismatch(self):
url = reverse("register")
response = self.client.post(url, {"username": "test", "email": "[email protected]", "password": "1234567890", "password_confirm": "123456789"})
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Password and Confirm Password do not match.")

class SettingsViewTestCase(TestCase):

def test_settings_view(self):
url = reverse("settings")
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "%s?next=%s" % (reverse("login"), reverse("settings")))

user = PawUser.objects.create_user(username="test", password="testtesttesttest", email="[email protected]")
self.client.force_login(user)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Settings")

response = self.client.post(url, {"language": "fr", "email": "[email protected]"})
self.assertEqual(response.status_code, 200)
user.refresh_from_db()
self.assertEqual(user.language, "fr")
self.client.cookies.load(response.cookies)
self.assertEqual(self.client.cookies[settings.LANGUAGE_COOKIE_NAME].value, "fr")

response = self.client.post(url, {"language": "invalid", "email": "[email protected]"})
self.assertEqual(response.status_code, 200)
self.client.cookies.load(response.cookies)
self.assertEqual(self.client.cookies[settings.LANGUAGE_COOKIE_NAME].value, "fr")

response = self.client.post(url, {"language": "en", "email": "[email protected]"})
self.assertEqual(response.status_code, 200)
user.refresh_from_db()
self.assertEqual(user.language, "en")
self.client.cookies.load(response.cookies)
self.assertEqual(self.client.cookies[settings.LANGUAGE_COOKIE_NAME].value, "en")
2 changes: 1 addition & 1 deletion paw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import get_version

PAW_VERSION = (0, 5, 10, "final", 0)
PAW_VERSION = (0, 5, 11, "final", 0)
FBL_ITERATION = 4

__version__ = f"{get_version(PAW_VERSION)}-fbl{FBL_ITERATION}"
Binary file modified paw/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
8 changes: 4 additions & 4 deletions paw/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ msgstr ""

#: paw/settings.py:133
msgid "English"
msgstr ""
msgstr "English"

#: paw/settings.py:134
msgid "French"
msgstr ""
msgstr "Français"

#: paw/settings.py:135
msgid "German"
msgstr ""
msgstr "Deutsch"

#: paw/settings.py:136
msgid "Dutch"
msgstr ""
msgstr "Nederlands"

#: paw/templates/base.html:20 paw/templates/dashboard_base.html:40
msgid "Tickets"
Expand Down
Binary file modified paw/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion paw/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ msgstr "Deutsch"

#: paw/settings.py:136
msgid "Dutch"
msgstr ""
msgstr "Nederlands"

#: paw/templates/base.html:20 paw/templates/dashboard_base.html:40
msgid "Tickets"
Expand Down
Binary file modified paw/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
10 changes: 5 additions & 5 deletions paw/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ msgstr "Utilisateur Google SSO"

#: paw/settings.py:133
msgid "English"
msgstr "Anglais"
msgstr "English"

#: paw/settings.py:134
msgid "French"
msgstr "Français"

#: paw/settings.py:135
msgid "German"
msgstr "Allemand"
msgstr "Deutsch"

#: paw/settings.py:136
msgid "Dutch"
msgstr ""
msgstr "Nederlands"

#: paw/templates/base.html:20 paw/templates/dashboard_base.html:40
msgid "Tickets"
Expand Down Expand Up @@ -274,7 +274,7 @@ msgstr "Ajouter un commentaire"

#: paw/templates/ticketing/ticket_detail.html:98
msgid "Close Ticket"
msgstr "Nouveau ticket"
msgstr "Fermer"

#: paw/templates/ticketing/ticket_detail.html:107
msgid "Make this an internal comment"
Expand Down Expand Up @@ -340,7 +340,7 @@ msgstr "pour"
#: paw/templates/ticketing/tickets.html:18
#: paw/templates/ticketing/tickets_history.html:18
msgid "Assigned to"
msgstr "Me l'attribuer"
msgstr "Attribué à"

#: paw/templates/ticketing/tickets.html:27
#: paw/templates/ticketing/tickets_history.html:27
Expand Down
Binary file modified paw/locale/nl/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions paw/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ msgstr "Google SSO Gebruiker"

#: paw/settings.py:133
msgid "English"
msgstr "Engels"
msgstr "English"

#: paw/settings.py:134
msgid "French"
msgstr "Frans"
msgstr "Français"

#: paw/settings.py:135
msgid "German"
msgstr "Duits"
msgstr "Deutsch"

#: paw/settings.py:136
msgid "Dutch"
Expand Down
Loading

0 comments on commit b4524d0

Please sign in to comment.