Exemplo n.º 1
0
    def test_login_raises_ValidationFailure_on_ValidationFailure(self):
        controller = views.AjaxAuthController(DummyRequest(json_body={}))
        controller.form = invalid_form({'password': '******'})

        with pytest.raises(deform.ValidationFailure) as exc_info:
            controller.login()

        assert exc_info.value.error.asdict() == {'password': '******'}
Exemplo n.º 2
0
    def test_login_returns_status_okay_when_validation_succeeds(self):
        request = DummyRequest(json_body={}, auth_domain='hypothes.is')
        controller = views.AjaxAuthController(request)
        controller.form = form_validating_to(
            {'user': FakeUser(username='******')})

        result = controller.login()

        assert result['status'] == 'okay'
Exemplo n.º 3
0
    def test_login_raises_JSONError_on_non_json_body(self):
        request = mock.Mock(authenticated_user=mock.Mock(groups=[]))
        type(request).json_body = mock.PropertyMock(side_effect=ValueError)

        controller = views.AjaxAuthController(request)

        with pytest.raises(accounts.JSONError) as exc_info:
            controller.login()
            assert exc_info.value.message.startswith(
                'Could not parse request body as JSON: ')
Exemplo n.º 4
0
    def test_login_raises_JSONError_on_non_object_json(self):
        request = mock.Mock(
            authenticated_user=mock.Mock(groups=[]), json_body='foo')

        controller = views.AjaxAuthController(request)

        with pytest.raises(accounts.JSONError) as exc_info:
            controller.login()
            assert (
                exc_info.value.message == 'Request JSON body must have a ' +
                                        'top-level object')
Exemplo n.º 5
0
    def test_login_converts_non_string_passwords_to_strings(self, _):
        for input_, expected_output in ((None, ''),
                                        (23, '23'),
                                        (True, 'True')):
            request = DummyRequest(
                json_body={'username': '******', 'password': input_},
                auth_domain='hypothes.is')
            controller = views.AjaxAuthController(request)
            controller.form.validate = mock.Mock(
                return_value={'user': mock.Mock()})

            controller.login()

            assert controller.form.validate.called
            pstruct = controller.form.validate.call_args[0][0]
            assert sorted(pstruct) == sorted([('username', 'user'),
                                              ('password', expected_output)])