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 test_03_user_group_get_by_url_code_exist(self): from api.endpoints.user_group import UserGroup url_code = "g2_code" expected_body = { "id": "03719e6a-f85d-492b-be0f-03ab1927014d", "created": "2018-11-01T21:36:47.417859+00:00", "modified": "2018-11-01T21:36:47.417882+00:00", "name": "G2", "short_name": "G2", "sister_testing_group_id": None, "tasks": [ {"short_name": "PSFU-04-A task short name", "status": "testing"}, {"short_name": "PSFU-05-C task short name", "status": "active"}, {"short_name": "PSFU-06-B task short name", "status": "active"}, {"short_name": "PSFU-08-A task short name", "status": "complete"}, ], "testing": False, "url_code": url_code, "demo": False, } ug = UserGroup.get_by_url_code(url_code, None) ug_dict = ug.to_dict() self.assertDictEqual(expected_body, ug_dict)
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_01_user_group_get_by_id_exist(self): from api.endpoints.user_group import UserGroup id = "9cabcdea-8169-4101-87bd-24fd92c9a6da" expected_body = { "id": id, "created": "2018-10-25T11:27:27.545703+00:00", "modified": "2018-10-25T11:27:27.545726+00:00", "name": "Testers", "short_name": "testers", "sister_testing_group_id": None, "tasks": None, "testing": False, "url_code": "test_code", "demo": False, } ug = UserGroup.get_by_id(id, None) ug_dict = ug.to_dict() self.assertDictEqual(expected_body, 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)
def test_04_user_group_get_by_id_not_exists(self): from api.endpoints.user_group import UserGroup url_code = "NOT_g2_code" ug = UserGroup.get_by_url_code(url_code, None) self.assertIsNone(ug)
def test_02_user_group_get_by_id_not_exists(self): from api.endpoints.user_group import UserGroup id = "9cabcdea-8169-4101-87bd-24fd92c9a6db" ug = UserGroup.get_by_id(id, None) self.assertIsNone(ug)