Skip to content

Commit

Permalink
LTI 1.3: Fix trailing slashes behavior in tests
Browse files Browse the repository at this point in the history
The changed behavior on trailing slashes caused some of the tests
to break.
  • Loading branch information
PasiSa committed Apr 14, 2023
1 parent 966fbda commit 3b216f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
10 changes: 9 additions & 1 deletion api/urls_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ class AplusRouter(ExtendedDefaultRouter):
routes[0].mapping['delete'] = 'destroy_many'

def __init__(self):
# TODO: try to verify that the trailing_slash trick does not break any existing links and routes.
# The following causes URLs to be routed either with or without the trailing slash.
# It is needed, because LTI 1.3 specifies some URLs that do not have trailing slash,
# but Django (and A+) default behavior automatically assumes the trailing slash,
# and some of the existing links to A+ material might assume this as well.
# The side effect of this change is, that the reverse URLs for APIs now appear
# without trailing slash, while before it was included in URL. Therefore the
# comparisons in some of the API unit tests needed to be fixed, but calling the
# API URLs in existing implementations should work without modifications, because
# both URL variants are routed.
super().__init__()
self.trailing_slash = '/?'

Expand Down
8 changes: 4 additions & 4 deletions course/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ def test_get_courselist(self):
results = [
{
'id': 1,
'url': 'http://testserver/api/v2/courses/1/',
'url': 'http://testserver/api/v2/courses/1',
'html_url': 'http://testserver/Course-Url/T-00.1000_d0/',
'code': '123456',
'name': 'test course',
'instance_name': 'Fall 2011 day 0'
},
{
'id': 2,
'url': 'http://testserver/api/v2/courses/2/',
'url': 'http://testserver/api/v2/courses/2',
'html_url': 'http://testserver/Course-Url/T-00.1000_d1/',
'code': '123456',
'name': 'test course',
'instance_name': 'Fall 2011 day 1'
},
{
'id': 3,
'url': 'http://testserver/api/v2/courses/3/',
'url': 'http://testserver/api/v2/courses/3',
'html_url': 'http://testserver/Course-Url/T-00.1000_d2/',
'code': '123456',
'name': 'test course',
'instance_name': 'Fall 2011 day 2'
},
{
'id': 4,
'url': 'http://testserver/api/v2/courses/4/',
'url': 'http://testserver/api/v2/courses/4',
'html_url': 'http://testserver/Course-Url/T-00.1000_hidden/',
'code': '123456',
'name': 'test course',
Expand Down
10 changes: 5 additions & 5 deletions userprofile/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ def test_get_userlist(self):

results = [
{'id': 101,
'url': 'http://testserver/api/v2/users/101/',
'url': 'http://testserver/api/v2/users/101',
'username': 'testUser',
'student_id': '12345X',
'email': 'test@aplus.com',
'full_name': 'Superb Student',
'is_external': False},
{'id': 102,
'url': 'http://testserver/api/v2/users/102/',
'url': 'http://testserver/api/v2/users/102',
'username': 'grader',
'student_id': '67890Y',
'email': 'grader@aplus.com',
'full_name': 'Grumpy Grader',
'is_external': False},
{'id': 103,
'url': 'http://testserver/api/v2/users/103/',
'url': 'http://testserver/api/v2/users/103',
'username': 'teacher',
'student_id': None,
'email': 'teacher@aplus.com',
'full_name': 'Tedious Teacher',
'is_external': True},
{'id': 104,
'url': 'http://testserver/api/v2/users/104/',
'url': 'http://testserver/api/v2/users/104',
'username': 'superuser',
'student_id': None,
'email': 'superuser@aplus.com',
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_get_userdetail(self):
response = client.get('/api/v2/users/101/')
self.assertEqual(response.data, {
'id': 101,
'url': 'http://testserver/api/v2/users/101/',
'url': 'http://testserver/api/v2/users/101',
'username':'testUser',
'student_id':'12345X',
'is_external': False,
Expand Down

0 comments on commit 3b216f8

Please sign in to comment.