Esempio n. 1
0
    def test_patch_users_username(
        self,
        http_client,
        base_url,
        mongo_principal,
        mongo_role,
        operation,
        value,
        expected_username,
        succeed,
    ):
        mongo_role.save()
        mongo_principal.save()

        body = PatchOperation(operation=operation,
                              path="/username",
                              value=value)

        request = HTTPRequest(
            base_url + "/api/v1/users/" + str(mongo_principal.id),
            method="PATCH",
            headers={"content-type": "application/json"},
            body=SchemaParser.serialize_patch(body),
        )
        response = yield http_client.fetch(request, raise_error=False)

        if succeed:
            assert response.code == 200
            updated = SchemaParser.parse_principal(
                response.body.decode("utf-8"), from_string=True)
            assert updated.username == expected_username

        else:
            assert response.code >= 400
Esempio n. 2
0
    def test_patch_add_role(self, http_client, base_url, mongo_principal,
                            mongo_role):
        mongo_role.save()
        mongo_principal.save()
        new_role = Role(name="new_role",
                        description="Some desc",
                        roles=[],
                        permissions=["bg-all"])
        new_role.save()

        body = PatchOperation(operation="add", path="/roles", value="new_role")

        url = base_url + "/api/v1/users/" + str(mongo_principal.id)
        request = HTTPRequest(
            url,
            method="PATCH",
            headers={"content-type": "application/json"},
            body=SchemaParser.serialize_patch(body),
        )
        response = yield http_client.fetch(request, raise_error=False)

        assert response.code == 200
        updated = SchemaParser.parse_principal(response.body.decode("utf-8"),
                                               from_string=True)
        assert len(updated.roles) == 2
Esempio n. 3
0
    def test_patch_password_update_meta(self, http_client, base_url,
                                        mongo_principal, mongo_role):
        mongo_role.save()
        mongo_principal.metadata = {"auto_change": True, "changed": False}
        mongo_principal.save()
        body = PatchOperation(operation="update",
                              path="/password",
                              value="new_password")

        url = base_url + "/api/v1/users/" + str(mongo_principal.id)
        request = HTTPRequest(
            url,
            method="PATCH",
            headers={"content-type": "application/json"},
            body=SchemaParser.serialize_patch(body),
        )
        response = yield http_client.fetch(request, raise_error=False)

        assert response.code == 200
        updated = SchemaParser.parse_principal(response.body.decode("utf-8"),
                                               from_string=True)
        assert updated.metadata.get("changed") is True