def test_language_header_and_url(self, course_key):
        expected_url = 'https://dummy-marketing.com/api/marketing/courses/{}'.format(
            course_key)

        with mock_requests_get() as mocked_get:
            helpers.get_marketing_data(course_key, 'eo')
            self.assertEquals(mocked_get.call_count,
                              1)  # Should be called once
            mocked_get.assert_called_once_with(
                url=expected_url, headers={'Accept-Language': 'eo'})
 def test_course_found_no_warning(self, warning):
     with mock_requests_get(status_code=200,
                            body_json={'name': 'My Course'}):
         course = helpers.get_marketing_data('course-v1:edX+Demo+2014',
                                             'ar')
         self.assertTrue(course)  # Should return nothing!
         self.assertEquals(0,
                           warning.call_count)  # Should NOT log a warning!
Exemple #3
0
    def get_serializer_context(self):
        context = super(CourseDetailView, self).get_serializer_context()
        if is_marketing_api_enabled():
            context['marketing_data'] = get_marketing_data(
                course_key=self.kwargs['course_key_string'],
                language=self.request.LANGUAGE_CODE,
            )

        return context
 def test_valid_response(self):
     with mock_requests_get(status_code=200,
                            body_json={'name': 'My Course'}):
         course = helpers.get_marketing_data('course-v1:edX+Demo+2014',
                                             'ar')
         self.assertIsInstance(
             course, dict)  # Sanity check: Should return a dictionary
         self.assertDictEqual(
             course,
             {'name': 'My Course'
              })  # Should return the JSON provided by the marketing API
 def assertCourseNotFoundWarning(self):
     with mock_requests_get(status_code=404,
                            body_json={'name': 'My Course'}):
         course = helpers.get_marketing_data('course-v1:edX+Demo+2014',
                                             'ar')
         self.assertFalse(course)  # Should return nothing!