示例#1
0
    def test_index_chunk_task(self):
        simple_items = [simple(save=True) for i in range(10)]

        # With live indexing, that'll create items in the index. Since
        # we want to test index_chunk_test, we need a clean index to
        # start with so we delete and recreate it.
        self.setup_indexes(empty=True)

        self.refresh()

        # Verify there's nothing in the index.
        eq_(len(SimpleIndex.search()), 0)

        # Create the record and the chunk and then run it through
        # celery.
        batch_id = "ou812"
        rec = record(batch_id=batch_id, save=True)

        chunk = (SimpleIndex, [item.id for item in simple_items])
        index_chunk_task.delay(get_index(), batch_id, rec.id, chunk)

        # Verify everything is in the index now.
        eq_(len(SimpleIndex.search()), 10)

        # Verify the record was marked succeeded.
        rec = Record.objects.get(pk=rec.id)
        eq_(rec.status, Record.STATUS_SUCCESS)
示例#2
0
    def test_index_chunk_task(self):
        simple_items = [simple(save=True) for i in range(10)]

        # With live indexing, that'll create items in the index. Since
        # we want to test index_chunk_test, we need a clean index to
        # start with so we delete and recreate it.
        self.setup_indexes(empty=True)

        self.refresh()

        # Verify there's nothing in the index.
        eq_(len(SimpleIndex.search()), 0)

        # Create the record and the chunk and then run it through
        # celery.
        batch_id = 'ou812'
        rec = record(batch_id=batch_id, save=True)

        chunk = (SimpleIndex, [item.id for item in simple_items])
        index_chunk_task.delay(get_index(), batch_id, rec.id, chunk)

        # Verify everything is in the index now.
        eq_(len(SimpleIndex.search()), 10)

        # Verify the record was marked succeeded.
        rec = Record.objects.get(pk=rec.id)
        eq_(rec.status, Record.STATUS_SUCCESS)
示例#3
0
    def test_mark(self):
        """Test marking as fail/success."""
        r = record(save=True)

        eq_(Record.objects.filter(status=Record.STATUS_NEW).count(), 1)
        eq_(Record.objects.filter(status=Record.STATUS_FAIL).count(), 0)
        eq_(Record.objects.filter(status=Record.STATUS_SUCCESS).count(), 0)

        r.mark_fail('Errorz!')
        eq_(Record.objects.filter(status=Record.STATUS_NEW).count(), 0)
        eq_(Record.objects.filter(status=Record.STATUS_FAIL).count(), 1)
        eq_(Record.objects.filter(status=Record.STATUS_SUCCESS).count(), 0)

        r.mark_success()
        eq_(Record.objects.filter(status=Record.STATUS_NEW).count(), 0)
        eq_(Record.objects.filter(status=Record.STATUS_FAIL).count(), 0)
        eq_(Record.objects.filter(status=Record.STATUS_SUCCESS).count(), 1)