def test_put_get_list(self):
        user = User(id=gen_uuid(), firstname='David', lastname='Reynolds')
        user.username = '******'
        self.datastore.put(user)

        entry1 = Entry(id=gen_uuid(),
                       user_id=user.id,
                       title='Foo',
                       content='Hello, World')

        entry2 = Entry(id=gen_uuid(),
                       user_id=user.id,
                       title='Bar',
                       content='Test entry number 2')

        self.datastore.put_list([entry1, entry2])

        index = self.datastore.indexes['index_user_entries']

        # get all entries that have this user_id. Like before, there are two SELECTs.
        # get_all selects the entity_id's of all entries where
        # index_user_entries.user_id == user.id and then gets a list of entities
        # that match the entity_id's from the entities table.
        entries = index.get_all(self.datastore, user_id=user.id)
        assert len(entries) == 2
    def test_put_get(self):
        user = User(id=gen_uuid(), firstname='David', lastname='Reynolds')
        user.username = '******'

        self.datastore.put(user)

        index = self.datastore.indexes['index_user']

        # Get operations on indexes perform two queries. One to get the entity_id
        # from the index table and another for pulling results from the entities table
        # using that entity_id.
        user = index.get(self.datastore, username='******')
        assert user['firstname'] == 'David'
        assert user['lastname'] == 'Reynolds'
    def test_put_get(self):
        user = User(id=gen_uuid(), firstname='David', lastname='Reynolds')
        user.username = '******'
        self.datastore.put(user)

        index = self.datastore.indexes['index_user']
        user = index.get(self.datastore, username='******')

        entries = []
        for i in xrange(10):
            entry = Entry(id=gen_uuid(),
                          user_id=user['id'],
                          title='%s' % i,
                          content='Hello, world')
            entries.append(entry)
        self.datastore.put_list(entries)

        # the entries and their indexes are distributed across the two test shards
        entry_index = self.datastore.indexes['index_user_entries']
        user_entries = entry_index.get_all(self.datastore, user_id=user['id'])

        assert len(user_entries) == 10