Beispiel #1
0
    def test_user_info(self):

        with patch("flightplandb.flightplandb.FlightPlanDB",
                   autospec=True) as MockClass:
            instance = MockClass.return_value
            instance._get.return_value = {
                "id": 1,
                "username": "******",
                "location": "😁",
                "gravatarHash": "7889b0d4380a7194b6b67c8e2765289d",
                "joined": "2008-12-31T15:49:18.000Z",
                "lastSeen": "2021-04-24T00:22:46.000Z",
                "plansCount": 479,
                "plansDistance": 1212799.2736187153,
                "plansDownloads": 10341,
                "plansLikes": 33
            }
            sub_instance = UserAPI(instance)
            response = sub_instance.fetch("lemon")
            correct_response = User(
                id=1,
                username="******",
                location="😁",
                gravatarHash="7889b0d4380a7194b6b67c8e2765289d",
                joined=datetime.datetime(2008,
                                         12,
                                         31,
                                         15,
                                         49,
                                         18,
                                         tzinfo=tzutc()),
                lastSeen=datetime.datetime(2021,
                                           4,
                                           24,
                                           0,
                                           22,
                                           46,
                                           tzinfo=tzutc()),
                plansCount=479,
                plansDistance=1212799.2736187153,
                plansDownloads=10341,
                plansLikes=33)
            # check that UserAPI method made correct request of FlightPlanDB
            instance.assert_has_calls([call._get("/user/lemon")])
            # check UserAPI method decoded data correctly for given response
            assert response == correct_response
Beispiel #2
0
    def me(self) -> User:
        """Fetches profile information for the currently authenticated user.

        Requires authentication.

        Returns
        -------
        User
            The User object of the currently authenticated user

        Raises
        ------
        :class:`~flightplandb.exceptions.UnauthorizedException`
            Authentication failed.
        """

        return User(**self._fp._get("/me"))
Beispiel #3
0
    def fetch(self, username: str) -> User:
        """Fetches profile information for any registered user

        Parameters
        ----------
        username : str
            Username of the registered User

        Returns
        -------
        User
            The User object of the user associated with the username

        Raises
        -------
        :class:`~flightplandb.exceptions.NotFoundException`
            No user was found with this username.
        """

        return User(**self._fp._get(f"/user/{username}"))
Beispiel #4
0
    def test_self_info(self):

        with patch("flightplandb.flightplandb.FlightPlanDB",
                   autospec=True) as MockClass:
            instance = MockClass.return_value
            instance._get.return_value = {
                "id": 18990,
                "username": "******",
                "location": None,
                "gravatarHash": "3bcb4f39a24700e081f49c3d2d43d277",
                "joined": "2020-08-06T17:04:30.000Z",
                "lastSeen": "2020-12-27T12:40:06.000Z",
                "plansCount": 2,
                "plansDistance": 794.0094160460012,
                "plansDownloads": 0,
                "plansLikes": 0
            }
            sub_instance = UserAPI(instance)
            response = sub_instance.me
            correct_response = User(
                id=18990,
                username="******",
                location=None,
                gravatarHash="3bcb4f39a24700e081f49c3d2d43d277",
                joined=datetime.datetime(2020, 8, 6, 17, 4, 30,
                                         tzinfo=tzutc()),
                lastSeen=datetime.datetime(2020,
                                           12,
                                           27,
                                           12,
                                           40,
                                           6,
                                           tzinfo=tzutc()),
                plansCount=2,
                plansDistance=794.0094160460012,
                plansDownloads=0,
                plansLikes=0)
            # check that UserAPI method made correct request of FlightPlanDB
            instance.assert_has_calls([call._get("/me")])
            # check UserAPI method decoded data correctly for given response
            assert response == correct_response
Beispiel #5
0
    def test_user_plans(self):

        with patch("flightplandb.flightplandb.FlightPlanDB",
                   autospec=True) as MockClass:
            instance = MockClass.return_value
            mock_response = [{
                "id": 62373,
                "fromICAO": "KLAS",
                "toICAO": "KLAX",
                "fromName": "Mc Carran Intl",
                "toName": "Los Angeles Intl",
                "flightNumber": None,
                "distance": 206.39578816273502,
                "maxAltitude": 18000,
                "waypoints": 8,
                "likes": 0,
                "downloads": 1,
                "popularity": 1,
                "notes": "",
                "encodedPolyline": r"aaf{E`|y}T|Ftf@px\\hpe@lnCxw \
                    Dbsk@rfx@vhjC`nnDd~f@zkv@nb~ChdmH",
                "createdAt": "2015-08-04T20:48:08.000Z",
                "updatedAt": "2015-08-04T20:48:08.000Z",
                "tags": ["generated"],
                "user": {
                    "id": 2429,
                    "username": "******",
                    "gravatarHash": "f30b58b998a11b5d417cc2c78df3f764",
                    "location": None
                }
            }, {
                "id": 62493,
                "fromICAO": "EHAM",
                "toICAO": "KJFK",
                "fromName": "Schiphol",
                "toName": "John F Kennedy Intl",
                "flightNumber": None,
                "distance": 3157.88876623323,
                "maxAltitude": 0,
                "waypoints": 2,
                "popularity": 0,
                "notes": None,
                "encodedPolyline": r"yvh~Hgi`\\lggfAjyi~M",
                "createdAt": "2015-08-05T22:44:34.000Z",
                "updatedAt": "2015-08-05T22:44:34.000Z",
                "tags": ["atlantic"],
                "user": {
                    "id": 1,
                    "username": "******",
                    "gravatarHash": "f30b58b998a11b5d417cc2c78df3f764",
                    "location": None
                }
            }]
            instance._getiter.return_value = (i for i in mock_response)

            sub_instance = UserAPI(instance)
            response = sub_instance.plans("lemon")

            correct_response_list = [
                Plan(id=62373,
                     fromICAO="KLAS",
                     toICAO="KLAX",
                     fromName="Mc Carran Intl",
                     toName="Los Angeles Intl",
                     flightNumber=None,
                     distance=206.39578816273502,
                     maxAltitude=18000,
                     waypoints=8,
                     likes=0,
                     downloads=1,
                     popularity=1,
                     notes="",
                     encodedPolyline=r"aaf{E`|y}T|Ftf@px\\hpe@lnCxw \
                    Dbsk@rfx@vhjC`nnDd~f@zkv@nb~ChdmH",
                     createdAt="2015-08-04T20:48:08.000Z",
                     updatedAt="2015-08-04T20:48:08.000Z",
                     tags=["generated"],
                     user=User(id=2429,
                               username="******",
                               gravatarHash="f30b58b998a11b5d417cc2c78df3f764",
                               location=None)),
                Plan(id=62493,
                     fromICAO="EHAM",
                     toICAO="KJFK",
                     fromName="Schiphol",
                     toName="John F Kennedy Intl",
                     flightNumber=None,
                     distance=3157.88876623323,
                     maxAltitude=0,
                     waypoints=2,
                     popularity=0,
                     notes=None,
                     encodedPolyline=r"yvh~Hgi`\\lggfAjyi~M",
                     createdAt="2015-08-05T22:44:34.000Z",
                     updatedAt="2015-08-05T22:44:34.000Z",
                     tags=["atlantic"],
                     user=User(id=1,
                               username="******",
                               gravatarHash="f30b58b998a11b5d417cc2c78df3f764",
                               location=None))
            ]
            # check UserAPI method decoded data correctly for given response
            assert list(i for i in response) == correct_response_list
            # check that UserAPI method made the correct request of FlightPlanDB
            instance.assert_has_calls([
                call._getiter('/user/lemon/plans', limit=100, sort='created')
            ])
Beispiel #6
0
    def test_plan_decode(self):
        with patch("flightplandb.flightplandb.FlightPlanDB",
                   autospec=True) as MockClass:
            instance = MockClass.return_value
            instance._post.return_value = {
                'application': None,
                'createdAt': '2021-04-28T20:33:57.000Z',
                'cycle': {
                    'id': 38, 'ident': 'FPD2104', 'release': 4, 'year': 21},
                'distance': 757.3434118878,
                'downloads': 0,
                'encodedPolyline': '_hxfEntgjUr_S_`qAgvaEo'
                'cvBsksPgn_a@_~kSwgbc@',
                'flightNumber': None,
                'fromICAO': 'KSAN',
                'fromName': 'San Diego Intl',
                'id': 4179222,
                'likes': 0,
                'maxAltitude': 0,
                'notes': 'Requested: KSAN BROWS TRM LRAIN KDEN',
                'popularity': 1619642037,
                'tags': ['decoded'],
                'toICAO': 'KDEN',
                'toName': 'Denver Intl',
                'updatedAt': '2021-04-28T20:33:57.000Z',
                'user': {
                    'gravatarHash': '3bcb4f39a24700e081f49c3d2d43d277',
                    'id': 18990,
                    'location': None,
                    'username': '******'},
                'waypoints': 5}

            sub_instance = PlanAPI(instance)
            request_query = "KSAN BROWS TRM LRAIN KDEN"
            response = sub_instance.decode(request_query)
            # check PlanAPI method made the correct request of FlightPlanDB
            correct_calls = [
                call._post(
                    path='/auto/decode',
                    json_data={'route': 'KSAN BROWS TRM LRAIN KDEN'})]

            instance.assert_has_calls(correct_calls)

            correct_response = Plan(
                id=4179222,
                fromICAO='KSAN',
                toICAO='KDEN',
                fromName='San Diego Intl',
                toName='Denver Intl',
                flightNumber=None,
                distance=757.3434118878,
                maxAltitude=0,
                waypoints=5,
                likes=0,
                downloads=0,
                popularity=1619642037,
                notes='Requested: KSAN BROWS TRM LRAIN KDEN',
                encodedPolyline='_hxfEntgjUr_S_`qAgvaEocvBsksPgn_a@_~kSwgbc@',
                createdAt=datetime.datetime(
                    2021, 4, 28, 20, 33, 57, tzinfo=tzutc()),
                updatedAt=datetime.datetime(
                    2021, 4, 28, 20, 33, 57, tzinfo=tzutc()),
                tags=['decoded'],
                user=User(
                    id=18990,
                    username='******',
                    location=None,
                    gravatarHash='3bcb4f39a24700e081f49c3d2d43d277',
                    joined=None,
                    lastSeen=None,
                    plansCount=0,
                    plansDistance=0.0,
                    plansDownloads=0,
                    plansLikes=0),
                application=None,
                route=None,
                cycle=Cycle(
                    id=38,
                    ident='FPD2104',
                    year=21,
                    release=4))

            # check PlanAPI method decoded data correctly for given response
            assert response == correct_response
Beispiel #7
0
    def test_plan_generate(self):
        with patch("flightplandb.flightplandb.FlightPlanDB",
                   autospec=True) as MockClass:
            instance = MockClass.return_value
            instance._post.return_value = {
                'application': None,
                'createdAt': '2021-04-28T19:55:45.000Z',
                'cycle': {
                    'id': 38,
                    'ident': 'FPD2104',
                    'release': 4,
                    'year': 21},
                'distance': 36.666306664518004,
                'downloads': 0,
                'encodedPolyline': '_dgeIybta@niaA~vdD',
                'flightNumber': None,
                'fromICAO': 'EHAL',
                'fromName': 'Ameland',
                'id': 4179148,
                'likes': 0,
                'maxAltitude': 0,
                'notes': 'Basic altitude profile:\n'
                         '- Ascent Rate: 2500ft/min\n'
                         '- Ascent Speed: 250kts\n'
                         '- Cruise Altitude: 35000ft\n'
                         '- Cruise Speed: 420kts\n'
                         '- Descent Rate: 1500ft/min\n'
                         '- Descent Speed: 250kts\n'
                         '\n'
                         'Options:\n'
                         '- Use NATs: yes\n'
                         '- Use PACOTS: yes\n'
                         '- Use low airways: yes\n'
                         '- Use high airways: yes\n',
                'popularity': 1619639745,
                'tags': ['generated'],
                'toICAO': 'EHTX',
                'toName': 'Texel',
                'updatedAt': '2021-04-28T19:55:45.000Z',
                'user': {
                    'gravatarHash': '3bcb4f39a24700e081f49c3d2d43d277',
                    'id': 18990,
                    'location': None,
                    'username': '******'},
                'waypoints': 2}

            sub_instance = PlanAPI(instance)
            request_query = GenerateQuery(fromICAO="EHAL", toICAO="EHTX")
            response = sub_instance.generate(request_query)
            # check PlanAPI method made the correct request of FlightPlanDB
            correct_calls = [
                call._post(
                    path='/auto/generate',
                    json_data={
                        'fromICAO': 'EHAL',
                        'toICAO': 'EHTX',
                        'useNAT': True,
                        'usePACOT': True,
                        'useAWYLO': True,
                        'useAWYHI': True,
                        'cruiseAlt': 35000,
                        'cruiseSpeed': 420,
                        'ascentRate': 2500,
                        'ascentSpeed': 250,
                        'descentRate': 1500,
                        'descentSpeed': 250,
                        'includeRoute': 'false'})]

            instance.assert_has_calls(correct_calls)

            correct_response = Plan(
                id=4179148,
                fromICAO='EHAL',
                toICAO='EHTX',
                fromName='Ameland',
                toName='Texel',
                flightNumber=None,
                distance=36.666306664518004,
                maxAltitude=0,
                waypoints=2,
                likes=0,
                downloads=0,
                popularity=1619639745,
                notes='Basic altitude profile:\n'
                '- Ascent Rate: 2500ft/min\n'
                '- Ascent Speed: 250kts\n'
                '- Cruise Altitude: 35000ft\n'
                '- Cruise Speed: 420kts\n'
                '- Descent Rate: 1500ft/min\n'
                '- Descent Speed: 250kts\n\nOptions:\n'
                '- Use NATs: yes\n'
                '- Use PACOTS: yes\n'
                '- Use low airways: yes\n'
                '- Use high airways: yes\n',
                encodedPolyline='_dgeIybta@niaA~vdD',
                createdAt=datetime.datetime(
                    2021, 4, 28, 19, 55, 45, tzinfo=tzutc()),
                updatedAt=datetime.datetime(
                    2021, 4, 28, 19, 55, 45, tzinfo=tzutc()),
                tags=['generated'],
                user=User(
                    id=18990,
                    username='******',
                    location=None,
                    gravatarHash='3bcb4f39a24700e081f49c3d2d43d277',
                    joined=None,
                    lastSeen=None,
                    plansCount=0,
                    plansDistance=0.0,
                    plansDownloads=0,
                    plansLikes=0),
                application=None,
                route=None,
                cycle=Cycle(
                    id=38,
                    ident='FPD2104',
                    year=21,
                    release=4))

            # check PlanAPI method decoded data correctly for given response
            assert response == correct_response
Beispiel #8
0
    def test_plan_fetch(self):
        with patch("flightplandb.flightplandb.FlightPlanDB",
                   autospec=True) as MockClass:
            instance = MockClass.return_value
            instance._get.return_value = {
                "id": 62373,
                "fromICAO": "KLAS",
                "toICAO": "KLAX",
                "fromName": "Mc Carran Intl",
                "toName": "Los Angeles Intl",
                "flightNumber": None,
                "distance": 206.39578816273502,
                "maxAltitude": 18000,
                "waypoints": 8,
                "likes": 0,
                "downloads": 1,
                "popularity": 1,
                "notes": "",
                "encodedPolyline": r"aaf{E`|y}T|Ftf@px\\hpe@lnCxw \
                Dbsk@rfx@vhjC`nnDd~f@zkv@nb~ChdmH",
                "createdAt": "2015-08-04T20:48:08.000Z",
                "updatedAt": "2015-08-04T20:48:08.000Z",
                "tags": [
                    "generated"
                ],
                "user": {
                    "id": 2429,
                    "username": "******",
                    "gravatarHash": "f30b58b998a11b5d417cc2c78df3f764",
                    "location": None
                }
            }

            sub_instance = PlanAPI(instance)
            response = sub_instance.fetch(62373)
            # check PlanAPI method made the correct request of FlightPlanDB
            instance.assert_has_calls(
                [call._get('/plan/62373', return_format='native')])

            correct_response = Plan(
                id=62373,
                fromICAO="KLAS",
                toICAO="KLAX",
                fromName="Mc Carran Intl",
                toName="Los Angeles Intl",
                flightNumber=None,
                distance=206.39578816273502,
                maxAltitude=18000,
                waypoints=8,
                likes=0,
                downloads=1,
                popularity=1,
                notes="",
                encodedPolyline=r"aaf{E`|y}T|Ftf@px\\hpe@lnCxw \
                Dbsk@rfx@vhjC`nnDd~f@zkv@nb~ChdmH",
                createdAt="2015-08-04T20:48:08.000Z",
                updatedAt="2015-08-04T20:48:08.000Z",
                tags=[
                    "generated"
                ],
                user=User(
                    id=2429,
                    username="******",
                    gravatarHash="f30b58b998a11b5d417cc2c78df3f764",
                    location=None
                ))

            # check PlanAPI method decoded data correctly for given response
            assert response == correct_response