Exemple #1
0
    def test_adequacy_request(self):
        """Test adequacy requests in a simple case."""
        request_adequacy = {
            'method':
            'straight_line',
            'providers': [{
                'id': 1,
                'latitude': 37.74753421600008,
                'longitude': -122.2316317029999
            }, {
                'id': 2,
                'latitude': 32.74753421600008,
                'longitude': -122.2316317029999
            }],
            'service_area_ids': ['ca_los_angeles_90001']
        }

        def _mock_get_json(force=True):
            return request_adequacy

        mock_request = mock.MagicMock()
        mock_request.get_json = _mock_get_json
        try:
            adequacy.adequacy_request(self.app, mock_request, engine)
        except TypeError:
            pytest.fail('Could not calculate adequacy.')
Exemple #2
0
    def test_adequacy_request_invalid_json(self):
        """Test adequacy requests in a simple case."""
        def _mock_get_json(force=True):
            raise json.JSONDecodeError(msg='', doc='', pos=0)

        mock_request = mock.MagicMock()
        mock_request.get_json = _mock_get_json
        with pytest.raises(InvalidFormat):
            adequacy.adequacy_request(self.app, mock_request, engine)
Exemple #3
0
    def test_adequacy_request_missing_providers(self):
        """Test adequacy requests without providers raise an error."""
        request_adequacy = {
            'method': 'straight_line',
            'service_area_ids': ['ca_los_angeles_90001']
        }

        def _mock_get_json(force=True):
            return request_adequacy

        mock_request = mock.MagicMock()
        mock_request.get_json = _mock_get_json
        with pytest.raises(InvalidFormat):
            adequacy.adequacy_request(self.app, mock_request, engine)
Exemple #4
0
    def test_adequacy_request_missing_area(self):
        """Test adequacy requests without service areas raise an error."""
        request_adequacy = {
            'providers': [{
                'id': 1,
                'latitude': 37.74753421600008,
                'longitude': -122.2316317029999
            }, {
                'id': 2,
                'latitude': 32.74753421600008,
                'longitude': -122.2316317029999
            }]
        }

        def _mock_get_json(force=True):
            return request_adequacy

        mock_request = mock.MagicMock()
        mock_request.get_json = _mock_get_json
        with pytest.raises(InvalidFormat):
            adequacy.adequacy_request(self.app, mock_request, engine)
Exemple #5
0
    def test_adequacy_request_no_providers_no_service_areas(self):
        """Test adequacy requests with neither providers nor service areas."""
        request_adequacy = {
            'method': 'straight_line',
            'providers': [],
            'service_area_ids': []
        }

        def _mock_get_json(force=True):
            return request_adequacy

        mock_request = mock.MagicMock()
        mock_request.get_json = _mock_get_json
        try:
            output = adequacy.adequacy_request(self.app, mock_request, engine)
            assert output == []
        except TypeError:
            pytest.fail('Could not calculate adequacy.')
Exemple #6
0
def calculate_adequacies():
    """Calculate adequacy for the input service areas and providers."""
    logger.debug('Calculate time distance standards.')
    response = adequacy.adequacy_request(app, flask.request, engine)
    return flask.jsonify(response)