GoogleCloudPlatform/gcloud-python — pull request #281 by dhermes (2014-10-22 07:35:08+00:00)
Title: Functional test - Add datastore query tests

This implements `projection`, `offset` and `group_by` on `datastore.query.Query`. I looked and didn't see any equivalent bugs from them.

As new `Query` features are outside the scope of functional / regression testing, I am going to peel them off into a separate PR and then rebase this one onto it after that is reviewed. However, please feel free to dig into this review.

Some other things to notice:
- #280 was filed as a result of this.
- In `gcloud-node`, fetching on a query returns a new query with the cursor set. We set the cursor after a query is completed, but this is not `start_cursor` so a user is still required to create a new cursor via:

```python
results = query.fetch()
new_query = query.with_cursor(query.cursor())
```

Also note that in tests like `test_limit_queries` #280 is most relevant and the `gcloud-node` implementation could also benefit from the `more_results` boolean returned from a connection.
- Raising a `RuntimeError` on `cursor()` access feels wrong. In reality, we'd like to access the start cursor and the end cursor and the one set on `Query` is one we next really want set, but instead returned as part of `fetch` results.
- Running these tests very often (i.e. 3 times a minute) resulted in very flaky results for the filter tests. I tried to address this by doing bulk adds / deletes in a `transaction` but it still was flaky. /cc @pcostell
- The `gcloud-node` implementation seems to allow `Dataset.save` to take a list of entities and save them in a transaction. This may be worth adding.
- We haven't implemented [`keys_only` queries][1] though I'm unsure if the Cloud Datastore API supports this.
- Getting just the `dict` from two `Entity`s for comparison should be easier. I suppose we could implement `__eq__` here.
- The code in `test_query_paginate_with_offset` is much more convoluted than the `gcloud-node` [equivalent][2]. This is mostly because `runQuery` does a lot under the covers in node land.
- I am unclear why the `group_by` query only returns two entities. Maybe someone can fill me in?

[1]: https://cloud.google.com/appengine/docs/python/datastore/queries#Python_Keys_only_queries
[2]: https://github.com/GoogleCloudPlatform/gcloud-node/blob/029f3a52e05a3b59bd07f69d7d2032b7a61fe331/regression/datastore.js#L312