Ejemplo n.º 1
0
    def test_delete_role(self, db_request):
        project = ProjectFactory.create(name="foo")
        user = UserFactory.create(username="******")
        role = RoleFactory.create(project=project, user=user)

        db_request.route_path = pretend.call_recorder(
            lambda *a, **kw: "/the-redirect/")
        db_request.session = pretend.stub(
            flash=pretend.call_recorder(lambda *a, **kw: None))
        db_request.POST["username"] = user.username
        db_request.matchdict["role_id"] = role.id
        db_request.user = UserFactory.create()
        db_request.remote_addr = "192.168.1.1"

        views.delete_role(project, db_request)

        assert db_request.session.flash.calls == [
            pretend.call(
                f"Removed '{role.user.username}' as '{role.role_name}' "
                f"on '{project.name}'",
                queue="success",
            )
        ]

        assert db_request.db.query(Role).all() == []
Ejemplo n.º 2
0
    def test_delete_role(self, db_request):
        project = ProjectFactory.create(name="foo")
        user = UserFactory.create(username="******")
        role = RoleFactory.create(project=project, user=user)

        db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect/")
        db_request.session = pretend.stub(
            flash=pretend.call_recorder(lambda *a, **kw: None)
        )
        db_request.POST["username"] = user.username
        db_request.matchdict["role_id"] = role.id
        db_request.user = UserFactory.create()
        db_request.remote_addr = "192.168.1.1"

        views.delete_role(project, db_request)

        assert db_request.session.flash.calls == [
            pretend.call(
                f"Removed '{role.user.username}' as '{role.role_name}' "
                f"on '{project.name}'",
                queue="success",
            )
        ]

        assert db_request.db.query(Role).all() == []
Ejemplo n.º 3
0
    def test_delete_role_not_found(self, db_request):
        project = ProjectFactory.create(name="foo")

        db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect/")
        db_request.session = pretend.stub(
            flash=pretend.call_recorder(lambda *a, **kw: None)
        )
        db_request.matchdict["role_id"] = uuid.uuid4()
        db_request.user = UserFactory.create()

        with pytest.raises(HTTPSeeOther):
            views.delete_role(project, db_request)

        assert db_request.session.flash.calls == [
            pretend.call("This role no longer exists", queue="error")
        ]
Ejemplo n.º 4
0
    def test_delete_role_not_found(self, db_request):
        project = ProjectFactory.create(name="foo")

        db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect/")
        db_request.session = pretend.stub(
            flash=pretend.call_recorder(lambda *a, **kw: None)
        )
        db_request.matchdict["role_id"] = uuid.uuid4()
        db_request.user = UserFactory.create()
        db_request.remote_addr = "192.168.1.1"

        with pytest.raises(HTTPSeeOther):
            views.delete_role(project, db_request)

        assert db_request.session.flash.calls == [
            pretend.call("This role no longer exists", queue="error")
        ]
Ejemplo n.º 5
0
    def test_delete_role_no_confirm(self, db_request):
        project = ProjectFactory.create(name="foo")
        user = UserFactory.create(username="******")
        role = RoleFactory.create(project=project, user=user)

        db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect/")
        db_request.session = pretend.stub(
            flash=pretend.call_recorder(lambda *a, **kw: None)
        )
        db_request.matchdict["role_id"] = role.id
        db_request.user = UserFactory.create()

        with pytest.raises(HTTPSeeOther):
            views.delete_role(project, db_request)

        assert db_request.session.flash.calls == [
            pretend.call("Confirm the request", queue="error")
        ]
Ejemplo n.º 6
0
    def test_delete_role_no_confirm(self, db_request):
        project = ProjectFactory.create(name="foo")
        user = UserFactory.create(username="******")
        role = RoleFactory.create(project=project, user=user)

        db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect/")
        db_request.session = pretend.stub(
            flash=pretend.call_recorder(lambda *a, **kw: None)
        )
        db_request.matchdict["role_id"] = role.id
        db_request.user = UserFactory.create()
        db_request.remote_addr = "192.168.1.1"

        with pytest.raises(HTTPSeeOther):
            views.delete_role(project, db_request)

        assert db_request.session.flash.calls == [
            pretend.call("Confirm the request", queue="error")
        ]