Skip to content

Commit

Permalink
split urls into 2 files, added i18n_patterns, affected test files are…
Browse files Browse the repository at this point in the history
… changed accordingly
  • Loading branch information
4-dash committed Oct 24, 2024
1 parent 54f862d commit 8732227
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 201 deletions.
6 changes: 4 additions & 2 deletions src/feedback/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding=utf-8

from django.utils.translation import get_language

#TODO: Aufruf einzelner Tests möglich machen

def suite():
Expand All @@ -23,8 +25,8 @@ def suite():
suite.addTest(unittest.TestLoader().loadTestsFromName(test_module))
return suite

LOGIN_END = '/intern/'
INDEX_END = '/intern/uebersicht/'
LOGIN_END = f'/{get_language()}/intern/'
INDEX_END = f'/{get_language()}/intern/uebersicht/'
TESTSERVER_BEGIN = ''
LOGIN_URL = TESTSERVER_BEGIN+LOGIN_END
INDEX_URL = TESTSERVER_BEGIN+INDEX_END
6 changes: 4 additions & 2 deletions src/feedback/tests/redirect_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from django.urls import re_path
from feedback.views import redirect
from django.conf.urls.i18n import i18n_patterns

urlpatterns = [

urlpatterns = i18n_patterns(
re_path(r'^redirect/$', redirect,
{'redirect_to': 'http://www.d120.de/'}),
re_path(r'^redirect/(?P<tail>.*)$', redirect,
{'redirect_to': 'http://www.d120.de/'}),
]
)
3 changes: 2 additions & 1 deletion src/feedback/tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from feedback.models import Semester, Person, Veranstaltung, Fragebogen2009, Mailvorlage
from feedback.tests.tools import NonSuTestMixin, get_veranstaltung
from django.utils.translation import get_language

@tag('latex')
class GenerateLettersTest(NonSuTestMixin, TestCase):
Expand All @@ -29,7 +30,7 @@ def setUp(self):
except OSError:
return self.skipTest("OSError while looking for pdflatex")

self.path = '/intern/generate_letters/'
self.path = f'/{get_language()}/intern/generate_letters/'
try:
self.orig_contents = self._get_erhebungswoche()
except IOError:
Expand Down
3 changes: 2 additions & 1 deletion src/feedback/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from feedback.tests.tools import get_veranstaltung
from django.urls import reverse
from django.contrib.auth.models import User
from django.utils.translation import get_language


class InitTest(TestCase):
Expand Down Expand Up @@ -501,7 +502,7 @@ def test_veranstalter_url(self):
self.assertEqual(len(url_parts), 2)
ver_id = self.v[0].id
self.assertEqual(url_parts[0],
'https://www.fachschaft.informatik.tu-darmstadt.de/veranstalter/login/?vid=%d' % ver_id)
f'https://www.fachschaft.informatik.tu-darmstadt.de/{get_language()}/veranstalter/login/?vid={ver_id}')
access_token = self.v[0].access_token
self.assertEqual('token=' + access_token, url_parts[1])
# FIXME: Is the below assert necessary? Since Python3 strings are all Unicode
Expand Down
25 changes: 13 additions & 12 deletions src/feedback/tests/test_views_intern.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from feedback.models import Semester, Person, Veranstaltung, Fragebogen2009, Mailvorlage, \
Fachgebiet, FachgebietEmail, Tutor, EmailEndung
from feedback.tests.tools import NonSuTestMixin, get_veranstaltung
from django.utils.translation import get_language

from feedback import tests

Expand All @@ -24,7 +25,7 @@ def setUp(self):
self.s, self.v = get_veranstaltung('vu')

def test_close_order_bestellung_liegt_vor_post(self):
path = '/intern/status_final/'
path = f'/{get_language()}/intern/status_final/'
self.v.status = Veranstaltung.STATUS_BESTELLUNG_LIEGT_VOR
self.v.save()

Expand All @@ -35,7 +36,7 @@ def test_close_order_bestellung_liegt_vor_post(self):
self.assertEqual(self.v.status, Veranstaltung.STATUS_BESTELLUNG_WIRD_VERARBEITET)

def test_close_order_keine_evaluation_post(self):
path = '/intern/status_final/'
path = f'/{get_language()}/intern/status_final/'
self.v.status = Veranstaltung.STATUS_KEINE_EVALUATION
self.v.save()

Expand All @@ -46,7 +47,7 @@ def test_close_order_keine_evaluation_post(self):
self.assertEqual(self.v.status, Veranstaltung.STATUS_KEINE_EVALUATION_FINAL)

def test_close_order_status_angelegt_post(self):
path = '/intern/status_final/'
path = f'/{get_language()}/intern/status_final/'
self.v.status = Veranstaltung.STATUS_ANGELEGT
self.v.save()

Expand All @@ -57,7 +58,7 @@ def test_close_order_status_angelegt_post(self):
self.assertEqual(self.v.status, Veranstaltung.STATUS_KEINE_EVALUATION_FINAL)

def test_close_order_bestellung_geoeffnet_post(self):
path = '/intern/status_final/'
path = f'/{get_language()}/intern/status_final/'
self.v.status = Veranstaltung.STATUS_BESTELLUNG_GEOEFFNET
self.v.save()

Expand All @@ -68,7 +69,7 @@ def test_close_order_bestellung_geoeffnet_post(self):
self.assertEqual(self.v.status, Veranstaltung.STATUS_KEINE_EVALUATION_FINAL)

def test_close_order_refuse(self):
path = '/intern/status_final/'
path = f'/{get_language()}/intern/status_final/'
self.v.status = Veranstaltung.STATUS_BESTELLUNG_LIEGT_VOR
self.v.save()

Expand All @@ -92,7 +93,7 @@ def test_index(self):
self.assertEqual(response.context['cur_semester'], s)

def test_fragebogensprache(self):
path = '/intern/fragebogensprache/'
path = f'/{get_language()}/intern/fragebogensprache/'
self.do_non_su_test(path)
self.client.login(username='supers', password='pw')

Expand All @@ -102,7 +103,7 @@ def test_fragebogensprache(self):
self.assertEqual(response.templates[0].name, 'intern/fragebogensprache.html')

def test_export_veranstaltungen_get(self):
path = '/intern/export_veranstaltungen/'
path = f'/{get_language()}/intern/export_veranstaltungen/'
self.do_non_su_test(path)
self.client.login(username='supers', password='pw')

Expand All @@ -118,7 +119,7 @@ def checkXMLEqual(self, xml1, xml2):
self.assertEqual(xml1, xml2)

def test_export_veranstaltungen_post(self):
path = '/intern/export_veranstaltungen/'
path = f'/{get_language()}/intern/export_veranstaltungen/'
self.client.login(username='supers', password='pw')
self.client.login(username='supers', password='pw')

Expand Down Expand Up @@ -343,7 +344,7 @@ def test_export_veranstaltungen_post(self):


def test_export_veranstaltungen_post_primaerdozent(self):
path = '/intern/export_veranstaltungen/'
path = f'/{get_language()}/intern/export_veranstaltungen/'
self.client.login(username='supers', password='pw')

s, v = get_veranstaltung('v')
Expand Down Expand Up @@ -441,7 +442,7 @@ def test_export_veranstaltungen_post_primaerdozent(self):
class ImportErgebnisseTest(NonSuTestMixin, TestCase):
def setUp(self):
super(ImportErgebnisseTest, self).setUp()
self.path = '/intern/import_ergebnisse/'
self.path = f'/{get_language()}/intern/import_ergebnisse/'
self.s = Semester.objects.create(semester=20110, fragebogen='2009', sichtbarkeit='ADM')

def test_get(self):
Expand Down Expand Up @@ -485,7 +486,7 @@ def test_post(self):
class SyncErgebnisseTest(NonSuTestMixin, TestCase):
def setUp(self):
super(SyncErgebnisseTest, self).setUp()
self.path = '/intern/sync_ergebnisse/'
self.path = f'/{get_language()}/intern/sync_ergebnisse/'
self.s, self.v = get_veranstaltung('v')

def test_get(self):
Expand Down Expand Up @@ -520,7 +521,7 @@ def test_post(self):


class SendmailTest(NonSuTestMixin, TestCase):
path = '/intern/sendmail/'
path = f'/{get_language()}/intern/sendmail/'

def test_get(self):
self.do_non_su_test(self.path)
Expand Down
9 changes: 5 additions & 4 deletions src/feedback/tests/test_views_intern_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from feedback.tests.tools import NonSuTestMixin, get_veranstaltung
from feedback import tests
from feedback.models import Veranstaltung
from django.utils.translation import get_language


class InternAuthTest(NonSuTestMixin, TestCase):
Expand All @@ -33,7 +34,7 @@ def test_login_debug_auth(self):
self.assertEqual(response['Location'], tests.INDEX_URL)

def test_rechte_uebernehmen(self):
path = '/intern/rechte_uebernehmen/'
path = f'/{get_language()}/intern/rechte_uebernehmen/'
self.do_non_su_test(path)

self.assertTrue(self.client.login(username='supers', password='pw'))
Expand All @@ -52,15 +53,15 @@ def test_rechte_uebernehmen(self):

def test_rechte_zuruecknehmen(self):
self.client.login(username='supers', password='pw')
self.client.post('/intern/rechte_uebernehmen/', {'vid': self.v.id}, **{'REMOTE_USER': 'super'})
self.client.post(f'/{get_language()}/intern/rechte_uebernehmen/', {'vid': self.v.id}, **{'REMOTE_USER': 'super'})

response = self.client.get('/intern/rechte_zuruecknehmen/', **{'REMOTE_USER': 'super'})
response = self.client.get(f'/{get_language()}/intern/rechte_zuruecknehmen/', **{'REMOTE_USER': 'super'})
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], tests.INDEX_URL)

def test_rechte_zuruecknehmen_no_origin_uid(self):
"""Es sollen rechte wiederhergestellt werden die vorher nicht abgegebn wurden"""
self.assertTrue(self.client.login(username='supers', password='pw'))
response = self.client.get('/intern/rechte_zuruecknehmen/', **{'REMOTE_USER': 'super'})
response = self.client.get(f'/{get_language()}/intern/rechte_zuruecknehmen/', **{'REMOTE_USER': 'super'})
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].split('?')[0].endswith(tests.INDEX_END))
9 changes: 5 additions & 4 deletions src/feedback/tests/test_views_intern_vv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from feedback.forms import UploadFileForm
from feedback.models import Semester, ImportCategory, ImportVeranstaltung, ImportPerson, Person
from feedback.tests.tools import NonSuTestMixin, get_veranstaltung
from django.utils.translation import get_language

from feedback import tests


class InternVvTest(NonSuTestMixin):
def test_import_vv(self):
path = '/intern/import_vv/'
path = f'/{get_language()}/intern/import_vv/'
self.do_non_su_test(path)

self.assertTrue(self.client.login(username='supers', password='pw'))
Expand All @@ -32,7 +33,7 @@ def test_import_vv(self):
self.assertTrue(response['Location'].endswith('/intern/import_vv_edit/'))

def test_import_vv_edit_get(self):
path = '/intern/import_vv_edit/'
path = f'/{get_language()}/intern/import_vv_edit/'
self.do_non_su_test(path)

self.client.login(username='supers', password='pw')
Expand All @@ -57,7 +58,7 @@ def test_import_vv_edit_post(self):
iv1_sub = ImportVeranstaltung.objects.create(typ='vu', name='Bla II', category=ic_sub)

self.client.login(username='supers', password='pw')
path = '/intern/import_vv_edit/'
path = f'/{get_language()}/intern/import_vv_edit/'

# kein Semester angegeben
response = self.client.post(path, {'v': [iv0.id, iv1.id, iv1_sub.id]}, **{'REMOTE_USER': 'super'})
Expand All @@ -79,7 +80,7 @@ def test_import_vv_edit_post(self):
class InternVvEditUsersTest(NonSuTestMixin, TestCase):
def setUp(self):
super(InternVvEditUsersTest, self).setUp()
self.path = '/intern/import_vv_edit_users/'
self.path = f'/{get_language()}/intern/import_vv_edit_users/'

self.p0 = Person.objects.create(vorname='Je', nachname='Mand')
self.p1 = Person.objects.create(vorname='Auch Je', nachname='Mand')
Expand Down
Loading

0 comments on commit 8732227

Please sign in to comment.