示例#1
0
 def test_get_user_by_id_calls_get_with_uri_and_params(
         self, mock_session, successful_response):
     mock_session.get.return_value = successful_response
     client = UserClient(mock_session)
     client.get_by_id("USER_ID")
     uri = "{0}/{1}".format(USER_URI, "USER_ID")
     mock_session.get.assert_called_once_with(uri, params={})
示例#2
0
 def test_get_scim_data_by_uid_calls_get_with_expected_uri_and_params(
         self, mock_session):
     client = UserClient(mock_session)
     client.get_scim_data_by_uid("USER_ID")
     uri = "/api/v7/scim-user-data/collated-view"
     mock_session.get.assert_called_once_with(uri,
                                              params={"userId": "USER_ID"})
示例#3
0
    def test_get_by_username_when_empty_list_returns_raises_user_not_exists(
            self, mock_session, mock_get_users_empty_response):
        mock_session.get.return_value = mock_get_users_empty_response
        client = UserClient(mock_session)
        with pytest.raises(Py42UserDoesNotExistError) as err:
            client.get_by_username("username")

        assert str(err.value) == "User 'username' does not exist."
示例#4
0
 def test_get_all_calls_get_with_uri_and_params(self, mock_session,
                                                mock_get_all_response):
     mock_session.get.side_effect = [mock_get_all_response]
     client = UserClient(mock_session)
     for _ in client.get_all():
         break
     first_call = mock_session.get.call_args_list[0]
     assert first_call[0][0] == USER_URI
     assert first_call[1]["params"] == DEFAULT_GET_ALL_PARAMS
示例#5
0
 def test_add_role_calls_post_with_expected_uri_and_data(
         self, mock_session):
     client = UserClient(mock_session)
     client.add_role(12345, "Test Role Name")
     uri = "/api/UserRole"
     assert mock_session.post.call_args[0][0] == uri
     assert '"roleName": "Test Role Name"' in mock_session.post.call_args[
         1]["data"]
     assert '"userId": 12345' in mock_session.post.call_args[1]["data"]
示例#6
0
 def test_unicode_username_get_user_by_username_calls_get_with_username(
         self, mock_session, successful_response):
     username = u"您已经发现了秘密信息"
     mock_session.get.return_value = successful_response
     client = UserClient(mock_session)
     client.get_by_username(username)
     expected_params = {u"username": username}
     mock_session.get.assert_called_once_with(USER_URI,
                                              params=expected_params)
示例#7
0
 def test_get_all_calls_get_expected_number_of_times(
         self, mock_session, mock_get_all_response,
         mock_get_all_empty_response):
     py42.settings.items_per_page = 1
     client = UserClient(mock_session)
     mock_session.get.side_effect = [
         mock_get_all_response,
         mock_get_all_response,
         mock_get_all_empty_response,
     ]
     for _ in client.get_all():
         pass
     py42.settings.items_per_page = 1000
     assert mock_session.get.call_count == 3
示例#8
0
 def test_get_page_calls_get_with_expected_url_and_params(
         self, mock_session):
     client = UserClient(mock_session)
     client.get_page(10, True, "email", "org", "role", 100, "q")
     mock_session.get.assert_called_once_with(
         "/api/User",
         params={
             "active": True,
             "email": "email",
             "orgUid": "org",
             "roleId": "role",
             "pgNum": 10,
             "pgSize": 100,
             "q": "q",
         },
     )
示例#9
0
    def test_get_departing_employee_client_returns_same_intance_on_multiple_calls(
            self, mock_session, session_factory, user_context):
        factory = MicroserviceClientFactory(TEST_ROOT_URL, mock_session,
                                            session_factory, user_context)
        user_client = UserClient(mock_session)
        client1 = factory.get_departing_employee_client(user_client)
        client2 = factory.get_departing_employee_client(user_client)

        assert client1 is client2
示例#10
0
 def test_get_departing_employee_client(self, mock_session, session_factory,
                                        user_context):
     factory = MicroserviceClientFactory(TEST_ROOT_URL, mock_session,
                                         session_factory, user_context)
     user_client = UserClient(mock_session)
     client = factory.get_departing_employee_client(user_client)
     assert type(
         client
     ) == detectionlists.departing_employee.DepartingEmployeeClient
示例#11
0
 def mock_user_client_raises_exception(self, mocker, mock_session,
                                       user_context, py42_response):
     user_client = UserClient(mock_session)
     response = mocker.MagicMock(spec=Response)
     response.status_code = 400
     exception = mocker.MagicMock(spec=HTTPError)
     exception.response = response
     mock_session.post.side_effect = Py42BadRequestError(exception)
     return user_client
示例#12
0
 def test_get_departing_employee_client_creates_client_with_expected_url(
         self, mock_session, session_factory, user_context,
         key_value_store_client):
     key_value_store_client.get_stored_value.return_value.text = DEPARTING_EMPLOYEE_URL
     factory = MicroserviceClientFactory(TEST_ROOT_URL, mock_session,
                                         session_factory, user_context,
                                         key_value_store_client)
     user_client = UserClient(mock_session)
     factory.get_departing_employee_client(user_client)
     session_factory.create_jwt_session.assert_called_with(
         DEPARTING_EMPLOYEE_URL, mock_session)
     assert session_factory.create_jwt_session.call_count == 1
示例#13
0
    def test_get_departing_employee_client_calls_get_stored_value_with_expected_key(
            self, mock_session, session_factory, user_context,
            key_value_store_client):
        factory = MicroserviceClientFactory(TEST_ROOT_URL, mock_session,
                                            session_factory, user_context,
                                            key_value_store_client)
        user_client = UserClient(mock_session)
        factory.get_departing_employee_client(user_client)

        key_value_store_client.get_stored_value.assert_called_with(
            "employeecasemanagement-API_URL")
        assert key_value_store_client.get_stored_value.call_count == 1
示例#14
0
    def test_post_create_user_is_successful(self, mock_session,
                                            post_api_mock_response):
        user_client = UserClient(mock_session)
        mock_session.post.return_value = post_api_mock_response
        org_uid = "TEST_ORG_ID"
        username = "******"
        password = "******"
        name = "TESTNAME"
        note = "Test Note"
        user_client.create_user(org_uid, username, username, password, name,
                                name, note)
        expected_params = {
            u"orgUid": org_uid,
            u"username": username,
            u"email": username,
            u"password": password,
            u"firstName": name,
            u"lastName": name,
            u"notes": note,
        }

        mock_session.post.assert_called_once_with(
            USER_URI, data=json.dumps(expected_params))
 def mock_user_client(self, mock_session, user_context, py42_response):
     user_client = UserClient(mock_session)
     py42_response.text = '{"username":"******"}'
     mock_session.get.return_value = py42_response
     return user_client
示例#16
0
 def mock_user_client(self, mock_session, user_context, py42_response):
     user_client = UserClient(mock_session)
     mock_session.post.return_value = py42_response
     return user_client
示例#17
0
 def test_get_roles_calls_get_with_expected_uri(self, mock_session):
     client = UserClient(mock_session)
     client.get_roles(12345)
     uri = "/api/UserRole/12345"
     mock_session.get.assert_called_once_with(uri)
示例#18
0
 def test_delete_role_calls_delete_with_expected_uri_and_params(
         self, mock_session):
     client = UserClient(mock_session)
     client.remove_role(12345, "Test Role Name")
     uri = "/api/UserRole?userId=12345&roleName=Test%20Role%20Name"
     mock_session.delete.assert_called_once_with(uri)
示例#19
0
 def test_get_available_roles_calls_get_with_expected_uri(
         self, mock_session):
     client = UserClient(mock_session)
     client.get_available_roles()
     uri = "/api/v4/role/view"
     mock_session.get.assert_called_once_with(uri)