From 19c9a74cc1d69aa3fb3336c4fee79cd306204a52 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 7 Jan 2020 16:33:21 -0500 Subject: [PATCH 1/2] Testing code for building search --- .../apps/bis/features/addressSearch.feature | 16 ++++++++ .../apps/bis/features/steps/addressSearch.py | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 bloclink/apps/bis/features/addressSearch.feature create mode 100644 bloclink/apps/bis/features/steps/addressSearch.py diff --git a/bloclink/apps/bis/features/addressSearch.feature b/bloclink/apps/bis/features/addressSearch.feature new file mode 100644 index 0000000..31ec0e9 --- /dev/null +++ b/bloclink/apps/bis/features/addressSearch.feature @@ -0,0 +1,16 @@ +Feature: Building search + + Scenario: Load building search page + Given request method as "GET" + When user request the application URi + Then result page will include code "200" + + Scenario: Search for a valid building + Given request method as "PUT" + When user search for a valid address + Then result page will include code "200" + + Scenario: Search for an invalid building + Given request method as "PUT" + When user search for a invalid address + Then result page will include code "400" diff --git a/bloclink/apps/bis/features/steps/addressSearch.py b/bloclink/apps/bis/features/steps/addressSearch.py new file mode 100644 index 0000000..e7ed7d6 --- /dev/null +++ b/bloclink/apps/bis/features/steps/addressSearch.py @@ -0,0 +1,40 @@ +from behave import * +import requests + + +# api_endpoints = {} +# request_headers = {} +# response_texts={} +# request_bodies = {} +# api_url=None +response_codes = {} +get_url = 'http://0.0.0.0:3000/' +post_url = 'http://0.0.0.0:5410/buildings/bis/submit-building/' +headers = {} +request = { + 'method': '', +} + +@given('request method as "{method}"') +def step_impl(context, method): + request['method'] = method + +@when('user request the application URi') +def step_impl(context): + response = requests.get(url=get_url, headers={'Content-Type': 'GET'}) + response_codes[request['method']] = response.status_code + +@when('user search for a valid address') +def step_impl(context): + response = requests.put(url=post_url, json={'address': '81 Prospect Street, Staten Island, New York 10304, United States'}, headers={'Content-Type': 'PUT'}) + response_codes[request['method']] = response.status_code + +@when('user search for a invalid address') +def step_impl(context): + response = requests.put(url=post_url, json={'address': 'New Portland, Maine, United States'}, headers={'Content-Type': 'PUT'}) + response_codes[request['method']] = response.status_code + +@then('result page will include code "{code}"') +def step_impl(context, code): + assert code == str(response_codes[request['method']]) + # assert True is not False -- GitLab From 5a0eee53c2c312daad9eaa466e20bb40d1dc57d2 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Wed, 8 Jan 2020 15:40:58 -0500 Subject: [PATCH 2/2] Restructure the testing code --- .../apps/bis/features/addressSearch.feature | 31 +++++++--- .../apps/bis/features/steps/addressSearch.py | 58 ++++++++++--------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/bloclink/apps/bis/features/addressSearch.feature b/bloclink/apps/bis/features/addressSearch.feature index 31ec0e9..8c87b36 100644 --- a/bloclink/apps/bis/features/addressSearch.feature +++ b/bloclink/apps/bis/features/addressSearch.feature @@ -1,16 +1,29 @@ Feature: Building search - Scenario: Load building search page - Given request method as "GET" - When user request the application URi - Then result page will include code "200" - Scenario: Search for a valid building - Given request method as "PUT" - When user search for a valid address + Given a valid building address + | address | + | 489 Hart Street, Brooklyn, New York 11221, United States | + | 81 Prospect Street, Staten Island, New York 10304, United States | + | Oakland California Temple, 4770 Lincoln Ave, Oakland, California 94602, United States | Then result page will include code "200" + And result page will include success as "True" Scenario: Search for an invalid building - Given request method as "PUT" - When user search for a invalid address + Given an invalid building address + | address | + | Staten Island, New York, New York, United States | + | New York, New York, New York 10453, United States | + | New York, New York, United States | + | New York, New York 10453, United States | + | East New York, Brooklyn, New York, New York 11208, United States | + Then result page will include code "400" + And result page will include success as "False" + + Scenario: Search for a not covered building + Given a not covered building address + | address | + | New Jersey Motor Vehicle Commission, 481 US Route 46 W, Wayne, New Jersey 07470, United States | + | 60 East Jamaica Avenue, Valley Stream, New York 11580, United States | Then result page will include code "400" + And result page will include success as "False" diff --git a/bloclink/apps/bis/features/steps/addressSearch.py b/bloclink/apps/bis/features/steps/addressSearch.py index e7ed7d6..da73319 100644 --- a/bloclink/apps/bis/features/steps/addressSearch.py +++ b/bloclink/apps/bis/features/steps/addressSearch.py @@ -1,40 +1,42 @@ from behave import * import requests +import json -# api_endpoints = {} -# request_headers = {} -# response_texts={} -# request_bodies = {} -# api_url=None -response_codes = {} -get_url = 'http://0.0.0.0:3000/' -post_url = 'http://0.0.0.0:5410/buildings/bis/submit-building/' -headers = {} -request = { - 'method': '', -} - -@given('request method as "{method}"') -def step_impl(context, method): - request['method'] = method - -@when('user request the application URi') +endpoint = 'http://0.0.0.0:5410/buildings/bis/submit-building/' +responses = [] + +@given('a valid building address') def step_impl(context): - response = requests.get(url=get_url, headers={'Content-Type': 'GET'}) - response_codes[request['method']] = response.status_code + global responses + responses = [] + for row in context.table: + response = requests.put(url=endpoint, json={'address': row['address']}, headers={'Content-Type': 'PUT'}) + responses.append(response) -@when('user search for a valid address') +@given('an invalid building address') def step_impl(context): - response = requests.put(url=post_url, json={'address': '81 Prospect Street, Staten Island, New York 10304, United States'}, headers={'Content-Type': 'PUT'}) - response_codes[request['method']] = response.status_code + global responses + responses = [] + for row in context.table: + response = requests.put(url=endpoint, json={'address': row['address']}, headers={'Content-Type': 'PUT'}) + responses.append(response) -@when('user search for a invalid address') +@given('a not covered building address') def step_impl(context): - response = requests.put(url=post_url, json={'address': 'New Portland, Maine, United States'}, headers={'Content-Type': 'PUT'}) - response_codes[request['method']] = response.status_code + global responses + responses = [] + for row in context.table: + response = requests.put(url=endpoint, json={'address': row['address']}, headers={'Content-Type': 'PUT'}) + responses.append(response) @then('result page will include code "{code}"') def step_impl(context, code): - assert code == str(response_codes[request['method']]) - # assert True is not False + for response in responses: + assert code == str(response.status_code) + +@then('result page will include success as "{TrueOrFalse}"') +def step_impl(context, TrueOrFalse): + for response in responses: + assert TrueOrFalse == str(json.loads(response.text)['success']) + -- GitLab