memoQResourceTest.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import unittest
  2. import memoQResource
  3. import json
  4. import os
  5. class MemoQResourceTest(unittest.TestCase):
  6. """Tests for memoQResource module."""
  7. def __init__(self, *args, **kwargs):
  8. super(MemoQResourceTest, self).__init__(*args, **kwargs)
  9. with open("testFiles/testConfig.json") as json_file:
  10. self.config = json.load(json_file)
  11. def test_valid_type(self):
  12. """ Test for valid_type method."""
  13. test = memoQResource.MemoQResource()
  14. self.assertFalse(
  15. test.valid_type(self.config["wrong_resource_type"]), "Wrong type should return false!")
  16. self.assertTrue(
  17. test.valid_type(self.config["valid_resource_type"]), "Valid type should return true!")
  18. def test_set_type(self):
  19. """ Test for set_type method."""
  20. test = memoQResource.MemoQResource()
  21. test.set_type(self.config["wrong_resource_type"])
  22. self.assertEqual(
  23. test.get_type(), None, "Setting wrong type succeeded!")
  24. test.set_type(self.config["valid_resource_type"])
  25. self.assertNotEqual(
  26. test.get_type(), None, "Setting valid type failed!")
  27. def test_set_active_resource(self):
  28. """ Test for get_project_by_domain method."""
  29. test = memoQResource.MemoQResource()
  30. test.set_active_resource(self.config["wrong_resource_guid"],
  31. self.config["valid_resource_type"])
  32. self.assertEqual(
  33. test.info, None, "Setting active resource with wrong guid \
  34. and valid type should return none!")
  35. test.set_active_resource(self.config["valid_resource_guid"],
  36. self.config["wrong_resource_type"])
  37. self.assertEqual(
  38. test.info, None, "Setting active resource with valid guid \
  39. and wrong type should return none!")
  40. test.set_active_resource(self.config["valid_resource_guid"],
  41. self.config["valid_resource_type"])
  42. self.assertNotEqual(
  43. test.info, None, "Setting active resource with valid guid \
  44. and type shouldn't return none!")
  45. def test_get_resources_of_type(self):
  46. """ Test for get_resources_of_type method."""
  47. test = memoQResource.MemoQResource()
  48. self.assertEqual(
  49. test.get_resources_of_type(self.config["wrong_resource_type"]), None, "Lookup for wrong type should return none!")
  50. self.assertNotEqual(test.get_resources_of_type(
  51. self.config["valid_resource_type"]), None, "Lookup for valid type shouldn't return none!")
  52. def test_get_all_resources(self):
  53. """ Test for get_all_resources method."""
  54. test = memoQResource.MemoQResource()
  55. test.set_active_resource(self.config["valid_resource_guid"],
  56. self.config["valid_resource_type"])
  57. resources = test.get_all_resources()
  58. self.assertTrue(len(resources),
  59. "List of resources shouldn't be empty!")
  60. self.assertTrue(len([x for x in resources if x[1].Guid == test.info.Guid and x[1].Name == test.info.Name]),
  61. "List should contain our valid resource!")
  62. def test_download_resource(self):
  63. """ Test for download_resource method."""
  64. test = memoQResource.MemoQResource()
  65. test.set_active_resource(self.config["valid_resource_guid"],
  66. self.config["valid_resource_type"])
  67. file_path = test.download_resource(".")
  68. self.assertTrue(os.path.isfile(file_path), "File should exist!")
  69. os.remove(file_path)
  70. if __name__ == "__main__":
  71. unittest.main()