TestDigitalFactoryFileModel.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from pathlib import Path
  2. from src.DigitalFactoryFileModel import DigitalFactoryFileModel
  3. from src.DigitalFactoryFileResponse import DigitalFactoryFileResponse
  4. file_1 = DigitalFactoryFileResponse(client_id = "client_id_1",
  5. content_type = "zomg",
  6. file_name = "file_1.3mf",
  7. file_id = "file_id_1",
  8. library_project_id = "project_id_1",
  9. status = "test",
  10. user_id = "user_id_1",
  11. username = "username_1",
  12. uploaded_at = "2021-04-07T10:33:25.000Z")
  13. file_2 = DigitalFactoryFileResponse(client_id ="client_id_2",
  14. content_type = "zomg",
  15. file_name = "file_2.3mf",
  16. file_id = "file_id_2",
  17. library_project_id = "project_id_2",
  18. status = "test",
  19. user_id = "user_id_2",
  20. username = "username_2",
  21. uploaded_at = "2021-02-06T09:33:22.000Z")
  22. file_wtf = DigitalFactoryFileResponse(client_id ="client_id_1",
  23. content_type = "zomg",
  24. file_name = "file_3.wtf",
  25. file_id = "file_id_3",
  26. library_project_id = "project_id_1",
  27. status = "test",
  28. user_id = "user_id_1",
  29. username = "username_1",
  30. uploaded_at = "2021-04-06T12:33:25.000Z")
  31. def test_setFiles():
  32. model = DigitalFactoryFileModel()
  33. assert model.count == 0
  34. model.setFiles([file_1, file_2])
  35. assert model.count == 2
  36. assert model.getItem(0)["fileName"] == "file_1.3mf"
  37. assert model.getItem(1)["fileName"] == "file_2.3mf"
  38. def test_clearProjects():
  39. model = DigitalFactoryFileModel()
  40. model.setFiles([file_1, file_2])
  41. model.clearFiles()
  42. assert model.count == 0
  43. def test_setProjectMultipleTimes():
  44. model = DigitalFactoryFileModel()
  45. model.setFiles([file_1, file_2])
  46. model.setFiles([file_2])
  47. assert model.count == 1
  48. assert model.getItem(0)["fileName"] == "file_2.3mf"
  49. def test_setFilter():
  50. model = DigitalFactoryFileModel()
  51. model.setFiles([file_1, file_2, file_wtf])
  52. model.setFilters({"file_name": lambda x: Path(x).suffix[1:].lower() in ["3mf"]})
  53. assert model.count == 2
  54. model.clearFilters()
  55. assert model.count == 3