Esempio n. 1
0
def test_get_api_success():
    #inserting for get
    filename = "create_api_for_success.json"
    request_data = setup.get_data(filename, file_path)
    headers = {'content-type': 'application/json'}
    service_url_upload = setup.get_api_url("insert")
    setup.send_post_request(service_url_upload, request_data, headers)

    service_url_get = setup.get_api_url(
        "get", ("Audiobook", "2EB8AA08-AA98-11EA-B4AA-73B441D16381"))
    headers = {'content-type': 'application/json'}
    response = setup.send_get_request(service_url_get, headers)

    service_url_get = setup.get_api_url("get_special", ("Audiobook", ))
    print(service_url_get)
    headers = {'content-type': 'application/json'}
    response_special = setup.send_get_request(service_url_get, headers)

    service_url_delete = setup.get_api_url(
        "delete", ("Audiobook", "2EB8AA08-AA98-11EA-B4AA-73B441D16381"))
    headers = {'content-type': 'application/json'}
    setup.send_delete_request(service_url_delete, headers)

    assert response.status_code == 200
    assert response_special.status_code == 200
def test_create_api_fail():
    filename = "create_api_for_fail.json"
    request_data = setup.get_data(filename, file_path)
    headers = {'content-type': 'application/json'}
    service_url_upload = setup.get_api_url("insert")
    response = setup.send_post_request(service_url_upload, request_data,
                                       headers)

    assert response.status_code == 400
Esempio n. 3
0
def test_update_api_norecord():
    filename = "create_api_for_success.json"
    request_data = setup.get_data(filename, file_path)
    service_url_update = setup.get_api_url(
        "update", ("Audiobook", "2EB8AA08-AA98-11EA-B4AA-73B441D16385"))
    headers = {'content-type': 'application/json'}
    response = setup.send_update_request(service_url_update, request_data,
                                         headers)

    assert response.status_code == 400
def test_create_api_success():
    filename = "create_api_for_success.json"
    request_data = setup.get_data(filename, file_path)
    headers = {'content-type': 'application/json'}
    service_url_upload = setup.get_api_url("insert")
    response = setup.send_post_request(service_url_upload, request_data,
                                       headers)

    #for cleaning
    service_url_delete = setup.get_api_url(
        "delete", ("Audiobook", "2EB8AA08-AA98-11EA-B4AA-73B441D16381"))
    headers = {'content-type': 'application/json'}
    print(service_url_delete)
    setup.send_delete_request(service_url_delete, headers)

    assert response.status_code == 200
Esempio n. 5
0
def test_update_api_fail():
    filename = "create_api_for_success.json"
    request_data = setup.get_data(filename, file_path)
    headers = {'content-type': 'application/json'}
    service_url_upload = setup.get_api_url("insert")
    setup.send_post_request(service_url_upload, request_data, headers)

    service_url_update = setup.get_api_url(
        "update", ("Song", "2EB8AA08-AA98-11EA-B4AA-73B441D16381"))
    print(service_url_update)
    headers = {'content-type': 'application/json'}
    request_data['audioMetadata']["audiobook_title"] = "updated"
    response = setup.send_update_request(service_url_update, request_data,
                                         headers)

    #for cleaning
    service_url_delete = setup.get_api_url(
        "delete", ("Audiobook", "2EB8AA08-AA98-11EA-B4AA-73B441D16381"))
    headers = {'content-type': 'application/json'}
    setup.send_delete_request(service_url_delete, headers)

    assert response.status_code == 400
Esempio n. 6
0
def initCustomer():
    import setup
    #get data from file
    order_info = setup.get_data()
    #if these things are not in the file, add them for future use
    if "first_name" not in order_info:
        order_info["first_name"] = input("First Name: ")
    if "last_name" not in order_info:
        order_info["last_name"] = input("Last Name: ")
    if "email" not in order_info:
        order_info["email"] = input("Email: ")
    if "phone" not in order_info:
        order_info["phone"] = input("Phone Number: ")
    if "address" not in order_info:
        order_info["address"] = input("Address: ")
    #update the file with the new info
    setup.write_data(order_info)
    #return customer data
    customer_info = Customer(order_info["first_name"], order_info["last_name"],
                             order_info["email"], order_info["phone"])
    address_info = Address(order_info["address"], order_info["city"],
                           order_info["state"], order_info["zip"])
    return customer_info, address_info
Esempio n. 7
0
def get_weather(command_input):
    import setup
    import zip_converter
    # get user data for command use
    user_data = setup.get_data()
    # create base variables to be modified later
    city = ""
    state = ""
    #figure out the location to detect the weather
    try:
        # if a location is given, use that
        location = command_input[command_input.index("weather") + 1]
        print("Location: ", location)
        #if a zip code is given
        try:
            print(int(location))
            city, state = zip_converter.zip_to_city_state(location)
        #if a city and state are given
        except ValueError:
            # separate city and state into individual strings
            state_list = [
                "al", "ak", "az", "ar", "ca", "co", "ct", "dc", "de", "fl",
                "ga", "hi", "id", "il", "in", "ia", "ks", "ky", "la", "me",
                "md", "ma", "mi", "mn", "ms", "mo", "mt", "ne", "nv", "nh",
                "nj", "nm", "ny", "nc", "nd", "oh", "ok", "or", "pa", "ri",
                "sc", "sd", "tn", "tx", "ut", "vt", "va", "wa", "wv", "wi",
                "wy"
            ]

            state_name_list = [
                "alabama", "alaska", "arizona", "arkansas", "california",
                "colorado", "connecticut", "delaware", "florida", "georgia",
                "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas",
                "kentucky", "louisiana", "maine", "maryland", "massachusetts",
                "michigan", "minnesota", "mississippi", "missouri", "montana",
                "nebraska", "nevada", "new hampshire", "new jersey",
                "new mexico", "new york", "north carolina", "north dakota",
                "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island",
                "south carolina", "south dakota", "tennessee", "texas", "utah",
                "vermont", "virginia", "washington", "west virginia",
                "wisconsin", "wyoming"
            ]

            #find out what sort of location we're dealing with
            loc = ""
            #find state abbreviations in location string
            for s in state_list:
                if (" " + s) in location[-3:]:
                    #isolate the state into a variable
                    state = s
                    #isolate the city into a variable
                    city = location.replace((" " + state), "")
                    loc = "abb"
            #find the state names in location string
            for s in state_name_list:
                if (" " + s) in location:
                    #isolate the state into a variable
                    state = s
                    #isolate the city into a variable
                    city = location.replace((" " + state), "")
                    loc = "name"
            if loc == "":
                city, state = zip_converter.city_to_city_state(location)

    #if no location is given
    except IndexError:
        #use user information
        city = user_data["city"]
        state = user_data["state"]
        location = city + " " + state

    #get latitude and longitude from city and state
    latitude, longitude = zip_converter.main(city, state)
    # find the conditions in that location
    import weather
    daily_forecast, hourly_forecast, current_conditions = weather.get_weather(
        latitude, longitude)
    temp = str(current_conditions.get('temp'))
    summ = current_conditions.get('summary')
    # construct a single output string from this input
    print("In " + city + " " + state + ", it is currently " + temp + '\u00b0' +
          "F and " + summ + ".")
    return "In " + city + " " + state + ", it is currently " + temp + '\u00b0' + "F and " + summ + "."