def test_post(self): client = result_sink_util.ResultSinkClient() client.sink = 'Make sink not None so _compose_test_result will be called' client._post_test_result = mock.MagicMock() client.post( 'testname', 'PASS', True, test_log='some_log', tags=[('tag key', 'tag value')]) client._post_test_result.assert_called_with( result_sink_util._compose_test_result( 'testname', 'PASS', True, test_log='some_log', tags=[('tag key', 'tag value')])) client.post('testname', 'PASS', True, test_log='some_log') client._post_test_result.assert_called_with( result_sink_util._compose_test_result( 'testname', 'PASS', True, test_log='some_log')) client.post('testname', 'PASS', True) client._post_test_result.assert_called_with( result_sink_util._compose_test_result('testname', 'PASS', True))
def test_compose_test_result(self): """Tests compose_test_result function.""" # Test a test result without log_path. test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'PASS', True) expected = { 'testId': 'TestCase/testSomething', 'status': 'PASS', 'expected': True, 'tags': [], } self.assertEqual(test_result, expected) short_log = 'Some logs.' # Tests a test result with log_path. test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'PASS', True, short_log) expected = { 'testId': 'TestCase/testSomething', 'status': 'PASS', 'expected': True, 'summaryHtml': '<text-artifact artifact-id="Test Log" />', 'artifacts': { 'Test Log': { 'contents': base64.b64encode(short_log) }, }, 'tags': [], } self.assertEqual(test_result, expected)
def test_long_test_log(self): """Tests long test log is reported as expected.""" len_32_str = 'This is a string in length of 32' self.assertEqual(len(len_32_str), 32) len_4128_str = (4 * 32 + 1) * len_32_str self.assertEqual(len(len_4128_str), 4128) expected = { 'testId': 'TestCase/testSomething', 'status': 'PASS', 'expected': True, 'summaryHtml': '<text-artifact artifact-id="Test Log" />', 'artifacts': { 'Test Log': { 'contents': base64.b64encode(len_4128_str) }, }, 'tags': [], 'testMetadata': { 'name': 'TestCase/testSomething' }, } test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'PASS', True, len_4128_str) self.assertEqual(test_result, expected)
def test_compose_test_result_assertions(self): """Tests invalid status is rejected""" with self.assertRaises(AssertionError): test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'SOME_INVALID_STATUS', True) with self.assertRaises(AssertionError): test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'PASS', True, tags=('a', 'b')) with self.assertRaises(AssertionError): test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'PASS', True, tags=[('a', 'b', 'c'), ('d', 'e')]) with self.assertRaises(AssertionError): test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'PASS', True, tags=[('a', 'b'), ('c', 3)])
def test_composed_with_tags(self): """Tests tags is in correct format.""" expected = { 'testId': 'TestCase/testSomething', 'status': 'SKIP', 'expected': True, 'tags': [{ 'key': 'disabled_test', 'value': 'true', }] } test_result = result_sink_util._compose_test_result( 'TestCase/testSomething', 'SKIP', True, tags=[('disabled_test', 'true')]) self.assertEqual(test_result, expected)