# Path: vulyk/models/tasks.py
# class Batch(Document):
# class AbstractTask(Document):
# class AbstractAnswer(Document):
#     def task_done_in(cls, batch_id: str) -> BatchUpdateResult:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def as_dict(self) -> Dict[str, Any]:
#     def ids_in_batch(cls, batch: Batch) -> List[str]:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def corrections(self) -> int:
#     def corrections(self, value: int) -> None:
#     def corrections(self) -> None:
#     def answers_numbers_by_tasks(cls, task_ids: List[str]) -> Dict[ObjectId, int]:
#     def as_dict(self) -> Dict[str, Dict]:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
# 
# Path: vulyk/signals.py

# 
# Path: tests/base.py
# class BaseTest(unittest.TestCase):
#     DB_NAME = 'vulyk_test'
#     MONGO_URI = 'mongodb://localhost:27017/'
#     # override to run against test DB during tests
#     settings.MONGODB_SETTINGS['DB'] = DB_NAME
#     # allows us to run selected tests w/o need to launch the whole bunch
#     register_connection('default', name=DB_NAME, host=MONGO_URI)
# 
# Path: tests/fixtures.py
# class FakeType(AbstractTaskType):
#     task_model = FakeModel
#     answer_model = FakeAnswer
#     type_name = 'FakeTaskType'
#     template = 'tmpl.html'
# 
#     _name = 'Fake name'
#     _description = 'Fake description'


import unittest
from vulyk.models.tasks import Batch, BatchUpdateResult
from vulyk.signals import on_batch_done
from .base import BaseTest
from .fixtures import FakeType
            closed=False,
            batch_meta={}
        ).save()
        called_times = 0

        @on_batch_done.connect
        def listen(sender: Batch) -> None:
            nonlocal called_times, batch
            assert(sender.id == batch.id), 'Wrong sender {!r}'.format(sender)
            called_times += 1

        result = Batch.task_done_in(batch.id)
        batch.reload()

        self.assertEqual(result, BatchUpdateResult(True, True))
        self.assertTrue(batch.closed)
        self.assertEqual(batch.tasks_processed, 5)
        self.assertEqual(called_times, 1)

    def test_task_done_closing_closed(self):
        batch = Batch(
            id='default',
            task_type=self.TASK_TYPE,
            tasks_count=5,
            tasks_processed=5,
            closed=True,
            batch_meta={}
        ).save()
        called_times = 0


# Path: vulyk/models/tasks.py
# class Batch(Document):
# class AbstractTask(Document):
# class AbstractAnswer(Document):
#     def task_done_in(cls, batch_id: str) -> BatchUpdateResult:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def as_dict(self) -> Dict[str, Any]:
#     def ids_in_batch(cls, batch: Batch) -> List[str]:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def corrections(self) -> int:
#     def corrections(self, value: int) -> None:
#     def corrections(self) -> None:
#     def answers_numbers_by_tasks(cls, task_ids: List[str]) -> Dict[ObjectId, int]:
#     def as_dict(self) -> Dict[str, Dict]:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
# 
# Path: vulyk/signals.py

# 
# Path: tests/base.py
# class BaseTest(unittest.TestCase):
#     DB_NAME = 'vulyk_test'
#     MONGO_URI = 'mongodb://localhost:27017/'
#     # override to run against test DB during tests
#     settings.MONGODB_SETTINGS['DB'] = DB_NAME
#     # allows us to run selected tests w/o need to launch the whole bunch
#     register_connection('default', name=DB_NAME, host=MONGO_URI)
# 
# Path: tests/fixtures.py
# class FakeType(AbstractTaskType):
#     task_model = FakeModel
#     answer_model = FakeAnswer
#     type_name = 'FakeTaskType'
#     template = 'tmpl.html'
# 
#     _name = 'Fake name'
#     _description = 'Fake description'


# Path: tests/test_batch_model.py
import unittest
from vulyk.models.tasks import Batch, BatchUpdateResult
from vulyk.signals import on_batch_done
from .base import BaseTest
from .fixtures import FakeType

            closed=False,
            batch_meta={}
        ).save()
        called_times = 0

        @on_batch_done.connect
        def listen(sender: Batch) -> None:
            nonlocal called_times, batch
            assert(sender.id == batch.id), 'Wrong sender {!r}'.format(sender)
            called_times += 1

        result = Batch.task_done_in(batch.id)
        batch.reload()

        self.assertEqual(result, BatchUpdateResult(True, True))
        self.assertTrue(batch.closed)
        self.assertEqual(batch.tasks_processed, 5)
        self.assertEqual(called_times, 1)

    def test_task_done_closing_closed(self):
        batch = Batch(
            id='default',
            task_type=self.TASK_TYPE,
            tasks_count=5,
            tasks_processed=5,
            closed=True,
            batch_meta={}
        ).save()
        called_times = 0


        @on_batch_done.connect