Пример #1
0
    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)
Пример #2
0
 def setUp(self):
     # Create a site to get a site_id
     response = postrequest("sites/", json.dumps(CREATE_SITE_BODY))
     self.assertEqual(response.status_code, 200)
     data = response.json()
     self.site_id = data["features"][0]["properties"]["id_site"]
     self.visit = self.create_visit()
Пример #3
0
 def create_visit(self):
     response = postrequest("sites/{}/visits".format(self.site_id),
                            json.dumps(self.create_visit_body))
     self.assertEqual(response.status_code, 200)
     data = response.json()
     self.assertEqual(len(data["features"]), 1)
     visit = data["features"][0]
     self.assertEqual(visit["id_site"], self.site_id)
     return visit
Пример #4
0
 def test_login(self):
     response = postrequest("login", auth())
     data = response.json()
     self.assertEqual(response.status_code, 200)
     self.assertEqual(data["message"], "Logged in as testuser")
     self.assertIsNotNone(data.get("access_token", None))
     access_token = data["access_token"]
     self.assertIsNotNone(data.get("refresh_token", None))
     refresh_token = data["refresh_token"]
     set_tokens(access_token, refresh_token)
Пример #5
0
    def test_post_photo(self):
        # check that there is currently no photos on the visit
        photos = self.get_photos()
        self.assertEqual(len(photos), 0)

        # post a photo
        response = postrequest(
            "sites/{}/visits/{}/photos".format(self.site_id,
                                               self.visit["id_visit"]),
            None,
            file="../frontend/src/assets/Azure-Commun-019.JPG",
        )
        self.assertEqual(response.status_code, 200)
        data = response.json()
        self.assertEqual(len(data), 1)
        self.assertIn("mares_{}".format(self.site_id), data[0])

        # check that we now get the photo in the site object
        photos = self.get_photos()
        self.assertEqual(len(photos), 1)
        self.assertEqual("/media/{}".format(data[0]), photos[0]["url"])
Пример #6
0
 def test_logout(self):
     response = postrequest("logout", auth())
     self.assertEqual(response.status_code, 200)
     set_tokens(None, None)