Exemplo n.º 1
0
def test_exception_catch_for_an_unknown_place():

    parser = Parser(
        "Yop, donne moi les coordonnées du trou noir Sagittarius A*")

    place = Location(parser)

    with pytest_raises(UnknownPlaceError):
        place.get_location()
Exemplo n.º 2
0
def test_Location_return_correct_Location_for_several_places(
        location, coordinates):

    parser = Parser(location)

    place = Location(parser)
    place.get_location()

    assert place.latitude, place.longitude == coordinates
Exemplo n.º 3
0
def test_story_return_correct_extract_and_url_for_several_location(
        input_user, extract_place, url_place):

    parser = Parser(input_user)
    location = Location(parser)
    location.get_location()
    story = Story(location)

    story.about()

    assert story.extract == extract_place
    assert story.url == url_place
Exemplo n.º 4
0
class TestLocationResource:
    @patch.object(LocationService, 'get_all', lambda: [
        make_location(),
        make_location(location_id=2, city='Moscow', country='Russia')
    ])
    def test_get(self, client: FlaskClient):
        with client:
            results = client.get(f'/api/{BASE_ROUTE}',
                                 follow_redirects=True).get_json()
            expected = (LocationSchema(many=True).dump([
                make_location(),
                make_location(location_id=2, city='Moscow', country='Russia')
            ]))
            for r in results:
                assert r in expected

    @patch.object(LocationService, 'create',
                  lambda create_request: Location(**create_request))
    def test_post(self, client: FlaskClient):
        with client:
            payload = dict(city='Moscow', country='Russia')
            result = client.post(f'/api/{BASE_ROUTE}/',
                                 json=payload).get_json()
            expected = (LocationSchema().dump(
                Location(city=payload['city'], country=payload['country'])))
            assert result == expected
Exemplo n.º 5
0
def test_class_Location_can_take_a_parser_object():

    parser = MockParser("tour%20eiffel")

    place = Location(parser)

    assert place._input_parsed == "tour%20eiffel"
Exemplo n.º 6
0
def test_mock_location_return_correct_location_of_eiffel_tower(monkeypatch):

    monkeypatch.setattr(
        "app.location.requests_get",
        mock_requests_get_location,
    )

    parser = MockParser("musée%20louvre")

    place = Location(parser)
    place.get_location()

    assert place.latitude, place.longitude == (
        48.85837009999999,
        2.2944813,
    )
Exemplo n.º 7
0
 def test_post(self, client: FlaskClient):
     with client:
         payload = dict(city='Moscow', country='Russia')
         result = client.post(f'/api/{BASE_ROUTE}/',
                              json=payload).get_json()
         expected = (LocationSchema().dump(
             Location(city=payload['city'], country=payload['country'])))
         assert result == expected
Exemplo n.º 8
0
    def test_put(self, client: FlaskClient):
        with client:
            result = client.put(f'/api/{BASE_ROUTE}/1',
                                json={
                                    'city': 'Dublin',
                                    'country': 'Ireland'
                                }).get_json()

            expected = (LocationSchema().dump(
                Location(location_id=1, city='Dublin', country='Ireland')))

            assert result == expected
Exemplo n.º 9
0
def get_infos(sentence):
    """Parse an input sentence and try to get infos from it, coordinates,
    extract from Wikipedia and url.

    Args:

        sentence (string): Sentence from user input

    Returns:

        tuple: Informations gathered from input parsed (coordinates, url to
            wikipedia, random message from GranPy)

        boolean: Does the parsing and finding informations occured normally

    """

    parser = Parser(sentence)
    location = Location(parser)

    try:
        location.get_location()
        story = Story(location)
        story.about()
    except UnknownPlaceError:
        # If Harold doesn't found requested location, returning random sentence
        # of error
        return sample(RANDOM_SENTENCE_UNKWON_PLACE, 1), False

    return (
        sample(RANDOM_SENTENCE_GRANPY, 1),
        location.latitude,
        location.longitude,
        story.extract,
        story.url,
    ), True
Exemplo n.º 10
0
def fake_update(location: Location, changes: LocationInterface):
    update_location = Location(location_id=location.location_id,
                               city=changes['city'],
                               country=changes['country'])

    return update_location
Exemplo n.º 11
0
def make_location(location_id: int = 1,
                  city: str = 'Belfast',
                  country='North Ireland') -> Location:
    return Location(location_id=location_id, city=city, country=country)
Exemplo n.º 12
0
class ListLocationOfSIO(Enum):
    kindergarten = Location(4, 6, 72)
    school = Location(2, 3, 10)
    clinic = Location(9, 12, 34)