memoQTMTest.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.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.info, None, "TM Info for valid TM guid shouldn't be none!")
  29. def test_all_tms(self):
  30. """Test for all_tms method."""
  31. test = memoQTM.MemoQTM()
  32. self.assertTrue(len(test.all_tms()), "List of TMs shouldn't be empty!")
  33. def test_download_tmx(self):
  34. """Test for download_tmx method."""
  35. test = memoQTM.MemoQTM()
  36. file_path = test.download_tmx(".", self.config["wrong_tm_guid"])
  37. self.assertEqual(file_path, None,
  38. "Filepath for wrong guid should be none!")
  39. file_path = test.download_tmx(".", self.config["valid_tm_guid"])
  40. self.assertNotEqual(file_path, None,
  41. "Filepath shouldn't be none! (argument)")
  42. self.assertTrue(os.path.isfile(file_path),
  43. "File should exist! (argument)")
  44. os.remove(file_path)
  45. test = memoQTM.MemoQTM()
  46. test.set_active_tm(self.config["valid_tm_guid"])
  47. self.assertNotEqual(
  48. test.info, None, "TM Info for valid TM guid shouldn't be none!")
  49. file_path = test.download_tmx(".")
  50. self.assertNotEqual(file_path, None,
  51. "Filepath shouldn't be none! (field)")
  52. self.assertTrue(os.path.isfile(file_path),
  53. "File should exist! (field)")
  54. os.remove(file_path)
  55. if __name__ == "__main__":
  56. unittest.main()