Esempio n. 1
0
def main(wf):
    parser = getCommandLineParser()
    args = parser.parse_args(wf.args)

    mvg = MVG(wf)
    favorties = Favorites(wf)

    if args.command == 'search':
        stations = mvg.search(args.param) if args.param else favorties.get()
        addStationItems(stations, favorties)

    elif args.command == 'departures':
        departures = mvg.departures(args.param)
        if args.query:
            departures = wf.filter(args.query, departures, key=getDepartureLabel)

        departures = sorted(departures, key=lambda k: k['departureTime'])
        addDepartures(departures)

    elif args.command == 'save':
        stations = mvg.search(args.param)
        if len(stations) == 1:
            favorties.add(stations[0])

    elif args.command == 'remove':
        favorties.remove({'id': int(args.param)})

    sendFeedback()
Esempio n. 2
0
def test_failure_authorization(vibium):
    unauth_session = MVG(vibium, "NO TOKEN")

    with pytest.raises(HTTPError) as exc:
        unauth_session.supported_features()

    assert exc.value.response.status_code == 401
Esempio n. 3
0
def main(wf):
    parser = getCommandLineParser()
    args = parser.parse_args(wf.args)

    mvg = MVG(wf)
    favorties = Favorites(wf)

    if args.command == 'search':
        stations = mvg.search(args.param) if args.param else favorties.get()
        addStationItems(stations, favorties)

    elif args.command == 'departures':
        departures = mvg.departures(args.param)
        if args.query:
            departures = wf.filter(args.query,
                                   departures,
                                   key=getDepartureLabel)

        departures = sorted(departures, key=lambda k: k['departureTime'])
        addDepartures(departures)

    elif args.command == 'save':
        stations = mvg.search(args.param)
        if len(stations) == 1:
            favorties.add(stations[0])

    elif args.command == 'remove':
        favorties.remove({'id': int(args.param)})

    sendFeedback()
Esempio n. 4
0
def test_supported_features(vibium):
    session = MVG(vibium, VALID_TOKEN)
    resp = session.supported_features()
    print(resp)
    assert resp["mode_id"]
    # assert not resp['on_off']
    # assert not resp['asset_type']
    assert not resp["indicator_arrow"]
Esempio n. 5
0
def session(vibium):

    url = vibium
    print("Overriding vibium function with url %s", url)
    session = MVG(url, VALID_TOKEN)
    # To make sure we start from a clean slate
    # we delete our resource in case it exists
    # All information including measurements
    # will be removed
    # TO DO delete all so, currently we only
    # handle resource SOURCE_ID
    try:
        session.get_source(SOURCE_ID)
        print(f"Deleting {SOURCE_ID}")
        session.delete_source(SOURCE_ID)
    except HTTPError:
        print(f"Source {SOURCE_ID} does not exist")

    return session
Esempio n. 6
0
def test_create_session_invalid_url():
    with pytest.raises(HTTPError):
        MVG("invalidurl", "NO TOKEN")
Esempio n. 7
0
def test_check_version(vibium):

    # Get current API version for testing
    session = MVG(vibium, "NO TOKEN")

    # Check OK run
    session.tested_api_version = session.api_version
    assert session.check_version()["api_version"] == session.api_version

    # Check Incompatible Major version
    session.tested_api_version = semver.VersionInfo(major=100)
    with pytest.raises(ValueError):
        session.check_version()

    # Check to high highest tested version
    session.tested_api_version = session.api_version.bump_minor()
    with pytest.raises(ValueError):
        session.check_version()

    # Check API minor version higher
    session.api_version = session.tested_api_version.bump_minor()
    with pytest.raises(UserWarning):
        session.check_version()

    # Check version with pre-release
    session.tested_api_version = session.api_version.bump_prerelease()
    session.check_version()
Esempio n. 8
0
def test_say_hello(vibium):
    session = MVG(vibium, "NO TOKEN")
    hello = session.say_hello()
    print(hello)
    assert session.say_hello() is not None
Esempio n. 9
0
def test_create_session_without_server():
    """We should get an HTTPError because we cannot connect to localhost:8000"""
    with pytest.raises(HTTPError):
        MVG("localhost:8000", "NO TOKEN")