예제 #1
0
    def test_always_fails_and_slow(self):
        self.app = helpers.makeTestApp(user = "******")
        from ddbmock import connect_boto_patch, config
        delay = 1
        config.config["always_fail_and_slow"]["DELAY_OPERATIONS"] = delay
        connect_boto_patch()
        expected = {
            u'message': u"The server encountered an internal error trying to fulfill the request",
            u'__type': u'com.amazonaws.dynamodb.v20120810#InternalServerError'
        }
        request = {}

        HEADERS = {
            'x-amz-target': 'dynamodb_20111205.list_tables',
            'content-type': 'application/x-amz-json-1.0',
        }

        start = time()
        res = self.app.post_json('/', request, headers=HEADERS, status=500)
        end = time()
        self.assertEqual(expected, json.loads(res.body))
        self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
                         res.headers['Content-Type'])

        self.assertAlmostEqual(delay, end-start, delta = 0.1)
예제 #2
0
    def test_intermittent_failure(self):
        self.app = helpers.makeTestApp(user = "******")
        from ddbmock import connect_boto_patch, config
        connect_boto_patch()
        request = {}

        HEADERS = {
            'x-amz-target': 'dynamodb_20111205.list_tables',
            'content-type': 'application/x-amz-json-1.0',
        }

        for _ in range(3):
            expected = {
                u'TableNames': []
            }

            res = self.app.post_json('/', request, headers=HEADERS, status=200)
            self.assertEqual(expected, json.loads(res.body))
            self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
                             res.headers['Content-Type'])

            expected = {
                u'message': u"The server encountered an internal error trying to fulfill the request",
                u'__type': u'com.amazonaws.dynamodb.v20120810#InternalServerError'
            }
            res = self.app.post_json('/', request, headers=HEADERS, status=500)
            self.assertEqual(expected, json.loads(res.body))
            self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
                             res.headers['Content-Type'])
예제 #3
0
    def setUp(self):
        from ddbmock.database.db import dynamodb
        from ddbmock.database.table import Table
        from ddbmock.database.key import PrimaryKey

        import helpers
        self.app = helpers.makeTestApp()
        dynamodb.hard_reset()

        hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
        range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
        self.t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key)
        dynamodb.data[TABLE_NAME] = self.t1
예제 #4
0
    def test_invalid_user(self):
        self.app = helpers.makeTestApp(user = "******")
        from ddbmock import connect_boto_patch
        connect_boto_patch()

        expected = {
            u'message': u"Can't find invalid_user in users",
            u'__type': u'com.amazonaws.dynamodb.v20120810#AccessDeniedException'
        }

        res = self.app.post_json('/', {}, headers={}, status=400)
        self.assertEqual(expected, json.loads(res.body))
        self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
                         res.headers['Content-Type'])
예제 #5
0
    def setUp(self, m_time):
        from ddbmock.database.db import dynamodb
        from ddbmock.database.table import Table
        from ddbmock.database.key import PrimaryKey
        import helpers
        self.app = helpers.makeTestApp()

        m_time.time.return_value = NOW

        dynamodb.hard_reset()

        hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
        range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)
        t1 = Table(TABLE_NAME, TABLE_RT, TABLE_WT, hash_key, range_key,
                   status='ACTIVE')
        dynamodb.data[TABLE_NAME] = t1
예제 #6
0
    def setUp(self):
        from ddbmock.database.db import dynamodb
        from ddbmock.database.table import Table
        from ddbmock.database.key import PrimaryKey

        import helpers
        self.app = helpers.makeTestApp()

        dynamodb.hard_reset()

        hash_key = PrimaryKey('hash_key', 'N')
        range_key = PrimaryKey('range_key', 'S')

        t1 = Table(TABLE_NAME1, 10, 10, hash_key, range_key)
        t2 = Table(TABLE_NAME2, 10, 10, hash_key, range_key)

        dynamodb.data[TABLE_NAME1] = t1
        dynamodb.data[TABLE_NAME2] = t2
예제 #7
0
    def test_readonly_user_can(self, name):
        self.app = helpers.makeTestApp(user = "******")
        from ddbmock import connect_boto_patch
        connect_boto_patch()
        HEADERS = {
            'x-amz-target': 'dynamodb_20111205.%s'% name,
            'content-type': 'application/x-amz-json-1.0',
        }

        res = self.app.post_json('/', {}, headers=HEADERS, status=[200,400])
        ret = json.loads(res.body)
        self.assertEqual('application/x-amz-json-1.0; charset=UTF-8', res.headers['Content-Type'])

        # Because no arguments, we either get a 200 for things that require no args, or a 400 for things that need args
        if res.status_code == 200:
            return
        self.assertIn("__type", ret)
        self.assertEqual(u'com.amazonaws.dynamodb.v20120810#ValidationException', ret["__type"])
예제 #8
0
    def test_readonly_user_cant(self, name):
        self.app = helpers.makeTestApp(user = "******")
        from ddbmock import connect_boto_patch
        connect_boto_patch()
        expected = {
            u'message': u"User: read_only is not authorized to perform: dynamodb:%s on resource: *" % name,
            u'__type': u'com.amazonaws.dynamodb.v20120810#AccessDeniedException'
        }
        request = {}

        HEADERS = {
            'x-amz-target': 'dynamodb_20111205.%s' % name,
            'content-type': 'application/x-amz-json-1.0',
        }

        res = self.app.post_json('/', request, headers=HEADERS, status=400)
        self.assertEqual(expected, json.loads(res.body))
        self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
                         res.headers['Content-Type'])
예제 #9
0
    def setUp(self):
        from ddbmock.database.db import dynamodb
        from ddbmock.database.table import Table
        from ddbmock.database.key import PrimaryKey

        import helpers
        self.app = helpers.makeTestApp()

        dynamodb.hard_reset()

        hash_key = PrimaryKey(TABLE_HK_NAME, TABLE_HK_TYPE)
        range_key = PrimaryKey(TABLE_RK_NAME, TABLE_RK_TYPE)

        self.t1 = Table(TABLE_NAME1, TABLE_RT, TABLE_WT, hash_key, range_key)
        self.t2 = Table(TABLE_NAME2, TABLE_RT, TABLE_WT, hash_key, None)

        dynamodb.data[TABLE_NAME1] = self.t1
        dynamodb.data[TABLE_NAME2] = self.t2

        self.t1.put(ITEM1, {})
        self.t1.put(ITEM2, {})
        self.t1.put(ITEM3, {})
        self.t2.put(ITEM4, {})
        self.t2.put(ITEM5, {})
예제 #10
0
    def test_slow_user_is_slow(self):
        self.app = helpers.makeTestApp(user = "******")
        from ddbmock import connect_boto_patch, config
        delay = 1
        config.config["slow_user"]["DELAY_OPERATIONS"] = delay
        connect_boto_patch()
        expected = {
            u'TableNames': []
        }
        request = {}

        HEADERS = {
            'x-amz-target': 'dynamodb_20111205.list_tables',
            'content-type': 'application/x-amz-json-1.0',
        }

        start = time()
        res = self.app.post_json('/', request, headers=HEADERS, status=200)
        end = time()
        self.assertEqual(expected, json.loads(res.body))
        self.assertEqual('application/x-amz-json-1.0; charset=UTF-8',
                         res.headers['Content-Type'])

        self.assertAlmostEqual(delay, end-start, delta = 0.1)
예제 #11
0
 def setUp(self):
     from ddbmock.database.db import dynamodb
     import helpers
     self.app = helpers.makeTestApp()
     dynamodb.hard_reset()