def test_table_endpoint_returns_data(client): set_session(client) resp = client.get("/table?limit=10&offset=0") assert resp.json == { "rows": [ { "case_number": "1", "case_status": "test", "employer_city": "sf", "employer_name": "google", "employer_state": "ca", "employment_start_date": "Sat, 01 Aug 2020 00:00:00 GMT", "full_time_position": "y", "job_title": "engineer", "prevailing_wage": 100000.0, "visa_class": "test", }, { "case_number": "2", "case_status": "test", "employer_city": "sf", "employer_name": "apple", "employer_state": "ca", "employment_start_date": "Sat, 01 Aug 2020 00:00:00 GMT", "full_time_position": "y", "job_title": "engineer", "prevailing_wage": 200000.0, "visa_class": "test", }, ], "total": 2, }
def test_data_endpoint_returns_queried_data(client): resp = client.get("/data?field1=job_title&value1=engineer") assert resp.json == { "results": [ { "case_number": "1", "case_status": "test", "employer_city": "sf", "employer_name": "google", "employer_state": "ca", "employment_start_date": "2020-08-01", "full_time_position": "y", "job_title": "engineer", "prevailing_wage": 100000.0, "visa_class": "test", }, { "case_number": "2", "case_status": "test", "employer_city": "sf", "employer_name": "apple", "employer_state": "ca", "employment_start_date": "2020-08-01", "full_time_position": "y", "job_title": "engineer", "prevailing_wage": 200000.0, "visa_class": "test", }, ], }
def test_beerecords(client: FlaskClient): res = client.get("/beerecords/1") data = check_ok_response(res, "Retrieve the Bee records success!") assert 0 < len(data["data"]) <= 50 # Verify all needed fields are present in every object in the data list version_matcher = re.compile("^\d+\.\d+\.\d+$") for datum in data["data"]: # Strings: for field in [ "bee_name", "coloration_abdomen", "coloration_thorax", "coloration_head", "flower_shape", "flower_color", "time", "loc_info", "user_id", "record_pic_path", "record_video_path", "flower_name", "city_name", "gender", "bee_behavior", "common_name", "app_version", "elevation" ]: assert field in datum assert type(datum[field]) == str or datum[field] is None # Numbers for field in ["beerecord_id", "bee_dict_id"]: assert field in datum assert type(datum[field]) == int or datum[field] is None # Date must follow specific format try: datetime.strptime(datum["time"], "%Y-%m-%dT%H:%M:%S.%fZ") except ValueError: assert False # App version must follow specific format assert len(version_matcher.findall(datum["app_version"])) == 1
def test_connected(client: FlaskClient): """Test base functionality -- getting from root should return 200 OK, a json object, with the given text.""" res = client.get("/isConnected") assert res.status_code == 200 assert res.content_type == "application/json" loaded = json.loads(res.data) assert type(loaded) == dict assert loaded["message"] == "Welcome! The api is working!"
def test_flowerdex_one(client: FlaskClient): # Base tests -- message must conform to expected response format res = client.get("/flowerdex/5") data = check_ok_response(res, "Retrieve the Flower information success!") assert len(data["data"]) > 0 # Data entry must have needed data entry = data["data"][0] assert type(entry["flower_id"]) == int assert type(entry["flower_latin_name"]) == str assert type(entry["flower_common_name"]) == str
def test_unmatched_flowers(client: FlaskClient): res = client.get("/unmatched_flowers") data = check_ok_response(res, "Retrieve the Bee records success!" ) # TODO This... is not the right response. assert len(data["data"]) > 0 for datum in data["data"]: for field in ["flower_name", "count"]: assert field in datum assert type(field) == str int( datum["count"] ) # Will throw an exception if the field can't be parsed into an int
def test_flower_shapes(client: FlaskClient, url=None): res = client.get("/flowershapes" if url is None else url) data = check_ok_response(res, "Retrieve the flower shapes success!") assert len(data["data"]) > 0 # All fields must be of the right type, must only return flower features for datum in data["data"]: for field in [ "feature_id", "feature_name", "feature_description", "feature_pic_path" ]: assert field in datum assert type(datum[field]) == str assert datum["feature_id"].startswith("fc")
def test_flower_list(client: FlaskClient): res = client.get("/flowerlist") data = check_ok_response(res, "Retrieve the Flower List success!") data = data["data"] for datum in data: for field in [ "latin_name", "main_common_name", "common_name", "main_color", "colors", "bloom_time", "shape", "image_src" ]: assert field in datum assert type(datum[field]) == str or datum[field] is None assert "flower_id" in datum assert type(datum["flower_id"]) == int
def test_beedex_one(client: FlaskClient): # Base tests -- message must conform to expected response format res = client.get("/beedex/5") data = check_ok_response(res, "Retrieve the Bee information success!") assert len(data["data"]) > 0 # Data entry must have needed data for datum in data["data"]: assert type(datum["bee_id"]) == int assert type(datum["bee_name"]) == str assert type(datum["common_name"]) == str assert type(datum["description"]) == str assert type(datum["confused"]) == str assert type(datum["confused"]) == str assert type(datum["bee_pic_path"]) == str assert "abdomen_list" in datum assert "thorax_list" in datum assert "head_list" in datum
def test_beevisrecords(client: FlaskClient): res = client.get("/beevisrecords") data = check_ok_response(res, "Retrieve the Bee records success!") assert len(data["data"]) > 0 # Verify all needed fields are present in every object in the data list for datum in data["data"]: for field in [ "bee_name", "loc_info", "flower_shape", "flower_name", "flower_color", "bee_behavior", "spgender", "elevation", "gender", "date" ]: assert field in datum assert type(datum[field]) == str or datum[field] is None # Date must follow specific format try: datetime.strptime(datum["date"], "%Y-%m-%dT%H:%M:%S.%fZ") except ValueError: assert False
parser_put_for = subparsers.add_parser('put-for') parser_put_for.add_argument('user_name') parser_put_for.add_argument('file_name') parser_get_from = subparsers.add_parser('get-from') parser_get_from.add_argument('user_name') parser_register = subparsers.add_parser('register') parser_register.add_argument('user_name') parser_get = subparsers.add_parser('get') parser_put = subparsers.add_parser('put') parser_put.add_argument('file_name') args = parser.parse_args() if 'user_name' not in user_config and args.command != "register": print("You have not registered with the server yet.") exit(1) if args.command == "put-for": client.put_for(user_config, args.user_name, args.file_name) elif args.command == "get-from": client.get_from(user_config, args.user_name) elif args.command == "register": client.register(user_config, args.user_name) elif args.command == "get": client.get(user_config) elif args.command == "put": client.put(user_config, args.file_name)
def test_flowerdex_none(client: FlaskClient): res = client.get("/flowerdex/999999") check_err_response(res, "Flower not found!", 404)
def test_flowerdex_all(client: FlaskClient): res = client.get("/flowerdex") data = check_ok_response(res, "Retrieve the Flower information success!") assert len(data["data"]) > 0
def test_beedex_none(client: FlaskClient): res = client.get("/beedex/999999") check_err_response(res, "Bee Dexes not found!", 200)