Example #1
0
def test_convert_to_nunit_results_format_multiple_results_nunit(mocker):
    x = '{"tags": {"opId": "ServerBackend-f421e441fa310430","browserUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","orgId": "1009391617598028","userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","clusterId": "0216-124733-lone970","user": "******","principalIdpObjectId": "71b45910-e7b4-44d8-82f7-bf6fac4630d0","browserHostName": "uksouth.azuredatabricks.net","parentOpId": "RPCClient-bb9b9591c29c01f7","jettyRpcType": "InternalDriverBackendMessages$DriverBackendRequest"},"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    t = ("2020-9-13", "13:20:16")
    mocker.patch("runeatest.utils.get_date_and_time", return_value=t)
    results = []
    results.append(testreporter.add_testcase("test name 3", True))
    results.append(testreporter.add_testcase("test name 4", True))
    results2 = []
    results2.append(testreporter.add_testcase("test name 5", True))
    results2.append(testreporter.add_testcase("test name 6", True))

    context = pysparkconnect.get_context()
    header = nunitresults.get_nunit_header(results, context)
    suite = nunitresults.get_test_suite_results(results, context)
    test_cases = nunitresults.get_test_case_results(results)
    test_cases += nunitresults.get_test_case_results(results)
    footer = nunitresults.get_nunit_footer()
    str_test_cases = "\n".join(test_cases)
    actual = header + "\n" + suite + "\n" + str_test_cases + "\n" + footer

    now = datetime.now()
    now_date = str(now.year) + str(now.month) + str(now.day)
    now_time = (str(now.hour) + str(now.minute) + str(now.second) +
                str(now.second) + str(now.microsecond))
    fname = "{thisdate}_{thistime}_nunit_test_results.xml".format(
        thisdate=now_date, thistime=now_time)
    f = open(fname, "w")
    f.write(actual)
    f.close()
def test_add_all_passed_test_cases(mocker):
    x = '{"tags": {"opId": "ServerBackend-f421e441fa310430","browserUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","orgId": "1009391617598028","userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","clusterId": "0216-124733-lone970","user": "******","principalIdpObjectId": "71b45910-e7b4-44d8-82f7-bf6fac4630d0","browserHostName": "uksouth.azuredatabricks.net","parentOpId": "RPCClient-bb9b9591c29c01f7","jettyRpcType": "InternalDriverBackendMessages$DriverBackendRequest"},"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)

    actual = []
    actual.append(
        testreporter.add_testcase(
            "test name", True,
            "this test will check that something will work"))
    actual.append(
        testreporter.add_testcase(
            "test name 2", True,
            "this test also will check that something will work"))
    expected = [
        {
            "test": "test name",
            "issuccess": "True",
            "description": "this test will check that something will work",
            "classname": "/Users/[email protected]/runeatest",
            "result": "success",
            "failurereason": "",
        },
        {
            "test": "test name 2",
            "issuccess": "True",
            "description":
            "this test also will check that something will work",
            "classname": "/Users/[email protected]/runeatest",
            "result": "success",
            "failurereason": "",
        },
    ]
    assert expected == actual
Example #3
0
def test_get_test_suite_result_all_passed(mocker):
    x = '{"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    results = []
    results.append(testreporter.add_testcase("test name", True))
    results.append(testreporter.add_testcase("test name 2", True))
    expected = '<test-suite type="TestFixture" name="/Users/[email protected]/runeatest" executed="True" result="success" success="True" time="0.000" asserts="0"><results>'
    actual = nunitresults.get_test_suite_results(results, context)
    assert expected == actual
Example #4
0
def test_get_nunit_header(mocker):
    x = '{"tags": {"opId": "ServerBackend-f421e441fa310430","browserUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","orgId": "1009391617598028","userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","clusterId": "0216-124733-lone970","user": "******","principalIdpObjectId": "71b45910-e7b4-44d8-82f7-bf6fac4630d0","browserHostName": "uksouth.azuredatabricks.net","parentOpId": "RPCClient-bb9b9591c29c01f7","jettyRpcType": "InternalDriverBackendMessages$DriverBackendRequest"},"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    t = ("2020-9-13", "13:20:16")
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    mocker.patch("runeatest.utils.get_date_and_time", return_value=t)
    results = []
    results.append(testreporter.add_testcase("test name", False))
    results.append(testreporter.add_testcase("test name 2", True))
    expected = '<test-results name="/Users/[email protected]/runeatest" total="2" date="2020-9-13" time="13:20:16">\n<environment nunit-version="2.6.0.12035" clr-version="2.0.50727.4963" os-version="uksouth.azuredatabricks.net" platform="Win32NT" cwd="C:\\Program Files\\NUnit 2.6\\bin\\" machine-name="0216-124733-lone970" user="******" user-domain="1009391617598028"/>\n<culture-info current-culture="en-US" current-uiculture="en-US"/>'
    actual = nunitresults.get_nunit_header(results, context)
    assert expected == actual
Example #5
0
def test_convert_to_nunit_results_format_multiple_results(mocker):
    x = '{"tags": {"opId": "ServerBackend-f421e441fa310430","browserUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","orgId": "1009391617598028","userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","clusterId": "0216-124733-lone970","user": "******","principalIdpObjectId": "71b45910-e7b4-44d8-82f7-bf6fac4630d0","browserHostName": "uksouth.azuredatabricks.net","parentOpId": "RPCClient-bb9b9591c29c01f7","jettyRpcType": "InternalDriverBackendMessages$DriverBackendRequest"},"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    t = ("2020-9-13", "13:20:16")
    mocker.patch("runeatest.utils.get_date_and_time", return_value=t)
    results = []
    results.append(
        testreporter.add_testcase(
            "test name fail 1",
            False,
            "this test is described here",
            "but the test has sadly failed",
        ))
    results.append(
        testreporter.add_testcase(
            "test name fail 2",
            False,
            "this test is intending to do something",
            "but the test failed",
        ))
    y = '{"tags": {"opId": "ServerBackend-f421e441fa310430","browserUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","orgId": "1009391617598028","userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","clusterId": "0216-124733-lone970","user": "******","principalIdpObjectId": "71b45910-e7b4-44d8-82f7-bf6fac4630d0","browserHostName": "uksouth.azuredatabricks.net","parentOpId": "RPCClient-bb9b9591c29c01f7","jettyRpcType": "InternalDriverBackendMessages$DriverBackendRequest"},"extraContext":{"notebook_path":"/Users/[email protected]/runeatest/another/notebook"}}'
    context = json.loads(y)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    results2 = []
    results2.append(
        testreporter.add_testcase(
            "test name fail 3",
            False,
            "another test, another description",
            "and another failure",
        ))
    results2.append(
        testreporter.add_testcase(
            "test name fail 4",
            False,
            "another test to fail, another description",
            "and another failure on this build",
        ))

    results3 = results + results2
    actual = nunitresults.convert_to_nunit_results_format(results3)

    now = datetime.now()
    now_date = str(now.year) + str(now.month) + str(now.day)
    now_time = (str(now.hour) + str(now.minute) + str(now.second) +
                str(now.second) + str(now.microsecond))
    fname = "{thisdate}_{thistime}_nunit_test_results.xml".format(
        thisdate=now_date, thistime=now_time)
    f = open(fname, "w")
    f.write(actual)
    f.close()
Example #6
0
def test_get_test_case_results_all_pass(mocker):
    x = '{"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    results = []
    results.append(
        testreporter.add_testcase("test name", True,
                                  "this description describes the test"))
    results.append(
        testreporter.add_testcase("test name 2", True,
                                  "this description describes the test"))
    expected0 = '<test-case name="test name" description="this description describes the test" classname="/Users/[email protected]/runeatest" executed="True" result="success" success="True" time="0.000" asserts="1"/>'
    expected1 = '<test-case name="test name 2" description="this description describes the test" classname="/Users/[email protected]/runeatest" executed="True" result="success" success="True" time="0.000" asserts="1"/>'
    actual = nunitresults.get_test_case_results(results)
    assert expected0 == actual[0]
    assert expected1 == actual[1]
Example #7
0
def test_get_test_case_results_one_failure(mocker):
    x = '{"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}'
    context = json.loads(x)
    mocker.patch("runeatest.pysparkconnect.get_context", return_value=context)
    results = []
    results.append(
        testreporter.add_testcase("test name", False,
                                  "this description describes the test",
                                  "oh dear"))
    expected = '<test-case name="test name" description="this description describes the test" classname="/Users/[email protected]/runeatest" executed="True" result="failure" success="False" time="0.000" asserts="1">\n<failure><message>oh dear\n</message></failure>\n</test-case>'
    actual = nunitresults.get_test_case_results(results)
    assert expected == actual[0]