def test_process_jar_invalid_zipfile(self): testjarfile = SimpleUploadedFile( 'foo.jar', b'invalidzipfilehehehe', content_type='application/java-archive') try: processjar.process_jar(testjarfile, 'someAppName') self.fail('Expected ValueError') except ValueError as ve: self.assertEqual('is not a valid zip file', str(ve))
def test_process_jar_on_in_memory_file_expect_name_mismatch(self): fake_jar_file = io.BytesIO() with zipfile.ZipFile(fake_jar_file, mode='w') as zf: zf.writestr('META-INF/MANIFEST.MF', TEST_VALID_MANIFEST_ONE) testjarfile = SimpleUploadedFile( 'foo.jar', fake_jar_file.getvalue(), content_type='application/java-archive') try: processjar.process_jar(testjarfile, 'expectedname') self.fail('Expected ValueError') except ValueError as ve: self.assertEqual( 'has app name as ' '<tt>CyCommunityDetectionTest</tt> ' 'but must be <tt>expectedname</tt>', str(ve))
def test_process_jar_on_in_memory_file(self): fake_jar_file = io.BytesIO() with zipfile.ZipFile(fake_jar_file, mode='w') as zf: zf.writestr('META-INF/MANIFEST.MF', TEST_VALID_MANIFEST_ONE) testjarfile = SimpleUploadedFile( 'foo.jar', fake_jar_file.getvalue(), content_type='application/java-archive') (a_name, a_ver, a_works, a_dep, has_exp) = processjar.process_jar(testjarfile, 'CyCommunityDetectionTest') self.assertEqual('CyCommunityDetectionTest', a_name) self.assertEqual('1.11.0', a_ver) self.assertEqual('3.7', a_works) self.assertEqual([], a_dep) self.assertEqual(True, has_exp)
def test_process_jar_on_temporary_uploaded_file(self): fake_jar_file = io.BytesIO() with zipfile.ZipFile(fake_jar_file, mode='w') as zf: zf.writestr('META-INF/MANIFEST.MF', TEST_VALID_MANIFEST_ONE) testjarfile = TemporaryUploadedFile('foo.jar', 'application/java-archive', 100, 0) with open(testjarfile.temporary_file_path(), 'wb') as f: f.write(fake_jar_file.getvalue()) (a_name, a_ver, a_works, a_dep, has_exp) = processjar.process_jar(testjarfile, 'CyCommunityDetectionTest') self.assertEqual('CyCommunityDetectionTest', a_name) self.assertEqual('1.11.0', a_ver) self.assertEqual('3.7', a_works) self.assertEqual([], a_dep) self.assertEqual(True, has_exp)