Browse Source

PYTEST COVERAGE 77%

Akash 3 years ago
parent
commit
98eba6c1db

BIN
tests/0TestInput/RawTestData.xlsx


BIN
tests/0TestInput/ServiceTestInput/CompleteBaangtWebdemo_else.xlsx


BIN
tests/0TestInput/ServiceTestInput/CompleteBaangtWebdemo_else_error.xlsx


+ 75 - 0
tests/test_ApiHandling.py

@@ -0,0 +1,75 @@
+import pytest
+from unittest.mock import patch
+from baangt.TestSteps.Exceptions import baangtTestStepException
+from baangt.base.ApiHandling import ApiHandling
+
+
+class fake_response:
+    def __init__(self, **kwargs):
+        self.status_code = 200
+        self.headers = ""
+        self.process()
+
+    def get(self, **kwargs):
+        return self
+
+    def post(self, **kwargs):
+        return self
+
+    def process(self):
+        return {"success": 200, "headers": ""}
+
+    def json(self):
+        return '{"success": 200, "headers": ""}'
+
+    def close(self):
+        pass
+
+
+@pytest.fixture(scope="module")
+def apiHandling():
+    return ApiHandling()
+
+
+@patch("requests.Session", fake_response)
+def test_getSession(apiHandling):
+    apiHandling.getSession()
+    assert 1 == 1
+
+
+@pytest.mark.parametrize("sessionNumber", [(None), (1)])
+def test_getNewSession(sessionNumber, apiHandling):
+    if sessionNumber:
+        apiHandling.getNewSession(sessionNumber=sessionNumber)
+    else:
+        with pytest.raises(baangtTestStepException):
+            apiHandling.getNewSession()
+    assert 1 in apiHandling.session
+
+
+@patch.object(ApiHandling, "getSession", fake_response)
+def test_getURL(apiHandling):
+    apiHandling.setBaseURL("")
+    apiHandling.setEndPoint("")
+    apiHandling.getURL()
+    assert 1 == 1
+
+
+@pytest.mark.parametrize("status", [(200), (300)])
+def test_returnTestCaseStatus(status, apiHandling):
+    result = apiHandling.returnTestCaseStatus(status)
+    assert result == "OK" or result == "Failed"
+
+
+@patch.object(ApiHandling, "getSession", fake_response)
+def test_postURL(apiHandling):
+    apiHandling.setBaseURL("")
+    apiHandling.setEndPoint("")
+    apiHandling.postURL(content="{}", url="url")
+    assert 1 == 1
+
+
+def test_setLoginData(apiHandling):
+    apiHandling.setLoginData("user", "pass")
+    assert apiHandling.session[1].auth == ("user", "pass")
+    apiHandling.tearDown()

+ 32 - 1
tests/test_browserHandling.py

@@ -222,4 +222,35 @@ def test_mobileConnectAppium(browserName, desired_app, mobileApp, mobile_app_set
     wdf = WebdriverFunctions
     with patch.dict(wdf.BROWSER_DRIVERS, {GC.BROWSER_APPIUM: MagicMock}):
         BrowserDriver._mobileConnectAppium(browserName, desired_app, mobileApp, mobile_app_setting)
-    assert 1 == 1
+    assert 1 == 1
+
+
+def test_handleIframe(getdriver):
+    getdriver.browserData = MagicMock()
+    getdriver.handleIframe("test")
+    assert 1 == 1
+    getdriver.iFrame = "test"
+    getdriver.handleIframe()
+    assert 1 == 1
+
+
+def test_checkLinks(getdriver):
+    getdriver.browserData = MagicMock()
+    getdriver.checkLinks()
+    assert 1 == 1
+
+
+def test_waitForPageLoadAfterButtonClick(getdriver):
+    getdriver.browserData = MagicMock()
+    getdriver.html = "test"
+    getdriver.waitForPageLoadAfterButtonClick()
+    assert 1 == 1
+
+
+@pytest.mark.parametrize("function", [("close"), ("closeall-0"), ("")])
+def test_handleWindow(function, getdriver):
+    getdriver.browserData = MagicMock()
+    getdriver.browserData.driver.window_handles = ["test"]
+    getdriver.handleWindow(function=function)
+    assert 1 == 1
+

+ 22 - 0
tests/test_browserHelperFunction.py

@@ -0,0 +1,22 @@
+import pytest
+import logging
+from unittest.mock import MagicMock, patch
+from baangt.base.BrowserHandling.BrowserHelperFunction import BrowserHelperFunction
+
+
+@pytest.mark.parametrize("desiredCapabilities", [({}), ({"seleniumGridIp": "0.0.0.0", "seleniumGridPort": "4444"})])
+def test_browserHelper_setSettingsRemoteV4(desiredCapabilities):
+    result = BrowserHelperFunction.browserHelper_setSettingsRemoteV4(desiredCapabilities)
+    assert len(result) == 3
+
+
+@pytest.mark.parametrize("logType", [(logging.ERROR), (logging.WARN), ("")])
+def test_browserHelper_log(logType):
+    BrowserHelperFunction.browserHelper_log(logType, "Log Text", MagicMock(), MagicMock, extra="test")
+    assert 1 == 1
+
+
+@patch("baangt.base.ProxyRotate.ProxyRotate.remove_proxy", MagicMock)
+def test_browserHelper_setProxyError():
+    BrowserHelperFunction.browserHelper_setProxyError({"ip": "127.0.0.1", "port": "4444"})
+    assert 1 == 1