test_evidence_candidate.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from .manager_case import ManagerTestCase
  2. from iepy.data.models import EvidenceLabel
  3. from .factories import (
  4. EntityFactory, EntityKindFactory,
  5. RelationFactory, EvidenceCandidateFactory
  6. )
  7. class TestEvidenceCandidate(ManagerTestCase):
  8. judge = "iepy"
  9. def setUp(self):
  10. self.k_person = EntityKindFactory(name='person')
  11. self.k_location = EntityKindFactory(name='location')
  12. self.e_john = EntityFactory(key='john', kind=self.k_person)
  13. self.e_bob = EntityFactory(key='bob', kind=self.k_person)
  14. self.e_argentina = EntityFactory(key='argentina', kind=self.k_location)
  15. self.e_germany = EntityFactory(key='germany', kind=self.k_location)
  16. self.e_australia = EntityFactory(key='australia', kind=self.k_location)
  17. self.person_location_relation = RelationFactory(
  18. left_entity_kind=self.k_person,
  19. right_entity_kind=self.k_location
  20. )
  21. self.positive_label = EvidenceLabel.YESRELATION
  22. self.negative_label = EvidenceLabel.NORELATION
  23. def test_save_label(self):
  24. labels = list(EvidenceLabel.objects.all())
  25. self.assertEqual(len(labels), 0)
  26. candidate = EvidenceCandidateFactory()
  27. candidate.set_label(self.person_location_relation, self.positive_label, self.judge)
  28. labels = list(EvidenceLabel.objects.all())
  29. self.assertEqual(len(labels), 1)
  30. label = labels[0]
  31. self.assertEqual(label.label, self.positive_label)
  32. self.assertEqual(label.judge, self.judge)
  33. self.assertEqual(label.evidence_candidate, candidate)
  34. def test_save_label_twice(self):
  35. labels = list(EvidenceLabel.objects.all())
  36. self.assertEqual(len(labels), 0)
  37. candidate = EvidenceCandidateFactory()
  38. candidate.set_label(self.person_location_relation, self.positive_label, self.judge)
  39. labels = list(EvidenceLabel.objects.all())
  40. self.assertEqual(len(labels), 1)
  41. candidate.set_label(self.person_location_relation, self.negative_label, self.judge)
  42. labels = list(EvidenceLabel.objects.all())
  43. self.assertEqual(len(labels), 1)
  44. label = labels[0]
  45. self.assertEqual(label.label, self.negative_label)
  46. self.assertEqual(label.judge, self.judge)
  47. self.assertEqual(label.evidence_candidate, candidate)
  48. def test_save_diferent_judges(self):
  49. labels = list(EvidenceLabel.objects.all())
  50. self.assertEqual(len(labels), 0)
  51. candidate = EvidenceCandidateFactory()
  52. candidate.set_label(self.person_location_relation, self.positive_label, "judge1")
  53. labels = list(EvidenceLabel.objects.all())
  54. self.assertEqual(len(labels), 1)
  55. candidate.set_label(self.person_location_relation, self.negative_label, "judge2")
  56. labels = list(EvidenceLabel.objects.all())
  57. self.assertEqual(len(labels), 2)
  58. label1, label2 = labels
  59. self.assertNotEqual(label1.judge, label2.judge)
  60. self.assertNotEqual(label1.label, label2.label)