Skip to content

Commit

Permalink
test: get view
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperhodge committed Jan 15, 2025
1 parent 4a2c148 commit 170a438
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cms.djangoapps.contentstore.tests.test_utils import AuthorizeStaffTestCase
from common.djangoapps.student.tests.factories import InstructorFactory
from rest_framework import status
from django.test import TestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
Expand All @@ -13,10 +14,29 @@ def test_inherited(self):
pass

def make_request(self, course_id=None, data=None):
return self.client.get(self.get_url(course_id), data)
url = self.get_url(self.course.id)
print('make_request url: ', url)
response = self.client.get(url, data)
print('make_request response status code: ', response.status_code)
print('make_request response content: ', response.content)
return response

def get_url(self, course_key):
return reverse(
url = reverse(
'cms.djangoapps.contentstore:v0:link_check_status',
kwargs={'course_id': 'course-v1:someOrg+someCourse+someRun'}
kwargs={'course_id': self.course.id}
)
print('get_url: ', url)
return url

def test_course_instructor(self, expect_status=status.HTTP_200_OK):
self.course_instructor = InstructorFactory(
username='instructor',
password=self.password,
course_key=self.course.id,
)
self.client.login(username=self.course_instructor.username, password=self.password)
response = self.make_request()
print('test_course_instructor response status code: ', response.status_code)
assert response.status_code == expect_status
return response
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def get(self, request: Request, course_id: str):
"""
course_key = CourseKey.from_string(course_id)
if not has_course_author_access(request.user, course_key):
print('missing course author access')
self.permission_denied(request)

task_status = _latest_task_status(request, course_id)
Expand Down Expand Up @@ -183,8 +184,8 @@ def get(self, request: Request, course_id: str):
# Wasn't JSON, just use the value as a string
pass

# print('DTO')
# print(broken_links_dto)
print('DTO')
print(broken_links_dto)

# mock dto for testing
# broken_links_dto = {
Expand Down Expand Up @@ -225,8 +226,9 @@ def get(self, request: Request, course_id: str):
**({'LinkCheckError': error} if error else {})
}

print('data', data)
serializer = LinkCheckSerializer(data=data)
serializer.is_valid(raise_exception=True)
serializer.is_valid(raise_exception=False)

return Response(serializer.data)

Expand Down
6 changes: 2 additions & 4 deletions cms/djangoapps/contentstore/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def test_register_exams_failure(self, _mock_register_exams_proctoring, _mock_reg
course_publish.assert_called()


class CourseOptimizerTestCase(TestCase):


class CourseOptimizerTest(TestCase):
def test_user_does_not_exist_raises_exception(self):
raise NotImplementedError

Expand Down Expand Up @@ -265,4 +263,4 @@ def test_max_number_of_retries_is_respected(self):
raise NotImplementedError

def test_scan_generates_file_named_by_course_key(self):
raise NotImplementedErro
raise NotImplementedError
1 change: 1 addition & 0 deletions openedx/core/lib/api/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def _decorator(func_or_class):
SessionAuthenticationAllowInactiveUser
)
func_or_class.permission_classes = ()
print('is_authenticated', is_authenticated)
if is_authenticated:
func_or_class.permission_classes += (IsAuthenticated,)
if is_user:
Expand Down

0 comments on commit 170a438

Please sign in to comment.