You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.3 KiB

  1. from django.test import TestCase
  2. from model_mommy import mommy
  3. from examples.assignment.usecase import StrategyName, bulk_assign
  4. from projects.models import Member, ProjectType
  5. from projects.tests.utils import prepare_project
  6. class TestBulkAssignment(TestCase):
  7. def setUp(self):
  8. self.project = prepare_project(ProjectType.SEQUENCE_LABELING)
  9. self.member_ids = list(Member.objects.values_list("id", flat=True))
  10. self.example = mommy.make("Example", project=self.project.item)
  11. def test_raise_error_if_weights_is_invalid(self):
  12. with self.assertRaises(ValueError):
  13. bulk_assign(
  14. self.project.item.id, StrategyName.weighted_sequential, self.member_ids, [0] * len(self.member_ids)
  15. )
  16. def test_raise_error_if_passing_wrong_member_ids(self):
  17. with self.assertRaises(ValueError):
  18. bulk_assign(
  19. self.project.item.id,
  20. StrategyName.weighted_sequential,
  21. self.member_ids + [100],
  22. [0] * len(self.member_ids),
  23. )
  24. def test_assign_examples(self):
  25. bulk_assign(self.project.item.id, StrategyName.weighted_sequential, self.member_ids, [100, 0, 0])
  26. self.assertEqual(self.example.assignments.count(), 1)
  27. self.assertEqual(self.example.assignments.first().assignee, self.project.admin)