def test_delete_location_documents(self) -> None: with tempfile.NamedTemporaryFile() as fp: fp.write(b"DATA") add_location_image(self.client, fp.name, self.location_1) with self.assertRaises(LocationCannotBeDeletedWithDependency): delete_location(self.client, self.location_1) docs = get_location_documents(self.client, self.location_1) self.assertEqual(len(docs), 1) for doc in docs: delete_document(self.client, doc)
def test_location_add_file_with_category(self) -> None: temp_file_path = os.path.join(self.tmpdir, ".".join(["temp_file", "txt"])) with open(temp_file_path, "wb") as tmp_file: tmp_file.write(b"TEST DATA FILE") add_file(self.client, temp_file_path, "LOCATION", self.location_1.id, "test_category") docs = get_location_documents(self.client, self.location_1) for doc in docs: self.assertEqual(doc.category, "test_category") delete_document(self.client, doc)
def test_location_upload_folder(self) -> None: fetch_location = get_location(self.client, [("City", "Lima1")]) self.assertEqual(self.location_1, fetch_location) for suffix in self.suffixes: with open( os.path.join(self.tmpdir, ".".join(["temp_file", suffix])), "wb") as tmp: tmp.write(b"TEST DATA FILE") add_files(self.client, self.tmpdir, "LOCATION", self.location_1.id, "test_category") docs = get_location_documents(self.client, self.location_1) self.assertEqual(len(docs), len(self.suffixes)) for doc in docs: self.assertEqual(doc.category, "test_category") delete_document(self.client, doc)
def test_location_add_file(self) -> None: temp_file_path = os.path.join(self.tmpdir, ".".join(["temp_file", "txt"])) with open(temp_file_path, "wb") as tmp_file: tmp_file.write(b"TEST DATA FILE") add_file( client=self.client, local_file_path=temp_file_path, entity_type="LOCATION", entity_id=self.location_1.id, ) docs = get_location_documents(client=self.client, location=self.location_1) self.assertEqual(len(docs), 1) for doc in docs: delete_document(self.client, doc)