def test_create_ok(self): data = CreateGroupMembership.create("acct:[email protected]", "reference") assert data.raw == { "data": { "relationships": { "group": { "data": { "id": { "$ref": "reference" }, "type": "group" } }, "member": { "data": { "id": "acct:[email protected]", "type": "user" } }, }, "type": "group_membership", } }
def test_accessors(self, create_group_membership_body): body = CreateGroupMembership(create_group_membership_body) assert body.member.id is None assert body.member.ref == "user_ref" assert body.group.id is None assert body.group.ref == "group_ref"
def test_create_ok(self): body = CreateGroupMembership.create("user_ref", "group_ref") assert body.raw == { "data": { "relationships": { "member": { "data": { "id": { "$ref": "user_ref" }, "type": "user" } }, "group": { "data": { "id": { "$ref": "group_ref" }, "type": "group" } }, }, "type": "group_membership", } }
def test_validation_can_fail(self): with pytest.raises(SchemaValidationError): CreateGroupMembership({ "data": { "type": "group_membership", "relationships": { # This isn't good enough, these should have bodies "member": {}, "group": {}, }, } })
def create(cls, user_ref, group_ref): """ Create a group membership create. As the group and user ids are not known at command creation time, a custom reference can be supplied to the group which is then used here to link the two. :param user_ref: Custom reference to the user :param group_ref: Custom reference to the group :rtype: CreateCommand """ return CreateCommand.create( CommandType.CREATE, CreateGroupMembership.create(user_ref, group_ref) )
def test_create_can_fail(self): with pytest.raises(SchemaValidationError): CreateGroupMembership.create("bad", None)
def test_accessors(self, create_group_membership_body): data = CreateGroupMembership(create_group_membership_body) assert data.member_id == "acct:[email protected]" assert data.group_id is None assert data.group_ref == "thing"
def group_membership_body(self): group_membership = CreateGroupMembership.create( "acct:[email protected]", "group_ref" ) return group_membership.raw
def group_membership_body(self): group_membership = CreateGroupMembership.create( "user_ref", "group_ref") return group_membership.raw