def test_create_user_group_ok(self): ug_json = { "name": "test ug", "short_name": "test ug short", } ug = UserGroup.from_json(copy.copy(ug_json), None) self.assertEqual(1, ug.create()) # now check that we can add another ug with an empty url_code ug2 = UserGroup.from_json(ug_json, None) self.assertEqual(1, ug2.create())
def set_or_create_user_group(self, ug_id=None, ug_json=None, interactive_mode=True): """ Args: ug_id: ug_json (dict): must be provided if interactive_mode is False; overwritten if interactive_mode is True interactive_mode: Returns: """ print( f"Found {len(self.user_ids)} users in input. User ids are: {self.user_ids}" ) if ug_id is not None: self.user_group_id = ug_id return self.user_group_id else: if interactive_mode: ug_id = input( "Please enter the id of the user group you would like to populate (or leave blank to create a new group):" ) if ug_id: self.user_group_id = ug_id return self.user_group_id else: group_name = input("Please enter the new user group name:") group_short_name = input( "Please enter the new user group short name:" ) group_code = input("Please enter the new user group url code:") ug_json = { "name": group_name, "short_name": group_short_name, "url_code": group_code, } ug = UserGroup.from_json(ug_json, None) self.user_group_id = ug.to_dict()["id"] ug.create() print(f"Created new user group with id {self.user_group_id}") return self.user_group_id
def test_07_user_group_create_from_json_full(self): from api.endpoints.user_group import UserGroup ug_json = { "id": "b20fcb9c-42c6-4fa6-bf1b-8d7add4d4777", "created": "2018-08-21 11:16:56+01:00", "modified": "2019-05-21 11:10:34+01:00", "name": "test05 ug", "short_name": "ug5", "sister_testing_group_id": None, "tasks": None, "testing": True, "url_code": "ug5_code", "demo": True, } ug = UserGroup.from_json(copy.copy(ug_json), None) ug_dict = ug.to_dict() self.assertDictEqual(ug_json, ug_dict)
def test_06_user_group_create_from_json_more(self): from api.endpoints.user_group import UserGroup ug_json = { "name": "test05 ug", "short_name": "ug5", "sister_testing_group_id": None, "tasks": None, "testing": None, "url_code": "ug5_code", "demo": False, } ug = UserGroup.from_json(copy.copy(ug_json), None) ug_dict = ug.to_dict() self.new_uuid_test_and_remove(ug_dict) self.now_datetime_test_and_remove(ug_dict, "created") self.now_datetime_test_and_remove(ug_dict, "modified") self.assertDictEqual(ug_json, ug_dict)
def test_05_user_group_create_from_json_basic(self): from api.endpoints.user_group import UserGroup ug_json = {"name": "test05 ug", "short_name": "test05"} ug = UserGroup.from_json(ug_json, None) ug_dict = ug.to_dict() self.new_uuid_test_and_remove(ug_dict) self.now_datetime_test_and_remove(ug_dict, "created") self.now_datetime_test_and_remove(ug_dict, "modified") expected_body = { "name": "test05 ug", "short_name": "test05", "sister_testing_group_id": None, "tasks": None, "testing": False, "url_code": "", "demo": False, } self.assertDictEqual(expected_body, ug_dict)