~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_filestorage.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-03-04 11:49:44 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20130304114944-azcvu9anlf8mizpa
Tags: upstream-1.3+bzr1452+dfsg
ImportĀ upstreamĀ versionĀ 1.3+bzr1452+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
__metaclass__ = type
13
13
__all__ = []
14
14
 
15
 
import codecs
16
15
from io import BytesIO
17
16
 
18
17
from maasserver.models import FileStorage
19
18
from maasserver.testing.factory import factory
20
19
from maasserver.testing.testcase import TestCase
 
20
from maastesting.utils import sample_binary_data
21
21
 
22
22
 
23
23
class FileStorageTest(TestCase):
57
57
            (storage.filename, storage.content))
58
58
 
59
59
    def test_stores_binary_data(self):
60
 
        # This horrible binary data could never, ever, under any
61
 
        # encoding known to man be interpreted as text(1).  Switch the
62
 
        # bytes of the byte-order mark around and by design you get an
63
 
        # invalid codepoint; put a byte with the high bit set between bytes
64
 
        # that have it cleared, and you have a guaranteed non-UTF-8
65
 
        # sequence.
66
 
        #
67
 
        # (1) Provided, of course, that man know only about ASCII and
68
 
        # UTF.
69
 
        binary_data = codecs.BOM64_LE + codecs.BOM64_BE + b'\x00\xff\x00'
70
 
 
71
 
        # And yet, because FileStorage supports binary data, it comes
72
 
        # out intact.
73
 
        storage = factory.make_file_storage(filename="x", content=binary_data)
74
 
        self.assertEqual(binary_data, storage.content)
 
60
        storage = factory.make_file_storage(content=sample_binary_data)
 
61
        self.assertEqual(sample_binary_data, storage.content)
75
62
 
76
63
    def test_overwrites_file(self):
77
64
        # If a file of the same name has already been stored, the