예제 #1
0
    def test_get_course_content(self, mock_sailthru_client):
        """
        test routine which fetches data from Sailthru content api
        """
        config = {'SAILTHRU_CACHE_TTL_SECONDS': 100}
        mock_sailthru_client.api_get.return_value = MockSailthruResponse(
            {"title": "The title"})
        response_json = _get_course_content('course:123', mock_sailthru_client,
                                            None, config)
        self.assertEquals(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_called_with(
            'content', {'id': 'course:123'})

        # test second call uses cache
        mock_sailthru_client.reset_mock()
        response_json = _get_course_content('course:123', mock_sailthru_client,
                                            None, config)
        self.assertEquals(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_not_called()

        # test error from Sailthru
        mock_sailthru_client.api_get.return_value = MockSailthruResponse(
            {}, error='Got an error')
        self.assertEquals(
            _get_course_content('course:124', mock_sailthru_client, None,
                                config), {})

        # test exception
        mock_sailthru_client.api_get.side_effect = SailthruClientError
        self.assertEquals(
            _get_course_content('course:125', mock_sailthru_client, None,
                                config), {})
예제 #2
0
    def test_get_course_content(self, mock_sailthru_client):
        """
        test routine which fetches data from Sailthru content api
        """
        config = {'SAILTHRU_CACHE_TTL_SECONDS': 100}
        mock_sailthru_client.api_get.return_value = MockSailthruResponse(
            {"title": "The title"})
        response_json = _get_course_content(self.course_id, 'course:123',
                                            mock_sailthru_client, None, config)
        self.assertEqual(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_called_with(
            'content', {'id': 'course:123'})

        # test second call uses cache
        mock_sailthru_client.reset_mock()
        response_json = _get_course_content(self.course_id, 'course:123',
                                            mock_sailthru_client, None, config)
        self.assertEqual(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_not_called()

        # test error from Sailthru
        mock_sailthru_client.api_get.return_value = MockSailthruResponse(
            {}, error='Got an error')
        data = self.ecom_course_data(self.course_id)
        expected_response = {
            'title': 'test course',
            'verification_deadline': '2016-12-01T23:59:00Z'
        }
        self.mock_ecommerce_api(data, self.course_id)
        self.assertEqual(
            _get_course_content(self.course_id, 'course:124',
                                mock_sailthru_client, None, config),
            expected_response)

        # test Sailthru exception
        data = self.ecom_course_data(self.course_id)
        expected_response = {
            'title': 'test course',
            'verification_deadline': '2016-12-01T23:59:00Z'
        }
        mock_sailthru_client.api_get.side_effect = SailthruClientError
        self.mock_ecommerce_api(data, self.course_id)
        self.assertEqual(
            _get_course_content(self.course_id, 'course:125',
                                mock_sailthru_client, None, config),
            expected_response)

        # test Sailthru and Ecommerce exception
        mock_sailthru_client.api_get.side_effect = SailthruClientError
        self.mock_ecommerce_api({}, self.course_id2, status=500)
        self.assertEqual(
            _get_course_content(self.course_id2, 'course:126',
                                mock_sailthru_client, None, config), {})
예제 #3
0
    def test_get_course_content(self, mock_sailthru_client):
        """
        test routine which fetches data from Sailthru content api
        """
        config = {'SAILTHRU_CACHE_TTL_SECONDS': 100}
        mock_sailthru_client.api_get.return_value = MockSailthruResponse({"title": "The title"})
        response_json = _get_course_content('course:123', mock_sailthru_client, None, config)
        self.assertEquals(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_called_with('content', {'id': 'course:123'})

        # test second call uses cache
        mock_sailthru_client.reset_mock()
        response_json = _get_course_content('course:123', mock_sailthru_client, None, config)
        self.assertEquals(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_not_called()

        # test error from Sailthru
        mock_sailthru_client.api_get.return_value = MockSailthruResponse({}, error='Got an error')
        self.assertEquals(_get_course_content('course:124', mock_sailthru_client, None, config), {})

        # test exception
        mock_sailthru_client.api_get.side_effect = SailthruClientError
        self.assertEquals(_get_course_content('course:125', mock_sailthru_client, None, config), {})