def test_api_data(self): res = app.get('/api/sample').get_data(as_text=True) data = json.loads(res) self.assertEqual(data, []) res = app.get('/api/sample?query=a').get_data(as_text=True) data = json.loads(res) self.assertEqual(data[0], 'a') self.assertEqual(data[1], 'aa')
def test_run_has_tests_as_sub_resources(self): response = app.get('/runs/1234/test_cases') test_cases = json.loads(response.data) self.assertEquals(len(test_cases), 1) self.assertEquals(test_cases['test_cases'][0]['name'], 'nice test case') self.assertEquals(test_cases['test_cases'][0]['status'], 'success')
def test_main_entry_point_has_key_elements(): res = app.get("/library/api") assert_in("services", res.json.keys()) assert_in("documentation", res.json.keys()) assert_in("books", res.json["services"].keys()) assert_in("users", res.json["services"].keys()) assert res.json["documentation"].endswith("/library/api/docs")
def test_wasted_time_route(): rv = app.get('/time') check_content_type(rv.headers) resp = json.loads(rv.data) # make sure we get a response eq_(rv.status_code, 200) # make sure there are no users eq_(len(resp), 0) # create a user d = dict( first_name="User1First", last_name="User1Last", email="*****@*****.**" ) rv = app.post('/users', data=d) check_content_type(rv.headers) eq_(rv.status_code, 201) # Verify we sent the right data back resp = json.loads(rv.data) eq_(resp["email"], "*****@*****.**") eq_(resp["first_name"], "User1First") eq_(resp["last_name"], "User1Last") # Get users again...should have one rv = app.get('/users') check_content_type(rv.headers) resp = json.loads(rv.data) # make sure we get a response eq_(rv.status_code, 200) eq_(len(resp), 1) # GET the user with specified ID rv = app.get('/users/%s' % resp[0]['id']) check_content_type(rv.headers) eq_(rv.status_code, 200) resp = json.loads(rv.data) eq_(resp["email"], "*****@*****.**") eq_(resp["first_name"], "User1First") eq_(resp["last_name"], "User1Last") # Try and add Duplicate User Email rv = app.post('/users', data=d) check_content_type(rv.headers) eq_(rv.status_code, 500)
def test_redirect_view(self, mocker, app): mocker.patch('lib.redis.Redis', return_value=FakeStrictRedis()) payload = { 'category': 'auto', 'protocol': 'http', 'origin': 'www.google.com' } response = app.post('/generate', data=payload) url = response.get_json()['url'] shorten = url.split('/')[-1] redirect = app.get('/%s' % shorten) location = redirect.headers.get('Location') assert redirect.status_code == 302 assert location == '%s://%s' % (payload['protocol'], payload['origin'])
def handle_index(): redir = None if nohttps == None: proto = request.headers.get("X-Forwarded-Proto") if not proto == "https": redir = _check_ssl(request.url) if not redir == None: return redir with open(path) as json_data: data = json.load(json_data) # creating altname list for to be deprecated url links altapps=[] for app in data['apps']: if app.get('altname'): altapps.append(app['altname']) return render_template("index.html", apps=[app['name'] for app in data['apps']], altapps=altapps )
def get_app_status_data(): # Use qpylib REST helper method to make a call to QRadar GAF API and return all apps result = qpylib.REST('GET', '/api/gui_app_framework/applications') if result.status_code != 200: return jsonify("QRadar returned {0} ({1})".format( str(result.status_code), json.dumps(result.json()["message"]))), 500 # Extract relevant details from response, excluding the app manager app itself app_details = [(app.get("manifest").get("name", "No Name"), app.get("application_state").get("application_id", "No ID"), app.get("manifest").get("version", "No Version"), app.get("application_state").get("status", "No Status"), app.get("manifest").get("uuid", "No UUID")) for app in result.json() if app.get("manifest").get("uuid") != OWN_UUID] return jsonify(app_details)
def test_api_data(): data = app.get('/api/items').get_data(as_text=True) assert(len(json.loads(data)) > 0)
def test_response_codes(): '''Validate major routes yield 200 response codes''' for route in routes: print(' * testing route', route) response = app.get(route) assert response.status_code == 200
def test_api_param(self): PAGE = 1 res = app.get( '/api/sample?page={0}'.format(PAGE)).get_data(as_text=True) data = json.loads(res) self.assertEqual(data, [])
def test_url_list_view(self, mocker, app): mocker.patch('lib.redis.Redis', return_value=FakeStrictRedis()) response = app.get('/list') assert response.mimetype == 'text/html' assert response.status_code == 200
def test_api_data(): data = app.get('/api/items').get_data(as_text=True) assert('title' in json.loads(data)[0])
def test_run_has_collection_of_test_cases(self): response = app.get('/runs/1234') run = json.loads(response.data) self.assertEquals(len(run['test_cases']), 1) self.assertEquals(run['test_cases'][0]['name'], 'nice test case') self.assertEquals(run['test_cases'][0]['status'], 'success')
def handle_app(appname): verbose = False chosen_region = None query_string = request.query_string if not query_string == "": for query in query_string.split('&'): if "verbose" in query.lower(): if query.endswith("1"): verbose = True elif "region" in query.lower(): chosen_region = query[7:] suffix = ".json" if verbose: suffix = ".verbose" + suffix if chosen_region: suffix = "." + chosen_region + suffix app_cache_file = os.path.join(cache_root_directory,appname.lower() + suffix) read_from_cache = True try: print(app_cache_file) with open(app_cache_file, "r") as cache: cache_time = float(cache.readline().strip()) current_time = time.time() if (current_time - cache_time) > cache_timeout_period_in_seconds: read_from_cache = False except IOError: read_from_cache = False if read_from_cache: print("Reading cached data for this request. here") else: print("Cache is out of date. Refreshing for this request.") try: with open(path) as json_data: data = json.load(json_data) ret = {} if verbose: print (request.url) redir = None if nohttps == None: proto = request.headers.get("X-Forwarded-Proto") if not proto == "https": redir = _check_ssl(request.url, verbose) if not redir == None: return redir for app in data['apps']: # create url link for both name and alternative name for ip-range apps if appname.lower() == app['name'].lower() or appname.lower() == str(app.get('altname')).lower(): app_config = app['config'] for config in app_config: if config.get('s3filepath'): datapath = config.get('localpath') awslib._get_file(bucket_name, config['s3filepath'], datapath) with open(datapath) as filedata: output = json.load(filedata) break elif config.get('R53'): ret = {} for item in config['R53']: ret[item['Name']] = {} ret[item['Name']]['all_ips'] = [] ret[item['Name']]['all_ips'] = awslib._get_records_from_zone(item['HostedZoneId'], item['Pattern'], item['Domain']) break dnsname = config['dnsname'] bs_app = config['beanstalk_app_name'] region = config['region'] # only run next section if region equal chosen_region if chosen_region: if chosen_region != region: continue exclusions = config['exclusions'] eip_check = config.get('show_eip') lb_check = config.get('show_lb_ip') inst_check = config.get('show_inst_ip') if ret.get(region) == None: ret[region] = {} lb_name = awslib._active_balancer(dnsname, region) if ret[region].get('all_ips') == None: ret[region]['all_ips'] = [] if not eip_check == None: eips = awslib._list_eips(region, filter=exclusions) if verbose: if ret[region].get('eips') == None: ret[region]['eips'] = eips else: ret[region]['eips'].extend(eips) if eip_check: ret[region]['all_ips'].extend(eips) if not lb_check == None: lb_url = awslib._environment_descr(bs_app, lb_name, region) elb = awslib._balancer_ip(lb_url) if verbose: if ret[region].get('elb') == None: ret[region]['elb'] = elb else: ret[region]['elb'].extend(elb) if lb_check: ret[region]['all_ips'].extend(elb) if not inst_check == None: inst_ips = awslib._instance_ip(lb_name, region) if verbose: if ret[region].get('instance_ips') == None: ret[region]['instance_ips'] = inst_ips else: ret[region]['instance_ips'].extend(inst_ips) if inst_check: ret[region]['all_ips'].extend(inst_ips) if not ret: return redirect(url_for('handle_index'), code=302) else: #sort ip list in ret when it can ret = ip_list_sort(ret) _write_cache(app_cache_file,ret) except: print ("Error: Unable to load new information for app: " + str(appname)) traceback.print_exc() with open(app_cache_file, "r") as cache: # read the first line as cache time cache_time = cache.readline() line = cache.readline() return jsonify(**eval(line))
def auth_login(self): response = app.get("/") self.assetEqual(response.status_code, 200)
def test_user_page(test_client): response = app.get('/shirts') assert response.status_code == 200
def test_showlist_page(test_client): response = app.get('/send') assert response.status_code == 200
def test_main_page(test_client): response = app.get('/') assert response.status_code == 200
def test_run_has_skips_attribute(self): self.response = app.get('/runs/1234') self.run = json.loads(self.response.data) self.assertEquals(self.run['skips'], 8)
def test_get_runs_index(self): self.response = app.get('/runs') self.assertEquals(self.response.status_code, 200)
def test_successful_get(app): response = app.get('http://localhost:5000/pokemon/charizard') assert response.status_code == 200 assert response.json['pokemon'] == 'charizard'
def test_run_has_id(self): self.response = app.get('/runs/1234') self.run = json.loads(self.response.data) self.assertEquals(self.run['id'], '1234')
def test_index_view(self, app): response = app.get('/') assert response.mimetype == 'text/html' assert response.status_code == 200
def test_run_has_success_percentage(self): self.response = app.get('/runs/1234') self.run = json.loads(self.response.data) self.assertEquals(self.run['success_percentage'], 80)
def test_not_found_view(self, mocker, app): mocker.patch('lib.redis.Redis', return_value=FakeStrictRedis()) response = app.get('/not_exist_shorten_url') # 404 Error Page assert response.mimetype == 'text/html' assert response.status_code == 200
def test_admin_page(test_client): response = app.get('/shirt/<product_id>') assert response.status_code == 200
def test_returns_404_when_not_found(self): self.response = app.get('/runs/12343') self.assertEquals(self.response.status_code, 404)
def test_index_response(self): response = app.get('/') self.assertEqual(response.status_code, 200)
def get_json(route): '''Return a JSON response from a route''' data = app.get(route).get_data(as_text=True) return json.loads(data)
def test_index_response(): response = app.get('/') assert(response.status_code == 200)
def test_booking_page(test_client): response = app.get('/contact') assert response.status_code == 200
def test_3_model_page(self): with self.app as app: response = app.get('/model', follow_redirects=True) self.assertEqual(response.status_code, 200)
def test_no_book_found_throws_404(): res = app.get("/library/api/books/NOTAREALISBN", status=404)
def create_user(): new_user = User('James','*****@*****.**', 'asdfasdf') db.session.add(new_user) db.session.commit() def login(username, password): return app.post('users/', data=dict( name=username, password=password ), follow_redirects=True) create_user() login('James','asdfasdf') #response = app.get('tasks/tasks/', follow_redirects=True) response_tasks=app.get('/tasks/tasks', follow_redirects=True) response_tasks_text=response_tasks.get_data(as_text=True) if response_tasks_text.find('Add a new task')!=-1: print ('success') print(response_tasks_text) #response_text=response.get_data(as_text=True) #response_text.find('Welcome') db.drop_all()
def test_not_found_get(app): response = app.get('http://localhost:5000/pokemon/charizars') assert response.status_code == 404