def test_search_results_with_no_parameters(mock_es_access):
    response = app.test_client().get('/search')

    assert mock_es_access.mock_calls == []

    json_body = json.loads(response.data.decode())
    assert json_body == EXPECTED_ERROR_RESPONSE
def test_search_results_using_postcode(mock_es_access):
    postcode = 'EX4 4QU'
    response = app.test_client().get('/search?postcode=EX4 4QU')

    mock_es_access.assert_called_once_with(postcode, PAGE_NUMBER, PAGE_SIZE)

    json_body = json.loads(response.data.decode())
    assert json_body == EXPECTED_RESPONSE
def test_search_results_using_phrase(mock_es_access):

    response = app.test_client().get('/search?phrase=someaddress')

    mock_es_access.assert_called_once_with('someaddress', PAGE_NUMBER, PAGE_SIZE)

    json_body = json.loads(response.data.decode())
    assert json_body == EXPECTED_RESPONSE
Example #4
0
    def setup_method(self, method):
        self.app = app.test_client()

        with mock.patch(
            'service.server.LoginApiClient.authenticate_user',
            return_value=True
        ) as mock_authorize:
            self._log_in_user()
    def test_status_returns_500_response_when_sync_manager_raises_error(self):
        exception_to_raise = Exception('Intentionally raised test exception')

        with mock.patch('service.sync_manager.get_index_updaters',
                        side_effect=exception_to_raise):
            response = app.test_client().get('/status')
            assert response.status_code == 500
            assert response.data.decode(
            ) == '{"error": "Internal server error"}'
    def test_health_returns_200_response_when_data_stores_respond_properly(
            self, mock_get_cluster_info, mock_get_next_data_page):

        response = app.test_client().get('/health')
        assert response.status_code == 200
        assert response.data.decode() == '{"status": "ok"}'

        mock_get_cluster_info.assert_called_once_with()
        mock_get_next_data_page.assert_called_once_with('', '2100-01-01', 1)
    def test_status_calls_sync_maganger_for_data(self, mock_is_updater_busy):
        mock_index_updater_1 = mock.MagicMock()
        mock_index_updater_1.last_successful_sync_time = datetime.now()
        mock_index_updater_1.last_title_modification_date = datetime.now()
        mock_index_updater_1.last_sync_attempt_successful = True
        mock_index_updater_1.index_name = 'index1'
        mock_index_updater_1.doc_type = 'doctype1'
        mock_index_updater_1.id = 'id1'

        with mock.patch('service.sync_manager.get_index_updaters',
                        return_value=[mock_index_updater_1
                                      ]) as mock_get_index_updaters:
            app.test_client().get('/status')

            mock_get_index_updaters.assert_called_once_with()
            assert mock_is_updater_busy.mock_calls == [
                call(mock_index_updater_1)
            ]
Example #8
0
    def setup_method(self, method):
        config_dict = {
            'DEBUG': False,
            'PASSWORD_SALT': 'salt',
        }

        app.config.update(config_dict)
        mock_db_access = MagicMock()
        mock_db_access.get_user.return_value = None
        server.db_access = mock_db_access
        self.app = app.test_client()
    def test_health_returns_500_response_when_es_access_fails(
            self, mock_get_cluster_info, mock_get_next_data_page):

        response = app.test_client().get('/health')

        assert response.status_code == 500
        json_response = json.loads(response.data.decode())
        assert json_response == {
            'status': 'error',
            'errors': ['Problem talking to elasticsearch: Test ES exception'],
        }
    def test_health_returns_500_response_with_multiple_errors_when_both_data_stores_fail(
            self, mock_get_cluster_info, mock_get_next_data_page):

        response = app.test_client().get('/health')

        assert response.status_code == 500
        json_response = json.loads(response.data.decode())
        assert json_response == {
            'status':
            'error',
            'errors': [
                'Problem talking to elasticsearch: Test ES exception',
                'Problem talking to PostgreSQL: Test PG exception',
            ],
        }
def client():
    return app.test_client()
 def setUp(self):
     self.ppi_api = app.config['PPI_END_POINT']
     self.app = app.test_client()
 def setup_method(self, method):
     self.app = app.test_client()
 def setup_method(self, method):
     self.app = app.test_client()
 def setup_method(self, method):
     self.app = app.test_client()
     self.headers = Headers([('iv-user', TEST_USERNAME), ('iv-groups', TEST_USER_GROUP)])
    def test_status_returns_data_retrieved_from_sync_manager(
            self, mock_is_updater_busy):
        mock_index_updater_1 = mock.MagicMock()
        mock_index_updater_1.last_successful_sync_time = datetime(
            2015, 4, 20, 10, 11, 12)
        mock_index_updater_1.last_unsuccessful_sync_time = datetime(
            2015, 4, 20, 12, 13, 14)
        mock_index_updater_1.last_title_modification_date = datetime(
            2015, 4, 21, 10, 11, 12)
        mock_index_updater_1.last_updated_title_number = 'title1'
        mock_index_updater_1.last_sync_attempt_successful = True
        mock_index_updater_1.index_name = 'index1'
        mock_index_updater_1.doc_type = 'doctype1'
        mock_index_updater_1.id = 'id1'

        mock_index_updater_2 = mock.MagicMock()
        mock_index_updater_2.last_successful_sync_time = datetime(
            2015, 4, 22, 10, 11, 12)
        mock_index_updater_2.last_unsuccessful_sync_time = datetime(
            2015, 4, 22, 12, 13, 14)
        mock_index_updater_2.last_title_modification_date = datetime(
            2015, 4, 23, 10, 11, 12)
        mock_index_updater_2.last_updated_title_number = 'title2'
        mock_index_updater_2.last_sync_attempt_successful = False
        mock_index_updater_2.index_name = 'index2'
        mock_index_updater_2.doc_type = 'doctype2'
        mock_index_updater_2.id = 'id2'

        updaters = [mock_index_updater_1, mock_index_updater_2]

        with mock.patch('service.sync_manager.get_index_updaters',
                        return_value=updaters):
            response = app.test_client().get('/status')
            assert response.status_code == 200
            response_json = json.loads(response.data.decode())
            assert response_json == {
                "polling_interval": CONFIG_DICT['POLLING_INTERVAL_SECS'],
                "status": {
                    "id1": {
                        "last_successful_sync_time":
                        "2015-04-20T10:11:12.000+0000",
                        "last_unsuccessful_sync_time":
                        "2015-04-20T12:13:14.000+0000",
                        "is_busy": True,
                        "index_name": "index1",
                        "doc_type": "doctype1",
                        "last_title_modification_date":
                        "2015-04-21T10:11:12.000+0000",
                        "last_title_number": "title1",
                    },
                    "id2": {
                        "last_successful_sync_time":
                        "2015-04-22T10:11:12.000+0000",
                        "last_unsuccessful_sync_time":
                        "2015-04-22T12:13:14.000+0000",
                        "is_busy": False,
                        "index_name": "index2",
                        "doc_type": "doctype2",
                        "last_title_modification_date":
                        "2015-04-23T10:11:12.000+0000",
                        "last_title_number": "title2",
                    },
                }
            }