def get_login_session(self): data = { 'j_username': USERNAME, 'j_password': PASSWORD, 'from': '/', 'Submit': 'log in', 'json': '{"j_username": "******", "j_password": "******", "remember_me": false, "from": "/"}' } session = requests.Session() response = session.post(JENKINS_HOST_ANDROID + '/j_acegi_security_check', data=data) try: assert_equals(response.status_code, 200) return session except: raise ("cannot login jenkins server!")
def test_001_get_all_services_sanity(self): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH) response = http_util.get(url, headers=common_utils.get_basic_headers()) assert_equals(response.status_code, 200) assert_true( common_utils.validate_schema( response.json(), services_schemas.services_get_all_schema))
def test_008_get_services_error(self, service): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH, self.testcase_data[service]) response = http_util.get(url, headers=common_utils.get_basic_headers()) response_json = response.json() assert_equals(response.status_code, 404) assert_true( common_utils.validate_schema( response_json, services_schemas.services_error_schema))
def test_001_complete_on_boarding(self, onboarding_team, onboarding_nationality): self.on_boarding_screen.search_and_select_content(onboarding_team) self.on_boarding_screen.search_and_select_content( onboarding_nationality) self.on_boarding_screen.accept_privacy_confirmation() self.following_screen.navigate_to_following_page() assert_equals(self.following_screen.get_favourite_club_name(), onboarding_team) assert_equals(self.following_screen.get_favourite_nation_name(), onboarding_nationality)
def test_003_create_services_error(self, service): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH) error_payload = {"error_name": service} response = http_util.post(url, request_json=error_payload, headers=common_utils.get_basic_headers()) response_json = response.json() assert_equals(response.status_code, 400) assert_true( common_utils.validate_schema( response_json, services_schemas.services_error_schema))
def test_004_create_services_success(self, service): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH) response = http_util.post( url, request_json=common_utils.create_services_payload(service), headers=common_utils.get_basic_headers()) response_json = response.json() assert_equals(response.status_code, 201) assert_true( common_utils.validate_schema( response_json, services_schemas.services_success_schema)) assert_equals(response_json["name"], service, "Service name did't match") self.testcase_data[service] = str(response_json["id"])
def tc_002_topic_search_perfect_match_test(self, announcement): preporter.info("Opening URL: " + config.BASE_URL) self._driver.open_url(config.BASE_URL) self._home_page.navigate_to_help_tab() self._home_page.click_to_community_link() self._driver.switch_window() preporter.info("Searching for " + announcement) self._community_page.search_text(announcement) try: assert_equals(self._community_page.get_first_order_search_results_titles()[0], announcement, "Item is not in top of search results") self._driver.close_tab() except AssertionError: self._driver.close_tab() fail("Item is not in top of search results")
def tc_001_topic_title_test(self, topic): preporter.info("Opening URL: " + config.BASE_URL) self._driver.open_url(config.BASE_URL) self._home_page.navigate_to_help_tab() self._home_page.click_to_community_link() self._driver.switch_window() preporter.info("Searching for " + topic) self._community_page.search_text(topic) self._community_page.find_and_click_topic_from_search_results(topic) try: assert_equals(self._community_page.get_topic_title(), topic, "Expected topic title not proper") self._driver.close_tab() except AssertionError: self._driver.close_tab() fail("Expected topic title not proper")
def test_001_create_service(self): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH) payload = common_utils.create_services_payload( data.SINGLE_USER_WORKFLOW_SERVICES[0]) response = http_util.post(url, request_json=payload, headers=common_utils.get_basic_headers()) assert_equals(response.status_code, 201) response_json = response.json() assert_true( common_utils.validate_schema( response_json, services_schemas.services_success_schema)) assert_equals(response_json["name"], data.SINGLE_USER_WORKFLOW_SERVICES[0]) self.testcase_data[response_json["name"]] = response_json["id"]
def test_003_update_service(self): url = common_utils.build_resource_endpoint( BASE_ENDPOINT, SERVICES_PATH, resource=str( self.testcase_data[data.SINGLE_USER_WORKFLOW_SERVICES[0]])) payload = common_utils.create_services_payload("updated service name") response = http_util.patch(url, request_json=payload, headers=common_utils.get_basic_headers()) assert_equals(response.status_code, 200) response_json = response.json() assert_true( common_utils.validate_schema( response_json, services_schemas.services_success_schema)) assert_equals( response_json["id"], self.testcase_data[data.SINGLE_USER_WORKFLOW_SERVICES[0]]) assert_equals(response_json["name"], "updated service name", "Updated name did't match") # Performing a get call to check if the resource got updated properly get_response = http_util.get(url, headers=common_utils.get_basic_headers()) get_response_json = get_response.json() assert_equals( get_response_json["id"], self.testcase_data[data.SINGLE_USER_WORKFLOW_SERVICES[0]]) assert_equals(get_response_json["name"], "updated service name", "Updated name did't match") # updating the data back to original to maintain state payload = common_utils.create_services_payload( data.SINGLE_USER_WORKFLOW_SERVICES[0]) update_response = http_util.patch( url, request_json=payload, headers=common_utils.get_basic_headers()) self.testcase_data[update_response.json() ["name"]] = response_json["id"]
def tc_004_available_countries_url_test(self, country): preporter.info("Opening URL: " + config.BASE_URL) self._driver.open_url(config.BASE_URL) try: self._home_page.click_on_current_selected_country() self._home_page.search_in_available_countries(country) self._home_page.click_on_first_search_item() preporter.info("Searching for country: " + country) preporter.info("Matching with URL: " + self._driver.get_url()) assert_equals(self._driver.get_url(), countries_to_url_map[country], "URL did't match with country code: " + country) except (TimeoutException, WebDriverException): self._home_page.click_on_hiring_banner() # TODO Find a better method to handle the banner self._home_page.click_on_homepage() self._home_page.click_on_current_selected_country() self._home_page.search_in_available_countries(country) self._home_page.click_on_first_search_item() preporter.info("Searching for country: " + country) preporter.info("Matching with URL: " + self._driver.get_url()) assert_equals(self._driver.get_url(), countries_to_url_map[country], "URL did't match with country code: " + country)
def test_006_delete_services_success(self, service): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH, self.testcase_data[service]) response = http_util.delete(url, headers=common_utils.get_basic_headers()) response_json = response.json() assert_equals(response.status_code, 200) assert_true( common_utils.validate_schema( response_json, services_schemas.services_success_schema)) assert_equals(str(response_json["id"]), self.testcase_data[service]) assert_equals(service, response_json["name"])
def test_004_delete_service(self): url = common_utils.build_resource_endpoint( BASE_ENDPOINT, SERVICES_PATH, resource=str( self.testcase_data[data.SINGLE_USER_WORKFLOW_SERVICES[0]])) response = http_util.delete(url, headers=common_utils.get_basic_headers()) assert_equals(response.status_code, 200) response_json = response.json() assert_true( common_utils.validate_schema( response_json, services_schemas.services_success_schema)) assert_equals(response_json["name"], data.SINGLE_USER_WORKFLOW_SERVICES[0]) assert_equals( response_json["id"], self.testcase_data[data.SINGLE_USER_WORKFLOW_SERVICES[0]]) get_response = http_util.get(url, headers=common_utils.get_basic_headers()) assert_equals(get_response.status_code, 404)
def test_002_get_all_services_pagination(self): url = common_utils.build_resource_endpoint(BASE_ENDPOINT, SERVICES_PATH) response = http_util.get(url, headers=common_utils.get_basic_headers()) assert_equals(response.status_code, 200) assert_true( common_utils.validate_schema( response.json(), services_schemas.services_get_all_schema)) limit = response.json()["limit"] url = common_utils.build_resource_endpoint( BASE_ENDPOINT, SERVICES_PATH) + "?$skip=" + str(limit) paginated_response = http_util.get( url, headers=common_utils.get_basic_headers()) assert_equals(response.status_code, 200) assert_true( common_utils.validate_schema( response.json(), services_schemas.services_get_all_schema)) assert_equals(paginated_response.json()["skip"], limit)
def request(url, method, json_data=None, session=None, headers=None, assertion=None): data = '' status_code = '' req_json = '' try: text = session.request(url=url, method=method, json=json_data, headers=headers).text if len(text) <= 1000: preporter.info(text) req_json = json.loads(text) status_code = req_json["status"] data = req_json["data"] preporter.info('接口返回status为:' + str(status_code)) if len(str(data)) >= 3000: preporter.info('接口返回data为(限制长度为3000):' + str(data)[0:3000]) else: preporter.info('接口返回data为:' + str(data)) except BaseException: if not assertion: fail('无法获取status或data!') else: key = assertion.keys() assert_equals(assertion[key], req_json[key]) finally: if not assertion: if not status_code == 'ok': preporter.error('接口响应:' + str(req_json)) else: assert_equals(status_code, 'ok') assert_equals(status_code, 'ok') if data is not None: return data
def test_us(self): assert_equals("us", self.expected)
def test_2(self, host, port): self = request_perform(request_get(host, port)) assert_equals(self.getinfo(self.RESPONSE_CODE), 400)
def test_3_2(self, message): args = Namespace(request="POST", message=message) client.main(args) assert_equals(sys.stdout.getline().strip(), 400)
def test_4_2(self, number): args = Namespace(equest="POST", message="test_message", qnumber=number) client.main(args) assert_equals(sys.stdout.getline().strip(), 400)
def test1(self, host, port, message): self = request_perform(request_post(host, port)) assert_equals(self.getinfo(self.RESPONSE_CODE), 200)
def test_baidu_set(self): """Test set preference""" baidu = BAI_DU(self.browser) baidu.preferences() assert_equals(1, 0)
def test_baidu_search(self): """Test search""" baidu = BAI_DU(self.browser) baidu.search("test") assert_equals(1, 1)
def test_baidu_search(self): """Test search""" baidu = BAI_DU(self.browser) baidu.search("test") assert_equals(1, 1)
def test_baidu_set(self): """Test set preference""" baidu = BAI_DU(self.browser) baidu.preferences() assert_equals(1, 0)
def test2(self): assert_equals(20, self.expected) # failed
def test_cn(self): assert_equals("cn", self.expected)
def test_2_2(self, port, request): args = Namespace(port=port, request=request) client.main(args) assert_equals(sys.stdout.getline().strip(), 400)
def test1(self): assert_equals(10, self.expected) # pass
def test1_2(self, address, request): args = Namespace(host=address, port=80, request=request) client.main(args) assert_equals(sys.stdout.getline().strip(), 400)