Exemplo n.º 1
0
    def test_get_with_unexpected_response(self):
        self.setup_connection(
            MAASFileStorage, FakeFileStorageReturningUnexpectedError)
        storage = MAASFileStorage(CONFIG)
        d = storage.get("foo")

        return self.assertFailure(d, ProviderInteractionError)
Exemplo n.º 2
0
    def test_put_with_error_returned(self):
        self.setup_connection(
            MAASFileStorage, FakeFileStorageWithErrorOnAddingFile)
        storage = MAASFileStorage(CONFIG)
        fileObj = BytesIO("some data")
        d = storage.put("foo", fileObj)

        return self.assertFailure(d, ProviderError)
Exemplo n.º 3
0
 def test_get_url(self):
     # get_url should return the base URL plus the op params for a
     # file name.
     storage = MAASFileStorage(CONFIG)
     url = storage.get_url("foofile")
     urlparts = urlparse(url)
     self.assertEqual("/maas/api/1.0/files/", urlparts.path)
     self.assertEqual("filename=foofile&op=get", urlparts.query)
Exemplo n.º 4
0
    def test_put_succeeds(self):
        self.setup_connection(MAASFileStorage, FakeFileStorage)
        storage = MAASFileStorage(CONFIG)
        fileObj = BytesIO("some data")

        d = storage.put("foo", fileObj)
        d.addCallback(self.assertTrue)
        d.addErrback(self.fail)
        return d
Exemplo n.º 5
0
    def test_get_succeeds(self):
        self.setup_connection(MAASFileStorage, FakeFileStorage)
        storage = MAASFileStorage(CONFIG)
        d = storage.get("foo")

        def check(value):
            # The underlying code returns a StringIO but because
            # implementations of StringIO and cStringIO are completely
            # different the only reasonable thing to do here is to
            # check to see if the returned object has a "read" method.
            attr = getattr(value, "read")
            self.assertIsNot(None, attr)
            self.assertTrue(value.read)

        d.addCallback(check)
        d.addErrback(self.fail)
        return d
Exemplo n.º 6
0
    def test_get_with_bad_filename(self):
        self.setup_connection(MAASFileStorage, FakeFileStorageReturning404)
        storage = MAASFileStorage(CONFIG)
        d = storage.get("foo")

        return self.assertFailure(d, FileNotFound)