def test_put_get_list(self):
        persons = [Person(id=gen_uuid(), firstname='David', lastname='Reynolds'),
                   Person(id=gen_uuid(), firstname='Foo', lastname='Bar')]
        self.datastore.put_list(persons)

        entities = self.datastore.get_list([p.id for p in persons])
        assert len(entities) == 2
    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):
        p = Person(id=gen_uuid(), firstname='David', lastname='Reynolds')
        self.datastore.put(p)

        entity = self.datastore.get(p.id)
        assert isinstance(entity, dict)
        assert entity['firstname'] == 'David'
        assert entity['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
    def test_update(self):
        p = Person(id=gen_uuid(), firstname='David', lastname='Reynolds')
        self.datastore.put(p)

        entity = self.datastore.get(p.id)
        p = Person(**entity)
        p.firstname = 'Foo'
        p.lastname = 'Bar'

        self.datastore.update(p)

        entity = self.datastore.get(p.id)
        assert entity['firstname'] == 'Foo'
        assert entity['lastname'] == 'Bar'
    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'