Beispiel #1
0
    def test_iter_update(self):
        def desired_action(group):
            i = group['index']
            if i == 1:
                return 'DELETE'
            elif i % 2 == 0:
                return 'UPDATE'
            else:
                return 'IGNORE'

        def mark_cool(group):
            action = desired_action(group)
            if action == 'UPDATE':
                group['is_cool'] = True
                return DocUpdate(group)
            elif action == 'DELETE':
                return DocUpdate(group, delete=True)

        ids = [g._id for g in self.groups] + ['NOT_REAL_ID']
        res = iter_update(self.db, mark_cool, ids)
        refresh_group_views()
        self.assertEqual(res.not_found_ids, {'NOT_REAL_ID'})
        for result_ids, action in [
            (res.ignored_ids, 'IGNORE'),
            (res.deleted_ids, 'DELETE'),
            (res.updated_ids, 'UPDATE'),
        ]:
            self.assertEqual(
                result_ids,
                {g._id
                 for g in self.groups if desired_action(g) == action})
Beispiel #2
0
    def test_iter_update(self):
        def desired_action(group):
            i = group['index']
            if i == 1:
                return 'DELETE'
            elif i % 2 == 0:
                return 'UPDATE'
            else:
                return 'IGNORE'

        def mark_cool(group):
            action = desired_action(group)
            if action == 'UPDATE':
                group['is_cool'] = True
                return DocUpdate(group)
            elif action == 'DELETE':
                return DocUpdate(group, delete=True)

        ids = [g._id for g in self.groups] + ['NOT_REAL_ID']
        res = iter_update(self.db, mark_cool, ids)
        refresh_group_views()
        self.assertEqual(res.not_found_ids, {'NOT_REAL_ID'})
        for result_ids, action in [
            (res.ignored_ids, 'IGNORE'),
            (res.deleted_ids, 'DELETE'),
            (res.updated_ids, 'UPDATE'),
        ]:
            self.assertEqual(
                result_ids,
                {g._id for g in self.groups if desired_action(g) == action}
            )
Beispiel #3
0
    def test_delete(self):
        with IterDB(self.db, chunksize=5) as iter_db:
            deleted_groups = set()
            for group in self.groups[:4]:
                deleted_groups.add(group._id)
                iter_db.delete(group)

            saved_groups = set()
            for group in self.groups[4:]:
                saved_groups.add(group._id)
                iter_db.save(group)
        refresh_group_views()

        self.assertEqual(deleted_groups, iter_db.deleted_ids)
        self.assertEqual(saved_groups, iter_db.saved_ids)
        for group_id in deleted_groups:
            self.assertRaises(ResourceNotFound, self.db.get, group_id)
Beispiel #4
0
    def test_delete(self):
        with IterDB(self.db, chunksize=5) as iter_db:
            deleted_groups = set()
            for group in self.groups[:4]:
                deleted_groups.add(group._id)
                iter_db.delete(group)

            saved_groups = set()
            for group in self.groups[4:]:
                saved_groups.add(group._id)
                iter_db.save(group)
        refresh_group_views()

        self.assertEqual(deleted_groups, iter_db.deleted_ids)
        self.assertEqual(saved_groups, iter_db.saved_ids)
        for group_id in deleted_groups:
            self.assertRaises(ResourceNotFound, self.db.get, group_id)
Beispiel #5
0
 def delete_docs(cls, docs, **params):
     super(Group, cls).delete_docs(docs, **params)
     refresh_group_views()
Beispiel #6
0
 def delete(self):
     super(Group, self).delete()
     refresh_group_views()
Beispiel #7
0
 def save_docs(cls, docs, use_uuids=True, all_or_nothing=False):
     utcnow = datetime.utcnow()
     for doc in docs:
         doc['last_modified'] = utcnow
     super(Group, cls).save_docs(docs, use_uuids, all_or_nothing)
     refresh_group_views()
Beispiel #8
0
 def save(self, *args, **kwargs):
     self.last_modified = datetime.utcnow()
     super(Group, self).save(*args, **kwargs)
     refresh_group_views()
Beispiel #9
0
 def delete_docs(cls, docs, **params):
     super(Group, cls).delete_docs(docs, **params)
     refresh_group_views()
Beispiel #10
0
 def delete(self):
     super(Group, self).delete()
     refresh_group_views()
Beispiel #11
0
 def save_docs(cls, docs, use_uuids=True, all_or_nothing=False):
     utcnow = datetime.utcnow()
     for doc in docs:
         doc['last_modified'] = utcnow
     super(Group, cls).save_docs(docs, use_uuids, all_or_nothing)
     refresh_group_views()
Beispiel #12
0
 def save(self, *args, **kwargs):
     self.last_modified = datetime.utcnow()
     super(Group, self).save(*args, **kwargs)
     refresh_group_views()