def test_to_json(self): """Tests converting to JSON""" auag = UsersAndGroups() auag.add_group(Group("group1")) auag.add_group(Group("group2", group_names=["group1"])) auag.add_user(User("user1", group_names=["group1"])) auag.add_user(User("user2", group_names=["group1", "group2"])) json_str = auag.to_json() self.assertTrue(json_str.startswith("[{ ")) self.assertTrue(json_str.endswith("}]")) self.assertTrue('"name":"user1"' in json_str) self.assertTrue('"name":"user2"' in json_str) self.assertTrue('"name":"group1"' in json_str) self.assertTrue('"name":"group2"' in json_str)
def get_test_json(): """Creates some JSON for testing.""" uags = UsersAndGroups() uags.add_group( Group( name="Group 1", display_name="This is Group 1", description="A group for testing.", group_names=[], )) uags.add_group( Group( name="Group 2", display_name="This is Group 2", description="Another group for testing.", group_names=["Group 1"], visibility=Visibility.NON_SHAREABLE, )) uags.add_user( User( name="User1", password="******", display_name="User 1", mail="*****@*****.**", group_names=["Group 1"], )) uags.add_user( User( name="User2", password="******", display_name="User 2", mail="*****@*****.**", group_names=["Group 1", "Group 2"], visibility=Visibility.NON_SHAREABLE, )) return uags.to_json()