def test_update_ssh_public_key(self):
        # Setup Expected Response
        key = 'key106079'
        expiration_time_usec = 2058878882
        fingerprint = 'fingerprint-1375934236'
        expected_response = {
            'key': key,
            'expiration_time_usec': expiration_time_usec,
            'fingerprint': fingerprint
        }
        expected_response = common_pb2.SshPublicKey(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = oslogin_v1.OsLoginServiceClient(channel=channel)

        # Setup Request
        name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
        ssh_public_key = {}

        response = client.update_ssh_public_key(name, ssh_public_key)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = oslogin_pb2.UpdateSshPublicKeyRequest(
            name=name, ssh_public_key=ssh_public_key)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_update_ssh_public_key(self):
        # Setup Expected Response
        key = "key106079"
        expiration_time_usec = 2058878882
        fingerprint = "fingerprint-1375934236"
        expected_response = {
            "key": key,
            "expiration_time_usec": expiration_time_usec,
            "fingerprint": fingerprint,
        }
        expected_response = common_pb2.SshPublicKey(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = oslogin_v1.OsLoginServiceClient()

        # Setup Request
        name = client.fingerprint_path("[USER]", "[FINGERPRINT]")
        ssh_public_key = {}

        response = client.update_ssh_public_key(name, ssh_public_key)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = oslogin_pb2.UpdateSshPublicKeyRequest(
            name=name, ssh_public_key=ssh_public_key)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_ssh_public_key(self):
        # Setup Expected Response
        key = 'key106079'
        expiration_time_usec = 2058878882
        fingerprint = 'fingerprint-1375934236'
        expected_response = {
            'key': key,
            'expiration_time_usec': expiration_time_usec,
            'fingerprint': fingerprint
        }
        expected_response = common_pb2.SshPublicKey(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = oslogin_v1.OsLoginServiceClient()

        # Setup Request
        name = client.fingerprint_path('[USER]', '[FINGERPRINT]')

        response = client.get_ssh_public_key(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = oslogin_pb2.GetSshPublicKeyRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request