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.

59 lines
1.9 KiB

  1. import uuid
  2. from django.test import TestCase
  3. from data_import.pipeline.data import BinaryData, TextData
  4. from examples.models import Example
  5. from projects.tests.utils import prepare_project
  6. class TestTextData(TestCase):
  7. def setUp(self):
  8. self.dic = {
  9. "example_uuid": uuid.uuid4(),
  10. "filename": "test.txt",
  11. "upload_name": "test.txt",
  12. "text": "test",
  13. }
  14. self.project = prepare_project()
  15. def test_parse(self):
  16. data = TextData.parse(**self.dic)
  17. self.assertIsInstance(data, TextData)
  18. self.assertEqual(data.uuid, self.dic["example_uuid"])
  19. self.assertEqual(data.filename, self.dic["filename"])
  20. self.assertEqual(data.upload_name, self.dic["upload_name"])
  21. self.assertEqual(data.text, self.dic["text"])
  22. def test_parse_empty_text(self):
  23. self.dic["text"] = ""
  24. with self.assertRaises(ValueError):
  25. TextData.parse(**self.dic)
  26. def test_create(self):
  27. data = TextData.parse(**self.dic)
  28. example = data.create(self.project.item)
  29. self.assertIsInstance(example, Example)
  30. self.assertEqual(example.uuid, self.dic["example_uuid"])
  31. class TestBinaryData(TestCase):
  32. def setUp(self):
  33. self.dic = {
  34. "example_uuid": uuid.uuid4(),
  35. "filename": "test.txt",
  36. "upload_name": "test.txt",
  37. }
  38. self.project = prepare_project()
  39. def test_parse(self):
  40. data = BinaryData.parse(**self.dic)
  41. self.assertIsInstance(data, BinaryData)
  42. self.assertEqual(data.uuid, self.dic["example_uuid"])
  43. def test_create(self):
  44. data = BinaryData.parse(**self.dic)
  45. example = data.create(self.project.item)
  46. self.assertIsInstance(example, Example)
  47. self.assertEqual(example.uuid, self.dic["example_uuid"])
  48. self.assertEqual(example.text, None)