示例#1
0
def mock_search_users(self, content_type, accept, body, **kwargs):
    """Mock of jcapiv1.api.search_api.SearchApi.search_systemusers_post()
    """
    limit = body['limit']
    skip = body['skip']
    return Systemuserslist(results=MOCK_USERS_LIST[skip:skip + limit],
                           total_count=len(MOCK_USERS_LIST))
示例#2
0
    def test_search_users_multi_field(self, mock_search_systemusers_post):
        users = [
            Systemuserreturn(username='******',
                             firstname='David',
                             lastname='Smith',
                             email='*****@*****.**'),
        ]
        mock_search_systemusers_post.return_value = Systemuserslist(
            results=users, total_count=len(users))

        api1 = JumpcloudApiV1("fake_key_123")
        user_search = api1.search_users({
            'firstname': 'David',
            'lastname': 'Smith'
        })
        assert (user_search == [user.to_dict() for user in users])

        call_args, call_kwargs = mock_search_systemusers_post.call_args
        assert (call_kwargs['body']['filter'] == {
            'and': [{
                'firstname': 'David'
            }, {
                'lastname': 'Smith'
            }]
        })
示例#3
0
    def test_search_users_no_results(self, mock_search_systemusers_post):
        users = []
        mock_search_systemusers_post.return_value = Systemuserslist(results=users, total_count=len(users))

        api1 = JumpcloudApiV1("fake_key_123")
        user_search = api1.search_users({'firstname': 'David'})
        assert (user_search == [])

        call_args, call_kwargs = mock_search_systemusers_post.call_args
        assert (call_kwargs['body'] == {'filter': {'and': [{'firstname': 'David'}]}})
示例#4
0
 def test_get_user_no_id(self, mock_systemusers_list):
     users = [
         Systemuserreturn(username='******',
                          firstname='David',
                          email='*****@*****.**'),
         Systemuserreturn(username='******',
                          firstname='Zekun',
                          email='*****@*****.**')
     ]
     mock_systemusers_list.return_value = Systemuserslist(
         results=users, total_count=len(users))
     api1 = JumpcloudApiV1("fake_key_123")
     with pytest.raises(SystemUserNotFoundError):
         api1.get_user('angela')
示例#5
0
 def test_get_user(self, mock_systemusers_list):
     users = [
         Systemuserreturn(**{
             'username': '******',
             'id': '1234',
             'firstname': 'Steve'
         }),
         Systemuserreturn(**{
             'username': '******',
             'id': '4321',
             'firstname': 'Angela'
         })
     ]
     response = Systemuserslist(results=users, total_count=len(users))
     mock_systemusers_list.return_value = response
     api1 = JumpcloudApiV1("fake_key")
     firstname = api1.get_user(username='******')['firstname']
     assert (firstname == 'Steve'), "Failed to retrieve correct user object"