Beispiel #1
0
    def test_get_programs_caching(self):
        """ Verify that when the value is set, the cache is used for getting
        programs.
        """
        self.mock_programs_api()

        # hit the Programs API twice
        for _ in range(2):
            get_programs()

        # verify that only one request has been made
        self.assertEqual(len(httpretty.httpretty.latest_requests), 1)
Beispiel #2
0
    def test_get_programs_caching(self):
        """ Verify that when the value is set, the cache is used for getting
        programs.
        """
        self.mock_programs_api()

        # hit the Programs API twice
        for _ in range(2):
            get_programs()

        # verify that only one request has been made
        self.assertEqual(len(httpretty.httpretty.latest_requests), 1)
Beispiel #3
0
 def test_get_programs_client_initialization_failure(self, mock_init):
     """
     Verify the behavior when API client fails to initialize.
     """
     mock_init.side_effect = Exception
     actual_programs_api_response = get_programs()
     self.assertEqual(actual_programs_api_response, [])
     self.assertTrue(mock_init.called)
Beispiel #4
0
    def test_get_programs_with_no_data(self):
        """ Verify the behavior when no programs data is found from the
        Programs service.
        """
        self.mock_programs_api(data={'results': []})

        actual_programs_api_response = get_programs()
        self.assertEqual(actual_programs_api_response, [])
Beispiel #5
0
    def test_get_programs_data_retrieval_failure(self):
        """
        Verify the behavior when data can't be retrieved from Programs.
        """
        self.mock_programs_api(status_code=500)

        actual_programs_api_response = get_programs()
        self.assertEqual(actual_programs_api_response, [])
Beispiel #6
0
 def test_get_programs_client_initialization_failure(self, mock_init):
     """
     Verify the behavior when API client fails to initialize.
     """
     mock_init.side_effect = Exception
     actual_programs_api_response = get_programs()
     self.assertEqual(actual_programs_api_response, [])
     self.assertTrue(mock_init.called)
Beispiel #7
0
    def test_get_programs_with_no_data(self):
        """ Verify the behavior when no programs data is found from the
        Programs service.
        """
        self.mock_programs_api(data={'results': []})

        actual_programs_api_response = get_programs()
        self.assertEqual(actual_programs_api_response, [])
Beispiel #8
0
    def test_get_programs_data_retrieval_failure(self):
        """
        Verify the behavior when data can't be retrieved from Programs.
        """
        self.mock_programs_api(status_code=500)

        actual_programs_api_response = get_programs()
        self.assertEqual(actual_programs_api_response, [])
Beispiel #9
0
    def test_get_programs(self):
        """
        Verify that the programs data can be retrieved.
        """
        self.mock_programs_api()

        actual_programs_api_response = get_programs()
        self.assertEqual(actual_programs_api_response,
                         self.PROGRAMS_API_RESPONSE['results'])

        # verify the API was actually hit (not the cache)
        self.assertEqual(len(httpretty.httpretty.latest_requests), 1)
Beispiel #10
0
    def test_get_programs(self):
        """
        Verify that the programs data can be retrieved.
        """
        self.mock_programs_api()

        actual_programs_api_response = get_programs()
        self.assertEqual(
            actual_programs_api_response,
            self.PROGRAMS_API_RESPONSE['results']
        )

        # verify the API was actually hit (not the cache)
        self.assertEqual(len(httpretty.httpretty.latest_requests), 1)
Beispiel #11
0
    def test_get_programs_client_settings_failure(self, setting_attribute):
        """
        Verify the behavior when API client fails to initialize due to
        missing settings.
        """
        self.mock_programs_api(data={'results': []})
        patched_settings = copy.deepcopy(settings)
        delattr(patched_settings, setting_attribute)
        expected_error_msg = "Failed to get settings for communication with the Programs API. " \
                             "Please make sure that the settings for 'PROGRAMS_API_URL', 'CREDENTIALS_SERVICE_USER'," \
                             " 'PROGRAMS_JWT_AUDIENCE', 'PROGRAMS_JWT_SECRET_KEY' are provided."

        with patch('credentials.apps.credentials.utils.settings', patched_settings):
            with LogCapture(LOGGER_NAME) as log:
                actual_programs_api_response = get_programs()
                self.assertEqual(actual_programs_api_response, [])
                log.check((LOGGER_NAME, 'ERROR', expected_error_msg))
Beispiel #12
0
    def test_get_programs_client_settings_failure(self, setting_attribute):
        """
        Verify the behavior when API client fails to initialize due to
        missing settings.
        """
        self.mock_programs_api(data={'results': []})
        patched_settings = copy.deepcopy(settings)
        delattr(patched_settings, setting_attribute)
        expected_error_msg = "Failed to get settings for communication with the Programs API. " \
                             "Please make sure that the settings for 'PROGRAMS_API_URL', 'CREDENTIALS_SERVICE_USER'," \
                             " 'PROGRAMS_JWT_AUDIENCE', 'PROGRAMS_JWT_SECRET_KEY' are provided."

        with patch('credentials.apps.credentials.utils.settings',
                   patched_settings):
            with LogCapture(LOGGER_NAME) as log:
                actual_programs_api_response = get_programs()
                self.assertEqual(actual_programs_api_response, [])
                log.check((LOGGER_NAME, 'ERROR', expected_error_msg))