def test_ratelimit_no_session(self):
        def dummy():
            return ('', 204)

        with self.real_app.test_request_context():
            with self.assertRaises(MWSServerError) as cm:
                ratelimit(dummy)()

            self.assertEqual(cm.exception.error, 401)
    def test_ratelimit_no_session(self):
        def dummy():
            return ('', 204)

        with self.real_app.test_request_context():
            with self.assertRaises(MWSServerError) as cm:
                ratelimit(dummy)()

            self.assertEqual(cm.exception.error, 401)
    def test_ratelimit(self):
        rv = self.app.post('/mws/')
        self.res_id = loads(rv.data)['res_id']

        limit = self.real_app.config['RATELIMIT_QUOTA'] = 3

        def dummy():
            return ('', 204)

        with self.app.session_transaction() as client_sess:
            session_id = client_sess['session_id']

        with self.real_app.test_request_context():
            session['session_id'] = session_id
            for i in range(limit):
                self.assertEqual(ratelimit(dummy)(), ('', 204))

            with self.assertRaises(MWSServerError) as cm:
                ratelimit(dummy)()

            self.assertEqual(cm.exception.error, 429)
    def test_ratelimit(self):
        rv = self.app.post('/mws/')
        self.res_id = loads(rv.data)['res_id']

        limit = self.real_app.config['RATELIMIT_QUOTA'] = 3

        def dummy():
            return ('', 204)

        with self.app.session_transaction() as client_sess:
            session_id = client_sess['session_id']

        with self.real_app.test_request_context():
            session['session_id'] = session_id
            for i in range(limit):
                self.assertEqual(ratelimit(dummy)(), ('', 204))

            with self.assertRaises(MWSServerError) as cm:
                ratelimit(dummy)()

            self.assertEqual(cm.exception.error, 429)