Пример #1
0
    def test_get_api_download_link_not_agreed(self, mock_auth, mock_ulapd_api):
        error = ('ulapd_ui', 'NO_LICENCE_SIGNED')
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'ccod']

        mock_auth.return_value = data.user_details_no_agreements

        with self.assertRaises(ApplicationError) as cm:
            get_api_download_link('ccod', 'CCOD_FULL.CSV')

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='ccod'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
Пример #2
0
    def test_get_api_download_link_no_resource(self, mock_curr_app, mock_auth,
                                               mock_ulapd_api):
        error = ('ulapd_ui', 'FILE_DOES_NOT_EXIST')
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'ocod']

        mock_auth.return_value = data.user_details_with_agreements

        with self.assertRaises(ApplicationError) as cm:
            get_api_download_link('ocod', 'blah')

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='blah'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
Пример #3
0
    def test_get_api_download_link_not_agreed_private(self, mock_auth,
                                                      mock_ulapd_api):
        error = ('ulapd_ui', 'NO_DATASET_ACCESS')
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'nps']

        mock_auth.return_value = data.user_details_no_agreements

        with self.assertRaises(ApplicationError) as cm:
            get_api_download_link('nps', 'NPS_FULL.CSV')

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='nps'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
Пример #4
0
    def test_get_api_download_link_generic_error(self, mock_metric,
                                                 mock_ulapd_api, mock_auth,
                                                 *_):
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'ocod']
        instance.get_download_link.return_value = {
            'link': 'https://S3-resource'
        }

        mock_auth.return_value = data.user_details_with_agreements

        mock_metric.side_effect = Exception('test')

        with self.assertRaises(Exception):
            get_api_download_link('ocod', 'OCOD_FULL.CSV')
Пример #5
0
    def test_get_api_download_link_api_error(self, mock_curr_app, mock_auth,
                                             mock_ulapd_api):
        error = ('ulapd_ui', 'DATASET_NOT_FOUND')
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'ocod']
        instance.get_download_link.return_value = None

        mock_auth.return_value = data.user_details_with_agreements

        with self.assertRaises(ApplicationError) as cm:
            get_api_download_link('ocod', 'OCOD_FULL.CSV')

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='ocod'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
Пример #6
0
def get_api_download_link(dataset, file_name):
    try:
        return jsonify(api_service.get_api_download_link(dataset, file_name))
    except ApplicationError as error:
        error_message = 'Failed to get datasets - {}'.format(error.message)
        current_app.logger.error(error_message)
        response = {
            "success": False,
            "error": error.message
        }
        return jsonify(response), error.http_code
Пример #7
0
def get_api_history_download_link(dataset, file_name):
    try:
        date = file_name.strip(dataset.upper()).strip('_FULL_').strip('_COU_').rsplit('.')[0]
        return jsonify(api_service.get_api_download_link(dataset, file_name, date))
    except ApplicationError as error:
        error_message = 'Failed to get datasets - {}'.format(error.message)
        current_app.logger.error(error_message)
        response = {
            "success": False,
            "error": error.message
        }
        return jsonify(response), error.http_code
Пример #8
0
    def test_get_api_download_link(self, mock_ulapd_api, mock_auth, *_):
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'ocod']
        instance.get_download_link.return_value = {
            'link': 'https://S3-resource'
        }

        mock_auth.return_value = data.user_details_with_agreements

        actual_output = get_api_download_link('ocod', 'OCOD_FULL.CSV')
        expected_output = {
            "success": True,
            "result": {
                "resource": 'OCOD_FULL.CSV',
                "valid_for_seconds": 10,
                "download_url": 'https://S3-resource'
            }
        }

        self.assertEqual(actual_output, expected_output)