async def test_get_bike(self, client: TestClient, random_bike): """Assert that you can get the data of a single bike.""" resp = await client.get(f'/api/v1/bikes/{random_bike.identifier}') schema = JSendSchema.of(bike=BikeSchema()) data = schema.load(await resp.json()) assert data["data"]["bike"]["identifier"] == random_bike.identifier
async def test_create_issue_for_bike(self, client, random_user, random_bike): response = await client.post( f"/api/v1/bikes/{random_bike.identifier}/issues", headers={"Authorization": f"Bearer {random_user.firebase_id}"}, json={"description": "I HATE IT"}) response_data = JSendSchema.of(issue=IssueSchema()).load( await response.json()) assert response_data["data"]["issue"][ "bike_identifier"] == random_bike.identifier
async def test_get_bikes(self, client: TestClient, random_bike): """Assert that anyone can get the entire list of bikes.""" resp = await client.get('/api/v1/bikes') schema = JSendSchema.of(bikes=Many(BikeSchema())) data = schema.load(await resp.json()) assert data["status"] == JSendStatus.SUCCESS assert isinstance(data["data"]["bikes"], list) assert len(data["data"]["bikes"]) == 1 assert data["data"]["bikes"][0]["identifier"] == random_bike.identifier
async def test_get_bike_rentals(self, client: TestClient, random_bike, random_admin): """Assert that you can get the rentals for a given bike.""" response = await client.get( f'/api/v1/bikes/{random_bike.identifier}/rentals', headers={"Authorization": f"Bearer {random_admin.firebase_id}"}) response_schema = JSendSchema.of(rentals=Many(RentalSchema())) response_data = response_schema.load(await response.json()) assert response_data["status"] == JSendStatus.SUCCESS assert isinstance(response_data["data"]["rentals"], list)
async def test_get_broken_bikes(self, client: TestClient, random_admin, random_bike): """Assert that an admin can get broken bikes from the system.""" await open_issue(random_admin, "This is broken", random_bike) response = await client.get( f"/api/v1/bikes/broken", headers={"Authorization": f"Bearer {random_admin.firebase_id}"}) response_data = JSendSchema.of(bikes=Many(BikeSchema())).load( await response.json()) assert response_data["status"] == JSendStatus.SUCCESS assert len(response_data["data"]["bikes"]) == 1
async def test_get_issues_for_bike(self, client, random_admin, random_bike): await Issue.create(user=random_admin, bike=random_bike, description="OMG AWFUL") response = await client.get( f"/api/v1/bikes/{random_bike.identifier}/issues", headers={"Authorization": f"Bearer {random_admin.firebase_id}"}) response_data = JSendSchema.of(issues=Many(IssueSchema())).load( await response.json()) assert response_data["status"] == JSendStatus.SUCCESS assert "issues" in response_data["data"] assert all(issue["bike_identifier"] == random_bike.identifier for issue in response_data["data"]["issues"])
async def test_register_bike(self, client: TestClient): """Assert that a bike can register itself with the system.""" request_schema = BikeRegisterSchema() request_data = { "public_key": random_key(32), "master_key": MASTER_KEY, "type": BikeType.ROAD, } request_json = request_schema.dump(request_data) response = await client.post('/api/v1/bikes', json=request_json) response_schema = JSendSchema.of(bike=BikeSchema()) response_data = response_schema.load(await response.json()) assert response_data["status"] == JSendStatus.SUCCESS
async def test_create_bike_rental(self, client: TestClient, random_user, random_bike, bike_connection_manager): """Assert that you can create a rental.""" await bike_connection_manager.update_location(random_bike, Point(0, 0)) response = await client.post( f'/api/v1/bikes/{random_bike.identifier}/rentals', headers={"Authorization": f"Bearer {random_user.firebase_id}"}) response_data = JSendSchema.of(rental=CurrentRentalSchema()).load( await response.json()) assert response_data["status"] == JSendStatus.SUCCESS assert "price" not in response_data["data"]["rental"] assert response_data["data"]["rental"][ "bike_identifier"] == random_bike.identifier assert response_data["data"]["rental"]["user_id"] == random_user.id