1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
import unittest
from lp.services.librarian.utils import guess_librarian_encoding
class LibrarianUtils(unittest.TestCase):
"""Librarian utilities functions."""
def test_guess_librarian_encoding(self):
"""Diffs and buillogs are served differently from the other files.
Package Diffs ('.diff.gz') and buildlogs ('.txt.gz') should be
served using mimetype 'text/plain' and encoding 'gzip'.
"""
encoding, mimetype = guess_librarian_encoding(
'foo.html', 'text/html')
self.assertEqual(encoding, None)
self.assertEqual(mimetype, 'text/html')
encoding, mimetype = guess_librarian_encoding(
'foo.dsc', 'application/debian-control')
self.assertEqual(encoding, None)
self.assertEqual(mimetype, 'application/debian-control')
encoding, mimetype = guess_librarian_encoding(
'foo.tar.gz', 'application/octet-stream')
self.assertEqual(encoding, None)
self.assertEqual(mimetype, 'application/octet-stream')
encoding, mimetype = guess_librarian_encoding(
'foo.txt.gz', 'will_be_overridden')
self.assertEqual(encoding, 'gzip')
self.assertEqual(mimetype, 'text/plain')
encoding, mimetype = guess_librarian_encoding(
'foo.diff.gz', 'will_be_overridden')
self.assertEqual(encoding, 'gzip')
self.assertEqual(mimetype, 'text/plain')
|