Exemplo n.º 1
0
    def test_should_add_and_commit_new_administrator(
            self, db_mock: MagicMock, administrator_mock: MagicMock):
        administrator_mock.side_effect = lambda **_: AN_ADMINISTRATOR

        register_administrator()

        db_mock.session.add.assert_called_with(AN_ADMINISTRATOR)
        db_mock.session.commit.assert_called_once()
Exemplo n.º 2
0
    def test_given_admin_with_email_already_existing_should_raise_unprocessable_entity(
            self, user_mock: MagicMock):
        a_user_mock = MagicMock()
        a_user_mock.get_administrator.return_value = AN_ADMINISTRATOR
        user_mock.query.filter_by.return_value.first.return_value = a_user_mock

        with raises(errors.UnprocessableEntity):
            register_administrator()
Exemplo n.º 3
0
    def test_should_set_user_password(self, user_mock: MagicMock,
                                      _flask_rebar_mock: MagicMock):
        A_PASSWORD = "******"
        _flask_rebar_mock.get_validated_body.return_value[
            "password"] = A_PASSWORD
        a_user_mock = MagicMock()
        user_mock.side_effect = lambda **_: a_user_mock

        register_administrator()

        a_user_mock.set_password.assert_called_with(A_PASSWORD)
Exemplo n.º 4
0
    def test_given_admin_with_username_already_existing_should_raise_unprocessable_entity(
            self, user_mock: MagicMock):
        def side_effect(**kwargs):
            mock = MagicMock()
            if "email" in kwargs:
                mock.first.return_value = None
            elif "username" in kwargs:
                a_user_mock = MagicMock()
                a_user_mock.get_administrator.return_value = AN_ADMINISTRATOR
                mock.first.return_value = a_user_mock

            return mock

        user_mock.query.filter_by.side_effect = side_effect

        with raises(errors.UnprocessableEntity):
            register_administrator()
Exemplo n.º 5
0
 def test_should_return_new_administrator_with_code_201(
         self, administrator_mock: MagicMock):
     administrator_mock.side_effect = lambda **_: AN_ADMINISTRATOR
     assert register_administrator() == (AN_ADMINISTRATOR, 201)