Пример #1
0
 def test_add_changes_to_batch(self):
     new_batch = Batch(title="Best Batch Ever")
     new_batch.save()
     add_versions_to_batch(new_batch, changed_items())
     self.assertIn(self.new_author,
                   [bi.version.object for bi
                    in new_batch.batchitem_set.all()])
Пример #2
0
class BatchTest(TestCase):
    def setUp(self):
        self.key = generate_key()
        self.batch = Batch(title="Best Batch Ever")
        self.new_author = create_author()
        self.batch.save()

    def tearDown(self):
        Author.objects.all().delete()
        BatchItem.objects.all().delete()

    def test_batch_serialization_and_processing(self):
        add_versions_to_batch(self.batch, changed_items())
        serialized = serialize_batch(self.key.decode('hex'), self.batch)
        process_batch(self.key.decode('hex'),
                      serialized['batch'],
                      serialized['iv'])

    def test_batch_with_deletion(self):
        delete_with_reversion(self.new_author)
        add_versions_to_batch(self.batch, changed_items())
        serialized = serialize_batch(self.key.decode('hex'), self.batch)
        with self.assertRaises(ObjectDoesNotExist):
            process_batch(self.key.decode('hex'),
                          serialized['batch'],
                          serialized['iv'])
Пример #3
0
 def test_add_changes_to_batch(self):
     new_batch = Batch(title="Best Batch Ever")
     new_batch.save()
     add_versions_to_batch(new_batch, changed_items())
     self.assertIn(self.new_author,
                   [bi.version.object for bi
                    in new_batch.batchitem_set.all()])
Пример #4
0
class BatchTest(TestCase):
    def setUp(self):
        self.key = generate_key()
        self.batch = Batch(title="Best Batch Ever")
        self.new_author = create_author()
        self.batch.save()

    def tearDown(self):
        Author.objects.all().delete()
        BatchItem.objects.all().delete()

    def test_batch_serialization_and_processing(self):
        add_versions_to_batch(self.batch, changed_items())
        serialized = serialize_batch(self.key.decode('hex'), self.batch)
        process_batch(self.key.decode('hex'),
                      serialized['batch'],
                      serialized['iv'])

    def test_batch_with_deletion(self):
        delete_with_reversion(self.new_author)
        add_versions_to_batch(self.batch, changed_items())
        serialized = serialize_batch(self.key.decode('hex'), self.batch)
        with self.assertRaises(ObjectDoesNotExist):
            process_batch(self.key.decode('hex'),
                          serialized['batch'],
                          serialized['iv'])
Пример #5
0
 def handle_noargs(self, **options):
     """
     clean pushes, get latest of each distinct object and mark as pushed
     """
     
     print "Initializing Nudge"
     print "  - Deleting all batches and batch items"
     Batch.objects.all().delete()
     BatchItem.objects.all().delete()
     
     print "  - Generating initial key"
     settings, created = Setting.objects.get_or_create(pk=1)
     new_key= generate_key()
     settings.local_key=new_key
     settings.save()
     
     print "  - Creating silent batch"
     silent = Batch(title="Nudge Initialization")
     silent.save()
     
     print "  - Adding objects to batch"
     latest = latest_objects()
     for l in latest:
         batch_item = BatchItem(object_id=l.object_id, version=l, batch=silent)
         batch_item.save()
         
     print "  - Marking batch as pushed"
     silent.pushed = datetime.datetime.now()
     silent.save()
Пример #6
0
 def test_batch_validation(self):
     batch1=Batch(title="Best Batch Ever")
     batch1.save()
     batch2=Batch(title="2nd Best Batch Ever")
     batch2.save()
     add_versions_to_batch(batch1, changed_items())
     add_versions_to_batch(batch2, changed_items())
     with self.assertRaises(BatchValidationError):
         batch1.is_valid(test_only=False)
Пример #7
0
 def test_batch_validation(self):
     batch1 = Batch(title="Best Batch Ever")
     batch1.save()
     batch2 = Batch(title="2nd Best Batch Ever")
     batch2.save()
     add_versions_to_batch(batch1, changed_items())
     add_versions_to_batch(batch2, changed_items())
     with self.assertRaises(BatchValidationError):
         batch1.is_valid(test_only=False)