Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 7
0
	def test_should_get_rar_mimetype_for_cbr(self):
		c = Comic('test.cbr')
		self.assertEquals(c.mimetype(), 'application/rar')
Exemplo n.º 8
0
	def test_should_get_zip_mimetype_for_cbz(self):
		c = Comic('test.cbz')
		self.assertEquals(c.mimetype(), 'application/zip')
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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'])
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 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')