Ejemplo n.º 1
0
    def test_begin_transaction_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = datastore_v1.DatastoreClient(channel=channel)

        # Setup request
        project_id = 'projectId-1969970175'

        with pytest.raises(CustomException):
            client.begin_transaction(project_id)
Ejemplo n.º 2
0
    def test_lookup_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = datastore_v1.DatastoreClient(channel=channel)

        # Setup request
        project_id = 'projectId-1969970175'
        keys = []

        with pytest.raises(CustomException):
            client.lookup(project_id, keys)
Ejemplo n.º 3
0
    def test_run_query_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = datastore_v1.DatastoreClient(channel=channel)

        # Setup request
        project_id = 'projectId-1969970175'
        partition_id = {}

        with pytest.raises(CustomException):
            client.run_query(project_id, partition_id)
    def test_rollback_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = datastore_v1.DatastoreClient(channel=channel)

        # Setup request
        project_id = "projectId-1969970175"
        transaction = b"-34"

        with pytest.raises(CustomException):
            client.rollback(project_id, transaction)
Ejemplo n.º 5
0
    def test_commit_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = datastore_v1.DatastoreClient(channel=channel)

        # Setup request
        project_id = 'projectId-1969970175'
        mode = enums.CommitRequest.Mode.MODE_UNSPECIFIED
        mutations = []

        with pytest.raises(CustomException):
            client.commit(project_id, mode, mutations)
Ejemplo n.º 6
0
    def test_run_query(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = datastore_pb2.RunQueryResponse(**expected_response)

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

        # Setup Request
        project_id = 'projectId-1969970175'
        partition_id = {}

        response = client.run_query(project_id, partition_id)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datastore_pb2.RunQueryRequest(
            project_id=project_id, partition_id=partition_id)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 7
0
    def test_lookup(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = datastore_pb2.LookupResponse(**expected_response)

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

        # Setup Request
        project_id = 'projectId-1969970175'
        keys = []

        response = client.lookup(project_id, keys)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datastore_pb2.LookupRequest(project_id=project_id,
                                                       keys=keys)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 8
0
    def test_rollback(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = datastore_pb2.RollbackResponse(**expected_response)

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

        # Setup Request
        project_id = 'projectId-1969970175'
        transaction = b'-34'

        response = client.rollback(project_id, transaction)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datastore_pb2.RollbackRequest(
            project_id=project_id, transaction=transaction)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 9
0
    def test_begin_transaction(self):
        # Setup Expected Response
        transaction = b'-34'
        expected_response = {'transaction': transaction}
        expected_response = datastore_pb2.BeginTransactionResponse(
            **expected_response)

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

        # Setup Request
        project_id = 'projectId-1969970175'

        response = client.begin_transaction(project_id)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datastore_pb2.BeginTransactionRequest(
            project_id=project_id)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 10
0
    def test_commit(self):
        # Setup Expected Response
        index_updates = 1425228195
        expected_response = {'index_updates': index_updates}
        expected_response = datastore_pb2.CommitResponse(**expected_response)

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

        # Setup Request
        project_id = 'projectId-1969970175'
        mode = enums.CommitRequest.Mode.MODE_UNSPECIFIED
        mutations = []

        response = client.commit(project_id, mode, mutations)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datastore_pb2.CommitRequest(project_id=project_id,
                                                       mode=mode,
                                                       mutations=mutations)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request