Esempio n. 1
0
 def test_one_container(self):
     """
     tests to ensure behavior is normal with one container
     """
     # setup expectation
     swift_stub = SwiftClientStub()
     swift_stub.with_account('123223')
     cont_name = 'a-container-name'
     swift_stub.with_container(cont_name)
     # interact
     conn = swiftclient.client.Connection()
     conn.get_auth()
     conn.put_container(cont_name)
     # get headers plus container metadata
     self.assertThat(len(conn.get_account()), matchers.Is(2))
     # verify container details
     account_containers = conn.get_account()[1]
     self.assertThat(len(account_containers), matchers.Is(1))
     self.assertThat(account_containers[0],
                     matchers.KeysEqual('count', 'bytes', 'name'))
     self.assertThat(account_containers[0]['name'], matchers.Is(cont_name))
     # get container details
     cont_info = conn.get_container(cont_name)
     self.assertIsNotNone(cont_info)
     self.assertThat(cont_info[0], matchers.KeysEqual('content-length',
                     'x-container-object-count', 'accept-ranges',
                     'x-container-bytes-used', 'x-timestamp',
                     'x-trans-id', 'date', 'content-type'))
     self.assertThat(len(cont_info[1]), matchers.Equals(0))
     # remove container
     swift_stub.without_container(cont_name)
     with testtools.ExpectedException(swiftclient.ClientException):
         conn.get_container(cont_name)
         # ensure there are no more containers in account
     self.assertThat(len(conn.get_account()[1]), matchers.Is(0))
Esempio n. 2
0
 def test_one_container(self):
     """
     tests to ensure behavior is normal with one container
     """
     # setup expectation
     swift_stub = SwiftClientStub()
     swift_stub.with_account('123223')
     cont_name = 'a-container-name'
     swift_stub.with_container(cont_name)
     # interact
     conn = swiftclient.client.Connection()
     conn.get_auth()
     conn.put_container(cont_name)
     # get headers plus container metadata
     self.assertThat(len(conn.get_account()), matchers.Is(2))
     # verify container details
     account_containers = conn.get_account()[1]
     self.assertThat(len(account_containers), matchers.Is(1))
     self.assertThat(account_containers[0],
                     matchers.KeysEqual('count', 'bytes', 'name'))
     self.assertThat(account_containers[0]['name'], matchers.Is(cont_name))
     # get container details
     cont_info = conn.get_container(cont_name)
     self.assertIsNotNone(cont_info)
     self.assertThat(cont_info[0], matchers.KeysEqual('content-length',
                     'x-container-object-count', 'accept-ranges',
                     'x-container-bytes-used', 'x-timestamp',
                     'x-trans-id', 'date', 'content-type'))
     self.assertThat(len(cont_info[1]), matchers.Equals(0))
     # remove container
     swift_stub.without_container(cont_name)
     with testtools.ExpectedException(swiftclient.ClientException):
         conn.get_container(cont_name)
         # ensure there are no more containers in account
     self.assertThat(len(conn.get_account()[1]), matchers.Is(0))
Esempio n. 3
0
    def test_two_objects(self):
        swift_stub = SwiftClientStub()
        swift_stub.with_account("123223")
        swift_stub.with_container("bob")
        swift_stub.with_container("bob2")
        swift_stub.with_object("bob", "test", "test_contents")
        swift_stub.with_object("bob", "test2", "test_contents2")

        conn = swiftclient.client.Connection()

        self.assertIs(len(conn.get_account()), 2)
        cont_info = conn.get_container("bob")
        self.assertIsNotNone(cont_info)
        self.assertThat(
            cont_info[0],
            KeysEqual(
                "content-length",
                "x-container-object-count",
                "accept-ranges",
                "x-container-bytes-used",
                "x-timestamp",
                "x-trans-id",
                "date",
                "content-type",
            ),
        )
        self.assertThat(len(cont_info[1]), Equals(2))
        self.assertThat(
            cont_info[1][0],
            Equals(
                {
                    "bytes": 13,
                    "last_modified": "2013-03-15T22:10:49.361950",
                    "hash": "ccc55aefbf92aa66f42b638802c5e7f6",
                    "name": "test",
                    "content_type": "application/octet-stream",
                }
            ),
        )
        self.assertThat(conn.get_object("bob", "test")[1], Is("test_contents"))
        self.assertThat(conn.get_object("bob", "test2")[1], Is("test_contents2"))

        swift_stub.without_object("bob", "test")
        conn.delete_object("bob", "test")
        with testtools.ExpectedException(swiftclient.ClientException):
            conn.delete_object("bob", "test")
        self.assertThat(len(conn.get_container("bob")[1]), Is(1))

        swift_stub.without_container("bob")
        with testtools.ExpectedException(swiftclient.ClientException):
            conn.get_container("bob")

        self.assertThat(len(conn.get_account()), Is(2))
Esempio n. 4
0
    def test_two_objects(self):
        swift_stub = SwiftClientStub()
        swift_stub.with_account('123223')
        swift_stub.with_container('bob')
        swift_stub.with_container('bob2')
        swift_stub.with_object('bob', 'test', 'test_contents')
        swift_stub.with_object('bob', 'test2', 'test_contents2')

        conn = swiftclient.client.Connection()

        self.assertIs(len(conn.get_account()), 2)
        cont_info = conn.get_container('bob')
        self.assertIsNotNone(cont_info)
        self.assertThat(
            cont_info[0],
            matchers.KeysEqual('content-length', 'x-container-object-count',
                               'accept-ranges', 'x-container-bytes-used',
                               'x-timestamp', 'x-trans-id', 'date',
                               'content-type'))
        self.assertThat(len(cont_info[1]), matchers.Equals(2))
        self.assertThat(
            cont_info[1][0],
            matchers.Equals({
                'bytes': 13,
                'last_modified': '2013-03-15T22:10:49.361950',
                'hash': 'ccc55aefbf92aa66f42b638802c5e7f6',
                'name': 'test',
                'content_type': 'application/octet-stream',
                'contents': 'test_contents'
            }))
        self.assertThat(
            conn.get_object('bob', 'test')[1], matchers.Is('test_contents'))
        self.assertThat(
            conn.get_object('bob', 'test2')[1], matchers.Is('test_contents2'))

        swift_stub.without_object('bob', 'test')
        with testtools.ExpectedException(swiftclient.ClientException):
            conn.delete_object('bob', 'test')
        self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1))

        swift_stub.without_container('bob')
        with testtools.ExpectedException(swiftclient.ClientException):
            conn.get_container('bob')

        self.assertThat(len(conn.get_account()), matchers.Is(2))
Esempio n. 5
0
 def test_one_container(self):
     """
     tests to ensure behavior is normal with one container
     """
     # setup expectation
     swift_stub = SwiftClientStub()
     swift_stub.with_account("123223")
     cont_name = "a-container-name"
     swift_stub.with_container(cont_name)
     # interact
     conn = swiftclient.client.Connection()
     conn.get_auth()
     conn.put_container(cont_name)
     # get headers plus container metadata
     self.assertThat(len(conn.get_account()), Is(2))
     # verify container details
     account_containers = conn.get_account()[1]
     self.assertThat(len(account_containers), Is(1))
     self.assertThat(account_containers[0], KeysEqual("count", "bytes", "name"))
     self.assertThat(account_containers[0]["name"], Is(cont_name))
     # get container details
     cont_info = conn.get_container(cont_name)
     self.assertIsNotNone(cont_info)
     self.assertThat(
         cont_info[0],
         KeysEqual(
             "content-length",
             "x-container-object-count",
             "accept-ranges",
             "x-container-bytes-used",
             "x-timestamp",
             "x-trans-id",
             "date",
             "content-type",
         ),
     )
     self.assertThat(len(cont_info[1]), Equals(0))
     # remove container
     swift_stub.without_container(cont_name)
     with testtools.ExpectedException(swiftclient.ClientException):
         conn.get_container(cont_name)
         # ensure there are no more containers in account
     self.assertThat(len(conn.get_account()[1]), Is(0))
Esempio n. 6
0
    def test_two_objects(self):
        swift_stub = SwiftClientStub()
        swift_stub.with_account('123223')
        swift_stub.with_container('bob')
        swift_stub.with_container('bob2')
        swift_stub.with_object('bob', 'test', 'test_contents')
        swift_stub.with_object('bob', 'test2', 'test_contents2')

        conn = swiftclient.client.Connection()

        self.assertIs(len(conn.get_account()), 2)
        cont_info = conn.get_container('bob')
        self.assertIsNotNone(cont_info)
        self.assertThat(cont_info[0],
                        matchers.KeysEqual('content-length',
                                           'x-container-object-count',
                                           'accept-ranges',
                                           'x-container-bytes-used',
                                           'x-timestamp', 'x-trans-id', 'date',
                                           'content-type'))
        self.assertThat(len(cont_info[1]), matchers.Equals(2))
        self.assertThat(cont_info[1][0], matchers.Equals(
            {'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
             'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
             'content_type': 'application/octet-stream',
             'contents': 'test_contents'}))
        self.assertThat(conn.get_object('bob', 'test')[1],
                        matchers.Is('test_contents'))
        self.assertThat(conn.get_object('bob', 'test2')[1],
                        matchers.Is('test_contents2'))

        swift_stub.without_object('bob', 'test')
        with testtools.ExpectedException(swiftclient.ClientException):
            conn.delete_object('bob', 'test')
        self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1))

        swift_stub.without_container('bob')
        with testtools.ExpectedException(swiftclient.ClientException):
            conn.get_container('bob')

        self.assertThat(len(conn.get_account()), matchers.Is(2))