memoQTMTest.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import unittest
  2. import memoQTM
  3. import json
  4. import os
  5. class MemoQTMTest(unittest.TestCase):
  6. """Tests for memoQTM module."""
  7. def __init__(self, *args, **kwargs):
  8. super(MemoQTMTest, self).__init__(*args, **kwargs)
  9. with open("testFiles/testConfig.json") as json_file:
  10. self.config = json.load(json_file)
  11. def test_get_tm_details(self):
  12. """Test for get_tm_details method."""
  13. test = memoQTM.MemoQTM()
  14. self.assertEqual(
  15. test.get_tm_details(self.config["wrong_tm_guid"]), None,
  16. "TM Info for wrong TM guid should be none!")
  17. self.assertNotEqual(
  18. test.get_tm_details(self.config["valid_tm_guid"]), None,
  19. "TM Info for wrong TM guid shouldn't be none!")
  20. def test_set_active_tm(self):
  21. """Test for set_active_tm method."""
  22. test = memoQTM.MemoQTM()
  23. test.set_active_tm(self.config["wrong_tm_guid"])
  24. self.assertEqual(
  25. test.tm.info, None, "TM Info for wrong TM guid should be none!")
  26. test.set_active_tm(self.config["valid_tm_guid"])
  27. self.assertNotEqual(
  28. test.tm.info, None, "TM Info for valid TM guid shouldn't be none!")
  29. def test_get_all_tms(self):
  30. """Test for get_all_tms method."""
  31. test = memoQTM.MemoQTM()
  32. self.assertTrue(len(test.get_all_tms()),
  33. "List of TMs shouldn't be empty!")
  34. def test_download_tmx(self):
  35. """Test for download_tmx method."""
  36. test = memoQTM.MemoQTM()
  37. file_path = test.download_tmx(".", self.config["wrong_tm_guid"])
  38. self.assertEqual(file_path, None,
  39. "Filepath for wrong guid should be none!")
  40. file_path = test.download_tmx(".", self.config["valid_tm_guid"])
  41. self.assertNotEqual(file_path, None,
  42. "Filepath shouldn't be none! (argument)")
  43. self.assertTrue(os.path.isfile(file_path),
  44. "File should exist! (argument)")
  45. os.remove(file_path)
  46. test = memoQTM.MemoQTM()
  47. test.set_active_tm(self.config["valid_tm_guid"])
  48. self.assertNotEqual(
  49. test.tm.info, None, "TM Info for valid TM guid shouldn't be none!")
  50. file_path = test.download_tmx(".")
  51. self.assertNotEqual(file_path, None,
  52. "Filepath shouldn't be none! (field)")
  53. self.assertTrue(os.path.isfile(file_path),
  54. "File should exist! (field)")
  55. os.remove(file_path)
  56. if __name__ == "__main__":
  57. unittest.main()