def test_delete_api_posts(url_config): expected_body = {} client = RestClient(url_config) response = client.sends().posts(postId=1).delete() client.sees(response).status_code(200).body(expected_body)
def test_put_api_posts(url_config): body = {'title': 'foo', 'body': 'bar', 'userId': 1} expected_body = {'title': 'foo', 'body': 'bar', 'userId': 1, 'id': 1} client = RestClient(url_config) response = client.sends().posts(postId=1).put(body) client.sees(response).status_code(200).body(expected_body)
def test_put_api_posts_invalid_postId(url_config): body = {'title': 'foo', 'body': 'bar', 'userId': 1} expected_body = {'error': 'id: 101 not found'} client = RestClient(url_config) response = client.sends().posts(postId=101).put(body) client.sees(response).status_code(404).body(expected_body)
def test_put_api_posts_empty_payload(url_config): body = {} expected_body = {'id': 1} client = RestClient(url_config) response = client.sends().posts(postId=1).put(body) client.sees(response).status_code(200).body(expected_body)
def test_get_posts_api_by_id(url_config): client = RestClient(url_config) response = client.sends().posts(postId=1).get() expected_body = { 'userId': 1, 'id': 1, 'title': 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit', 'body': 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto' } client.sees(response).status_code(200).body(expected_body)
def main(): ''' The main method of the application. ''' whisk_display = Display() # Start of app whisk_display.print_general(WELCOME) protocol = None host = None port = None # Get the hostname, if it exists. if len(sys.argv) > 2: host = sys.argv[1] # Get the portname, if it exists. if len(sys.argv) > 3: port = sys.argv[2] rest_client = RestClient(protocol, host, port) protocol, host, port = rest_client.get_protocol_host_port() while True: # Remind the user where the command is currently pointed at. whisk_display.print_general("Using " + protocol + host + ":" + port + "/") # Get the command. command_to_use = retrieve_command(whisk_display).upper() # Check which command this is for and run said command accordingly. if (command_to_use == GET): get_command(whisk_display, rest_client) elif (command_to_use == POST): post_command(whisk_display, rest_client) elif (command_to_use == UPDATE): update_command(whisk_display, rest_client) elif (command_to_use == DELETE): delete_command(whisk_display, rest_client) elif (command_to_use == HELP): help_command(whisk_display) elif (command_to_use == EXIT): break
def test_get_comments_by_postId_query(url_config): client = RestClient(url_config) response = client.sends().comments(query="?postId=1").get() client.sees(response).status_code(200).count(5)
def test_get_posts_api_invalid_postId(url_config): client = RestClient(url_config) response = client.sends().posts(postId=101).get() expected_body = {} client.sees(response).status_code(404).body(expected_body)
def test_get_posts_api_all(url_config): client = RestClient(url_config) response = client.sends().posts().get() client.sees(response).status_code(200).count(100)