def test_add_users(self, api_mock): api_mock.add_sub_resource.return_value = True team = Team({'Id': 'fgUr1', 'Name': 'Team1'}) user1 = User({'FirstName': 'Paul1', 'LastName': 'Smith1', 'UserName': '******', 'Id': 'wser4351'}) user2 = User({'FirstName': 'Paul', 'LastName': 'Smith', 'UserName': '******', 'Id': 'wser435'}) assert_true(team.add_users([user1, user2])) api_mock.add_sub_resource.assert_called_once_with( 'teams', 'fgUr1', 'users', [ OrderedDict([('Id', 'wser4351'), ('UserName', 'paul.smith1'), ('FirstName', 'Paul1'), ('LastName', 'Smith1')]), OrderedDict([('Id', 'wser435'), ('UserName', 'paul.smith'), ('FirstName', 'Paul'), ('LastName', 'Smith')]) ] )
def test_deactivate(self, api_mock): api_mock.update.return_value = True user = User({'Id': 'wsGth', 'Active': True}) assert_true(user.deactivate()) api_mock.update.assert_called_once_with( 'users', 'wsGth', OrderedDict([('Id', 'wsGth'), ('UserName', ''), ('FirstName', ''), ('LastName', ''), ('FullName', ''), ('Email', ''), ('AccessLevel', 'Learner'), ('DisableMessages', False), ('Active', False), ('Skype', ''), ('PhoneWork', ''), ('PhoneMobile', ''), ('LastLogin', ''), ('LoginKey', ''), ('IsCustomUsername', False), ('Password', ''), ('SkipFirstLogin', True), ('TimeZone', 'UTC'), ('Street1', ''), ('Street2', ''), ('City', ''), ('State', ''), ('PostalCode', ''), ('Country', ''), ('CompanyName', ''), ('JobTitle', ''), ('CustomField1', ''), ('CustomField2', ''), ('CustomField4', ''), ('CustomField5', ''), ('CustomField6', ''), ('CustomField7', ''), ('CustomField8', ''), ('CustomField9', ''), ('CustomField10', ''), ('Culture', '')]))
def test_remove_teams(self, api_mock): api_mock.remove_sub_resource.return_value = True user = User({'Id': 'fgUr2', 'Name': 'User1'}) assert_true(user.remove_teams()) api_mock.remove_sub_resource.assert_called_once_with( 'users', user.Id, 'teams', None)
def test_update_advanced_custom_fields(self, api_mock): api_mock.add_sub_resource.return_value = True user = User({'Id': 'wsGth', 'Active': True}) fields = [{"Test1": "x"}] assert_true(user.update_advanced_custom_fields(fields)) api_mock.add_sub_resource.assert_called_once_with( 'users', user.Id, 'usercustomfields', fields)
def test_all_full_details(self, api_mock): api_mock.all.return_value = [ { "Id": 'ws5tghd', "Name": "Paul" }, { "Id": 'ws5tghe', "Name": "James" }, ] api_mock.find.side_effect = [ { "Id": 'ws5tghd', "Name": "Paul", "CustomField1": "148" }, { "Id": 'ws5tghe', "Name": "James", "CustomField1": "145" }, ] result = User.all(True) eq_(len(result), 2) eq_(result[0].Id, 'ws5tghd') eq_(result[1].Id, 'ws5tghe') eq_(result[0].CustomField1, '148') eq_(result[1].CustomField1, '145') assert_true(api_mock.all.called) eq_(api_mock.find.call_count, 2)
def test_courses(self, api_mock): api_mock.get_sub_resource.return_value = [{ 'Id': 'fgUr3', 'Name': 'Course1' }, { 'Id': 'fgUr2', 'Name': 'Course2' }] user = User({'Id': 'fgUr1', 'Name': 'User1'}) courses = user.courses() eq_(len(courses), 2) eq_('fgUr3', courses[0].Id) api_mock.get_sub_resource.assert_called_once_with( 'users', 'fgUr1', 'courses')
def test_teams(self, api_mock): api_mock.get_sub_resource.return_value = [{ 'Id': 'fgUr3', 'Name': 'SubTeam1' }, { 'Id': 'fgUr2', 'Name': 'SubTeam2' }] user = User({'Id': 'fgUr1', 'Name': 'User1'}) teams = user.teams() eq_(len(teams), 2) eq_('fgUr3', teams[0].Id) api_mock.get_sub_resource.assert_called_once_with( 'users', 'fgUr1', 'teams')
def test_remove_user(self, api_mock): api_mock.remove_sub_resource.return_value = True team = Team({'Id': 'fgUr1', 'Name': 'Team1'}) user = User({'Id': 'fgUr2', 'Name': 'User1'}) assert_true(team.remove_user(user)) api_mock.remove_sub_resource.assert_called_once_with( 'teams', team.Id, 'users', user.Id)
def test_demote_leader(self, api_mock): api_mock.remove_sub_resource.return_value = True team = Team({'Id': 'fgUr1', 'Name': 'Team1'}) user1 = User({'FirstName': 'Paul1', 'LastName': 'Smith1', 'UserName': '******', 'Id': 'wser4351'}) assert_true(team.demote_team_leader(user1)) api_mock.remove_sub_resource.assert_called_once_with( 'teams', team.Id, 'leaders', user1.Id )