Exemplo n.º 1
0
    def test_bad_request(self, mocked_logger):
        """ Default HTTP 400 with errors
        """
        base = BaseController()
        errors = {'error': 'general error'}

        with pytest.raises(web.HTTPBadRequest) as expected:
            base.bad_request(errors)
        mocked_logger.assert_called_once()
        resp = json.loads(expected.value.text)
        assert resp['reason'] == errors
Exemplo n.º 2
0
    def test_invalid_data(self):
        base = BaseController()
        base.bad_request = MagicMock('aaa')
        error = {'field': 'invalid'}

        base.handle_business_errors(ValidationError(error))

        base.bad_request.assert_called_with({'field': 'invalid'})
Exemplo n.º 3
0
    async def test_invalid_data(self):
        base = BaseController()
        base.bad_request = MagicMock('aaa')
        error = {'code': 'some_code', 'reason': {'error': 'something'}}

        base.handle_service_errors(InvalidDataError(400, json.dumps(error)))

        base.bad_request.assert_called_with({'error': 'something'})
Exemplo n.º 4
0
    def test_invalid_jwt(self):
        request = Mock()
        request.headers.get.return_value = 'Bearer aa.aa.aa'
        contr = BaseController()
        contr.bad_request = MagicMock()

        _ = contr.get_identity(request)

        contr.bad_request.assert_called_once()