def test_create_site(self): body = CREATE_SITE_BODY.copy() # Should fail when no site_type provided del body["site_type"] response = postrequest("sites/", json.dumps(body)) self.assertEqual(response.status_code, 400) data = response.json() self.assertIn("not-null constraint", data["error_message"]) # Should fail with incorrect site_type body["site_type"] = "wrong" response = postrequest("sites/", json.dumps(body)) self.assertEqual(response.status_code, 400) data = response.json() self.assertIn("invalid input value for enum sitetype", data["error_message"]) # Success for mare body["site_type"] = "mare" response = postrequest("sites/", json.dumps(body)) self.assertEqual(response.status_code, 200) data = response.json() # Test that site is now getting returned site_id = data["features"][0]["properties"]["id_site"] response = getrequest("sites/") self.assertEqual(response.status_code, 200) data = response.json() sites_ids = [f["properties"]["id_site"] for f in data["features"]] self.assertIn(site_id, sites_ids)
def test_create_visit(self): # Create 2 visits on same site visit1 = self.create_visit() visit2 = self.create_visit() self.assertNotEqual(visit1["id_visit"], visit2["id_visit"]) # Query site and check last_visit response = getrequest("sites/{}".format(self.site_id)) self.assertEqual(response.status_code, 200) data = response.json() site = data["features"][0]["properties"] self.assertEqual(site["last_visit"]["id_visit"], visit2["id_visit"])
def get_photos(self): resp = getrequest("sites/{}".format(self.site_id)) return resp.json()["features"][0]["properties"]["photos"]
def test_site_types(self): response = getrequest("sites/types") self.assertEqual(response.status_code, 200) data = response.json() self.assertGreaterEqual(data["count"], 1) self.assertTrue("mare" in data["site_types"])
def test_get_sites(self): resp = getrequest("sites") data = resp.json() self.assertEqual(data["type"], "FeatureCollection")
def test_get_observations(self): response = getrequest("observations") self.assertEqual(response.status_code, 200) data = response.json() self.assertEqual(data["type"], "FeatureCollection") self.assertIsInstance(data["features"], list)