def create_test_admin(slack_id: str) -> User: """ Create a test admin user with slack id, and with all other attributes set. ========== ============================= Property Preset ========== ============================= Slack ID ``slack_id`` Bio I like puppies and kittens! Email [email protected] Name Iemann Atmin Github kibbles Github ID 123453 Image URL https://via.placeholder.com/150 Major Computer Science Permission Admin Position Adrenaline Junkie ========== ============================= :param slack_id: The slack id string :return: a filled-in user model (no empty strings) """ u = User(slack_id) u.biography = 'I like puppies and kittens!' u.email = '*****@*****.**' u.name = 'Iemann Atmin' u.github_username = '******' u.github_id = '123453' u.image_url = 'https:///via.placeholder.com/150' u.major = 'Computer Science' u.permissions_level = Permissions.admin u.position = 'Adrenaline Junkie' u.karma = 1 return u
def test_handle_edit_other_user(self): """Test user command edit parser with all fields.""" user = User("ABCDE89JK") user.name = "rob" user.email = "*****@*****.**" user.position = "dev" user.github_username = "******" user.github_id = "123" user.major = "Computer Science" user.biography = "Im a human" user.permissions_level = Permissions.admin user_attaches = [user.get_attachment()] self.mock_facade.retrieve.return_value = user self.mock_github.org_add_member.return_value = "123" with self.app.app_context(): resp, code = self.testcommand.handle( "user edit --member U0G9QF9C6 " "--name rob " "--email <mailto:[email protected]|[email protected]> --pos dev --github" " [email protected] --major 'Computer Science'" " --bio 'Im a human'", "U0G9QF9C6") expect = {'attachments': user_attaches} self.assertDictEqual(resp, expect) self.assertEqual(code, 200) self.mock_facade.retrieve.assert_any_call(User, "U0G9QF9C6") self.mock_facade.store.assert_called_once_with(user)
def test_edit_user_biography(self) -> None: """Test edit user command API to edit user's biography.""" self.mock_facade.retrieve.return_value = self.test_user self.testapi.user_edit(self.test_user_id, bio="I'm testing") edited_user = User(self.test_user_id) edited_user.biography = "I'm testing" self.mock_facade.store.assert_called_once_with(edited_user)
def test_print(): """Test print user class.""" user = User("U0G9QF9C6") user.biography = "bio test" user.email = "*****@*****.**" user.permissions_level = Permissions.admin assert str(user) == "{'slack_id': 'U0G9QF9C6'," \ " 'name': ''," \ " 'email': '*****@*****.**'," \ " 'github_username': ''," \ " 'github_id': ''," \ " 'major': ''," \ " 'position': ''," \ " 'biography': 'bio test'," \ " 'image_url': ''," \ " 'permissions_level': <Permissions.admin: 3>,"\ " 'karma': 1}"
def test_handle_edit_all_fields(self): user = User(self.u0.slack_id) user.name = 'rob' user.email = '*****@*****.**' user.position = 'dev' user.github_username = '******' user.github_id = '123' user.major = 'Computer Science' user.biography = 'Im a human lol' user.permissions_level = Permissions.member expect = {'attachments': [user.get_attachment()]} self.mock_github.org_add_member.return_value = "123" with self.app.app_context(): resp, code = self.testcommand.handle( "user edit " "--name rob " "--email <mailto:[email protected]|[email protected]> --pos dev --github" " rob --major 'Computer Science'" " --bio 'Im a human lol'", self.u0.slack_id) self.assertDictEqual(resp, expect) self.assertEqual(code, 200)