Esempio n. 1
0
def test_get_entity(_1, _2, make_datastore_entity, mocker):
    """Test"""
    mocked_entity = make_datastore_entity()
    mocked_get = mocker.patch("google.cloud.datastore.Client.get",
                              return_value=mocked_entity)
    result = Datastore().get_entity("kind", "namespace", 1)
    mocked_get.assert_called_once()
    assert result is not None
    for key in mocked_entity.keys():
        assert result[key] == mocked_entity[key]
    assert result["id"] == mocked_entity.id
Esempio n. 2
0
def test_save_entity(mocked_datastore):
    Datastore().save_entity("kind", "namespace", {"data": "test"})
    mocked_datastore.return_value.put.assert_called_once()
Esempio n. 3
0
def test_query_entity_with_filters_passing_filters(mocked_datastore):
    filter_list = [["field1", ">=", "field2"]]
    Datastore().query_entity_with_filters("kind", "namespace", filter_list)
    mocked_datastore.return_value.query.assert_called_once()
Esempio n. 4
0
def test_query_entity_with_filters_passing_empty_list(mocked_datastore):
    Datastore().query_entity_with_filters("kind", "namespace", [])
    mocked_datastore.return_value.query.assert_called_once()
Esempio n. 5
0
def test_get_entity_not_existing_entity_should_raise_error(_1, _2, _3):
    """Test"""
    with pytest.raises(Exception):
        Datastore().get_entity("kind", "namespace", 1)
Esempio n. 6
0
def test_get_entity_not_passing_id_should_raise_error(_):
    """Test"""
    with pytest.raises(ValueError):
        Datastore().get_entity(None, None, None)
Esempio n. 7
0
def test_update_entity(mocked_datastore):
    """Test"""
    mocked_entity = Mock(spec=Entity)
    mocked_entity.key = Mock()
    Datastore().update_entity("kind", "namespace", mocked_entity, {})
    mocked_datastore.return_value.put.assert_called_once()