Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Nov 22, 2021
1 parent 46e5a73 commit be64bb4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions esp/esp/program/modules/tests/testallviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from esp.customforms.DynamicModel import DynamicModelHandler
from esp.customforms.models import Form
from esp.middleware import ESPError
from esp.program.tests import ProgramFrameworkTest
from esp.program.models import ProgramModule
from esp.program.modules.base import ProgramModuleObj
Expand Down Expand Up @@ -149,19 +150,19 @@ def tearDown(self):
def testAllViews(self):
# Check all views of all modules
failed_modules = []
cls = self.program.classes()[0]
cls_id = str(cls.id)
sec = cls.get_sections()[0]
sec_id = str(sec.id)
event = self.program.getTimeSlots()[0]
event_id = str(event.id)
for tl in ['learn', 'teach', 'admin', 'volunteer']:
modules = self.program.getModules(tl = tl)
for module in modules:
views = module.get_all_views()
for view in views:
cls = self.program.classes()[0]
cls_id = str(cls.id)
sec = cls.get_sections()[0]
sec_id = str(sec.id)
event = self.program.getTimeSlots()[0]
event_id = str(event.id)
# In case the user has been unregistered, reregister them
self.program.classes()[0].get_sections()[0].preregister_student(self.adminUser)
sec.preregister_student(self.adminUser)
# Try a whole bunch of different requests (because different views have different expectations)
# Skip to the next view if this view ever properly serves a page (or redirects to another page)
try: # Various GET arguments
Expand All @@ -171,7 +172,7 @@ def testAllViews(self):
except Exception, e:
print(e)
try: # Use a class ID as the extra argument
response = self.client.get('/' + tl + '/' + self.program.getUrlBase() + '/' + view + '/' + cls_id + '?student=' + self.adminUser.id)
response = self.client.get('/' + tl + '/' + self.program.getUrlBase() + '/' + view + '/' + cls_id)
if str(response.status_code)[:1] in ['2', '3']:
continue
except Exception, e:
Expand All @@ -190,7 +191,7 @@ def testAllViews(self):
print(e)
try: # Various POST data
# Mostly used for registering for classes, so unregister for the class in advance
self.program.classes()[0].get_sections()[0].unpreregister_student(self.adminUser)
sec.unpreregister_student(self.adminUser)
response = self.client.post('/' + tl + '/' + self.program.getUrlBase() + '/' + view, {'class_id': cls_id, 'section_id': sec_id, 'json_data': '{}'})
if str(response.status_code)[:1] in ['2', '3']:
continue
Expand Down

0 comments on commit be64bb4

Please sign in to comment.