test_ApiHandling.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import pytest
  2. from unittest.mock import patch
  3. from baangt.TestSteps.Exceptions import baangtTestStepException
  4. from baangt.base.ApiHandling import ApiHandling
  5. class fake_response:
  6. def __init__(self, **kwargs):
  7. self.status_code = 200
  8. self.headers = ""
  9. self.process()
  10. def get(self, **kwargs):
  11. return self
  12. def post(self, **kwargs):
  13. return self
  14. def process(self):
  15. return {"success": 200, "headers": ""}
  16. def json(self):
  17. return '{"success": 200, "headers": ""}'
  18. def close(self):
  19. pass
  20. @pytest.fixture(scope="module")
  21. def apiHandling():
  22. return ApiHandling()
  23. @patch("requests.Session", fake_response)
  24. def test_getSession(apiHandling):
  25. apiHandling.getSession()
  26. assert 1 == 1
  27. @pytest.mark.parametrize("sessionNumber", [(None), (1)])
  28. def test_getNewSession(sessionNumber, apiHandling):
  29. if sessionNumber:
  30. apiHandling.getNewSession(sessionNumber=sessionNumber)
  31. else:
  32. with pytest.raises(baangtTestStepException):
  33. apiHandling.getNewSession()
  34. assert 1 in apiHandling.session
  35. @patch.object(ApiHandling, "getSession", fake_response)
  36. def test_getURL(apiHandling):
  37. apiHandling.setBaseURL("")
  38. apiHandling.setEndPoint("")
  39. apiHandling.getURL()
  40. assert 1 == 1
  41. @pytest.mark.parametrize("status", [(200), (300)])
  42. def test_returnTestCaseStatus(status, apiHandling):
  43. result = apiHandling.returnTestCaseStatus(status)
  44. assert result == "OK" or result == "Failed"
  45. @patch.object(ApiHandling, "getSession", fake_response)
  46. def test_postURL(apiHandling):
  47. apiHandling.setBaseURL("")
  48. apiHandling.setEndPoint("")
  49. apiHandling.postURL(content="{}", url="url")
  50. assert 1 == 1
  51. def test_setLoginData(apiHandling):
  52. apiHandling.setLoginData("user", "pass")
  53. assert apiHandling.session[1].auth == ("user", "pass")
  54. apiHandling.tearDown()