示例#1
0
	def test_should_mime_type_matches_extension(self, mock_zip):
		mock_zip.namelist.return_value = ['bar.png', 'baz.gif', 'buz.jpeg', 'foo.jpg']
		c = Comic('test.cbz', mock_zip)
		self.assertEquals(c.get_file_mime(0), 'image/png')
		self.assertEquals(c.get_file_mime(1), 'image/gif')
		self.assertEquals(c.get_file_mime(2), 'image/jpeg')
		self.assertEquals(c.get_file_mime(3), 'image/jpeg')
示例#2
0
	def test_should_group_subdir_files_in_dirs(self):
		books = [
			Comic(os.path.join('x', 'buzz', 'bar.cbz')),
			Comic(os.path.join('x', 'baz', 'foo.cbz')),
		]
		
		for item in books:
			item.set_rel_path('x')
		
		ret = self.lister.group_by_path(books)

		self.assertIsInstance(ret, ComicDir)
		self.assertIn(books[0], ret.child('buzz').books)
		self.assertIn(books[1], ret.child('baz').books)
示例#3
0
	def test_should_track_current_file_on_navigate(self):
		c = Comic('test.zip', self.mock_zip)
		
		c.get_file(1)
		self.assertEqual(c.current_file_index, 1)
		
		c.prev_file()
		self.assertEqual(c.current_file_index, 0)
		
		c.next_file()
		self.assertEqual(c.current_file_index, 1)
		
		c.get_file(2)
		self.assertEqual(c.current_file_index, 2)
示例#4
0
	def test_should_raise_on_invalid_page(self):
		c = Comic('test.zip', self.mock_zip)
		
		with self.assertRaises(InvalidPageError):
			c.get_file(5)
		
		with self.assertRaises(InvalidPageError):
			c.prev_file()
		
		with self.assertRaises(InvalidPageError):
			c.get_file(5)
示例#5
0
	def test_should_group_books_by_folder(self):
		
		books = [
			Comic(os.path.join('x', 'bar.cbz')),
			Comic(os.path.join('x', 'foo', 'baz.cbz')),
			Comic(os.path.join('x', 'foo', 'bar', 'bizz.cbz')),
			Comic(os.path.join('x', 'foo.cbz')),
			Comic(os.path.join('x', 'bar', 'buzz.cbz')),
		]
		
		for item in books:
			item.set_rel_path('x')
		
		ret = self.lister.group_by_path(books)
		
		self.assertIsInstance(ret, ComicDir)
		self.assertIn(books[0], ret.books)
		self.assertIn(books[3], ret.books)
		self.assertIn(books[1], ret.child('foo').books)
		self.assertIn(books[4], ret.child('bar').books)
		self.assertIn(books[2], ret.traverse_children(['foo', 'bar']).books)
示例#6
0
	def test_should_create_new_on_metadata_call(self):
		c = Comic('foo/bar.cbz')
		m = c.metadata(1)
		self.assertEquals(m.user_id, 1)
		self.assertEquals(m.book_relpath, 'foo/bar.cbz')
示例#7
0
	def test_should_get_rar_mimetype_for_cbr(self):
		c = Comic('test.cbr')
		self.assertEquals(c.mimetype(), 'application/rar')
示例#8
0
	def test_should_get_zip_mimetype_for_cbz(self):
		c = Comic('test.cbz')
		self.assertEquals(c.mimetype(), 'application/zip')
示例#9
0
	def test_should_set_rel_path_to_full_path_on_invalid_base(self):
		path = os.path.join('foo', 'bar', 'fizz', 'baz.cbz')
		c = Comic(path)
		c.set_rel_path(os.path.join('buzz', 'baz'))
		self.assertEqual(path, c.rel_path)
示例#10
0
	def test_should_set_rel_path_to_path_minus_base(self):
		path = os.path.join('foo', 'bar', 'fizz', 'baz.cbz')
		c = Comic(path)
		c.set_rel_path(os.path.join('foo', 'bar'))
		self.assertEqual(os.path.join('fizz', 'baz.cbz'), c.rel_path)
示例#11
0
	def test_should_sort_returned_files(self):
		c = Comic('test.zip', self.mock_zip)
		files = c.get_file_list()
		self.assertEqual(files, ['bar.jpg', 'foo/baz.JPG', 'zzz.Jpg'])
示例#12
0
	def test_should_list_only_supported_files(self):
		c = Comic('test.zip', self.mock_zip)
		files = c.get_file_list()
		self.assertIn('foo/baz.JPG', files)
		self.assertIn('bar.jpg', files)
		self.assertNotIn('fizz.txt', files)
示例#13
0
	def test_should_convert_multiple_dashes_and_underscores_in_name_to_one_space(self):
		c = Comic('foo/test-bizz--foo__fa_bar.cbz')
		self.assertEquals(c.name, 'test bizz foo fa bar')
示例#14
0
	def test_should_set_name_to_base_path_name(self):
		c = Comic('foo/test.cbz')
		self.assertEquals(c.name, 'test')
		c = Comic('foo.cbz')
		self.assertEquals(c.name, 'foo')