class ResultDownloadTestCase(AuthUserTestCase): DEBUG_FILE_NAME = "37c4b87edffc5d198ff5a185cee7ee09" def setUp(self): super(ResultDownloadTestCase, self).setUp() self.udata = UserData(self.user) self.path = os.path.join(self.udata.getStorageDir(), ResultDownloadTestCase.DEBUG_FILE_NAME) self.data_path = self.path + "_data" os.mkdir(self.udata.getStorageDir()) shutil.copytree(os.path.join(settings.MEDIA_ROOT, "testing/template_dir"), self.data_path) self.tempfile = ContentFile("The quick brown fox jumps over the lazy dog") self.tempfile.name = "dummy" self.video = Video() self.video.data = self.tempfile self.video.uid = self.user self.video.vname = "dummy" self.video.vhash = ResultDownloadTestCase.DEBUG_FILE_NAME self.video.status = Video.STATUS_RECONSTRUCTED self.video.save() def tearDown(self): Video.objects.filter(uid=self.user).delete() shutil.rmtree(self.udata.getStorageDir()) super(ResultDownloadTestCase, self).tearDown() def test_unauth(self): self.deauth() response = self.client.get("/uclvr/download", {'name': 'dummy'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], '') self.assertEqual(response.context['req'], views.REQ_DOWNLOAD) self.assertEqual(response.context['payload'], ["Unauthenticated"]) def test_unexisting(self): self.auth() response = self.client.get("/uclvr/download", {'name': 'unexisting'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], 'debug_user') self.assertEqual(response.context['req'], views.REQ_DOWNLOAD) self.assertEqual(response.context['payload'], ["Resource not existing"]) def test_success(self): self.auth() self.video.status = Video.STATUS_RECONSTRUCTED self.video.save() response = self.client.get("/uclvr/download", {'name': 'dummy'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.get('Content-Disposition'), "attachment; filename=dummy.obj") self.assertEqual(response.get('X-Sendfile'), os.path.join(self.data_path, "result.obj")) def test_unfinished(self): self.auth() self.video.status = Video.STATUS_ERROR self.video.save() response = self.client.get("/uclvr/download", {'name': 'dummy'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], 'debug_user') self.assertEqual(response.context['req'], views.REQ_DOWNLOAD) self.assertEqual(response.context['payload'], ["Output not ready or error occurred"])
class DeleteTestCase(AuthUserTestCase): def setUp(self): super(DeleteTestCase, self).setUp() self.udata = UserData(self.user) os.mkdir(self.udata.getStorageDir()) # create video video = Video() tempfile = ContentFile("DUMMY_DATA") tempfile.name = "dummy" video.data = tempfile video.uid = self.user video.vname = "dummy" video.vhash = "" video.status = Video.STATUS_ERROR video.save() def tearDown(self): shutil.rmtree(self.udata.getStorageDir()) Video.objects.filter(uid=self.user).delete() super(DeleteTestCase, self).tearDown() def test_unauthenticated(self): self.deauth() response = self.client.get("/uclvr/delete") self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], '') self.assertEqual(response.context['req'], views.REQ_DEL) self.assertEqual(response.context['payload'], ["Unauthenticated"]) def test_invalid_format(self): self.auth() response = self.client.get("/uclvr/delete", {'wrong_label': ''}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], 'debug_user') self.assertEqual(response.context['req'], views.REQ_DEL) self.assertEqual(response.context['payload'], ["No name given"]) def test_unexisting(self): self.auth() response = self.client.get("/uclvr/delete", {'name': 'unexisting'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], 'debug_user') self.assertEqual(response.context['req'], views.REQ_DEL) self.assertEqual(response.context['payload'], ["Unexisting video"]) def test_delete(self): self.auth() response = self.client.get("/uclvr/delete", {'name': 'dummy'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['uname'], 'debug_user') self.assertEqual(response.context['req'], views.REQ_DEL) self.assertEqual(response.context['payload'], ["Deleted"]) self.assertEqual(len(Video.objects.filter(uid=self.user)), 0, "Video record deleted")
class CeleryTestCase(TestCase): def setUp(self): #create dummy user self.user = User.objects.create_user("debug_user", "", "debug_user") self.user.save() self.udata = UserData(self.user) def tearDown(self): self.user.delete() if os.path.exists(self.udata.getStorageDir()): shutil.rmtree(self.udata.getStorageDir())
class ResourceDataTestCase(AuthUserTestCase): DEBUG_FILE_NAME = "37c4b87edffc5d198ff5a185cee7ee09" def setUp(self): super(ResourceDataTestCase, self).setUp() self.udata = UserData(self.user) # user data is assumed to work correctly self.auth() file_url = os.path.join(self.udata.getStorageDir(), ResourceDataTestCase.DEBUG_FILE_NAME) self.data_path = file_url + "_data" #setup user files in user directory from template testing dir shutil.copytree(os.path.join(settings.MEDIA_ROOT, "testing/template_dir"), self.data_path) self.resource = ResourceData(file_url) def tearDown(self): shutil.rmtree(self.udata.getStorageDir()) super(ResourceDataTestCase, self).tearDown() def test_join_path(self): relpath = self.resource.joinPath("test/path/to/file.tmp") expected = self.udata.joinPath(ResourceDataTestCase.DEBUG_FILE_NAME + "_data/test/path/to/file.tmp") self.assertEqual(relpath, expected) def test_get_output_vsfm(self): ply = self.resource.getVsfmOutput() self.assertIn("result1.ply", ply) self.assertIn("result2.ply", ply) #remove result1, should output result 2 os.remove(os.path.join(self.data_path, "result1.ply")) ply = self.resource.getVsfmOutput() self.assertIn("result2.ply", ply) self.assertNotIn("resutl1.ply", ply) #remove last ply os.remove(os.path.join(self.data_path, "result2.ply")) ply = self.resource.getVsfmOutput() self.assertEqual(ply, []) def test_get_unique_output(self): path = self.resource.getUniqueVsfmOutput() self.assertEqual(path, os.path.join(self.data_path, "result1.ply")) #remove result1, should output result 2 os.remove(os.path.join(self.data_path, "result1.ply")) path = self.resource.getUniqueVsfmOutput() self.assertEqual(path, os.path.join(self.data_path, "result2.ply")) #remove last ply os.remove(os.path.join(self.data_path, "result2.ply")) path = self.resource.getUniqueVsfmOutput() self.assertEqual(path, None) def test_get_output_URL(self): url = self.resource.getFinalOutputFile() self.assertEqual(url, os.path.join(self.data_path, "result.obj")) #remove obj file, should return none os.remove(os.path.join(self.data_path, "result.obj")) url = self.resource.getFinalOutputFile() self.assertEqual(url, None) def test_get_log_path(self): #get log path for ffmpeg name, path = self.resource.getLogPath("ffmpeg") self.assertEqual(name, "ffmpeg.log") self.assertEqual(path, os.path.join(self.data_path, "log/ffmpeg.log")) #get log path for vsfm name, path = self.resource.getLogPath("vsfm") self.assertEqual(name, "vsfm.log") self.assertEqual(path, os.path.join(self.data_path, "log/vsfm.log")) #get log path for meshlab name, path = self.resource.getLogPath("meshlab") self.assertEqual(name, "meshlab.log") self.assertEqual(path, os.path.join(self.data_path, "log/meshlab.log")) #get unexisting name, path = self.resource.getLogPath("foo") self.assertIsNone(name) self.assertIsNone(path) def test_create_log(self): #create a log log = self.resource.getLogFile("mylog") self.assertIsNotNone(log) log.close() self.assertTrue(os.path.exists(os.path.join(self.data_path, "log/mylog.log"))) #create other log log = self.resource.getLogFile("myotherlog") self.assertIsNotNone(log) log.close() self.assertTrue(os.path.exists(os.path.join(self.data_path, "log/myotherlog.log"))) def test_clear_data(self): self.resource.removeProcessingData() self.assertEqual(os.listdir(self.data_path), [])