How to use test_default method in tox

Best Python code snippet using tox_python

conftest.py

Source:conftest.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# ======================================================================================================================3# Imports4# ======================================================================================================================5import pytest6pytest_plugins = ['helpers_namespace']7# ======================================================================================================================8# Helpers9# ======================================================================================================================10# noinspection PyUnresolvedReferences11@pytest.helpers.register12def merge_dicts(*args):13 """Given any number of dicts, shallow copy and merge into a new dict, precedence goes to key value pairs in latter14 dicts.15 Args:16 *args (list(dict)): A list of dictionaries to be merged.17 Returns:18 dict: A merged dictionary.19 """20 result = {}21 for dictionary in args:22 result.update(dictionary)23 return result24# noinspection PyUnresolvedReferences25@pytest.helpers.register26def is_sub_dict(small, big):27 """Determine if one dictionary is a subset of another dictionary.28 Args:29 small (dict): A dictionary that is proposed to be a subset of another dictionary.30 big (dict): A dictionary that is a superset of another dictionary.31 Returns:32 bool: A bool indicating if the small dictionary is in fact a sub-dictionary of big33 """34 return dict(big, **small) == big35# ======================================================================================================================36# Fixtures37# ======================================================================================================================38@pytest.fixture(scope='session')39def default_global_properties():40 """Default global properties which can be used to construct valid JUnitXML documents."""41 return \42 """43 <properties>44 <property name="BUILD_URL" value="https://rpc.jenkins.cit.rackspace.net/job/PM_rpc-openstack-pike-rc-xenial_mnaio_no_artifacts-swift-system/78/"/>45 <property name="BUILD_NUMBER" value="78"/>46 <property name="RE_JOB_ACTION" value="system"/>47 <property name="RE_JOB_IMAGE" value="xenial_mnaio_no_artifacts"/>48 <property name="RE_JOB_SCENARIO" value="swift"/>49 <property name="RE_JOB_BRANCH" value="pike-rc"/>50 <property name="RPC_RELEASE" value="r16.2.0"/>51 <property name="RPC_PRODUCT_RELEASE" value="pike"/>52 <property name="OS_ARTIFACT_SHA" value="Unknown"/>53 <property name="PYTHON_ARTIFACT_SHA" value="Unknown"/>54 <property name="APT_ARTIFACT_SHA" value="Unknown"/>55 <property name="REPO_URL" value="https://github.com/rcbops/rpc-openstack"/>56 <property name="JOB_NAME" value="PM_rpc-openstack-pike-rc-xenial_mnaio_no_artifacts-swift-system"/>57 <property name="MOLECULE_TEST_REPO" value="molecule-validate-neutron-deploy"/>58 <property name="MOLECULE_SCENARIO_NAME" value="default"/>59 <property name="ci-environment" value="asc"/>60 </properties>61 """ # noqa62@pytest.fixture(scope='session')63def default_testcase_properties():64 """Default test case properties which can be used to construct valid JUnitXML documents."""65 return \66 """67 <properties>68 <property name="jira" value="ASC-123"/>69 <property name="jira" value="ASC-456"/>70 <property name="test_id" value="1"/>71 <property name="test_step" value="false"/>72 <property name="start_time" value="2018-04-10T21:38:18Z"/>73 <property name="end_time" value="2018-04-10T21:38:19Z"/>74 </properties>75 """76@pytest.fixture(scope='session')77def default_testcase_elements():78 """Default test case properties which can be used to construct valid JUnitXML documents."""79 return \80 """81 <system-out>stdout</system-out>82 <system-err>stderr</system-err>83 """84@pytest.fixture(scope='session')85def invalid_json_config(tmpdir_factory,86 default_global_properties,87 default_testcase_properties,88 default_testcase_elements):89 """config sample"""90 config = \91"""92{93 "test_cycle": "pike",94 "project_id": 12345,95 "module_hierarchy": ["one","two","three"],96 "path_to_test_exec_dir97}98""" # noqa99 config_path = tmpdir_factory.mktemp('data').join('./conf.json').strpath100 with open(str(config_path), 'w') as f:101 f.write(config)102 return config_path103@pytest.fixture(scope='session')104def simple_json_config(tmpdir_factory):105 """config sample"""106 config = \107"""108{109 "zigzag": {110 "test_cycle": "pike",111 "project_id": "12345",112 "build_url": "https://bar.com/foo",113 "build_number": "78",114 "module_hierarchy": ["one","two","three"],115 "path_to_test_exec_dir": "{{ '' }}"116 }117}118""" # noqa119 config_path = tmpdir_factory.mktemp('data').join('./conf.json').strpath120 with open(str(config_path), 'w') as f:121 f.write(config)122 return config_path123@pytest.fixture(scope='session')124def single_passing_xml(tmpdir_factory,125 default_global_properties,126 default_testcase_properties,127 default_testcase_elements):128 """JUnitXML sample representing a single passing test."""129 filename = tmpdir_factory.mktemp('data').join('single_passing.xml').strpath130 junit_xml = \131 """<?xml version="1.0" encoding="utf-8"?>132 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">133 {global_properties}134 <testcase classname="tests.test_default" file="tests/test_default.py" line="8"135 name="test_pass[ansible://localhost]" time="0.00372695922852">136 {testcase_properties}137 {testcase_elements}138 </testcase>139 </testsuite>140 """.format(global_properties=default_global_properties,141 testcase_properties=default_testcase_properties,142 testcase_elements=default_testcase_elements)143 with open(filename, 'w') as f:144 f.write(junit_xml)145 return filename146@pytest.fixture(scope='session')147def invalid_zigzag_config_file(tmpdir_factory,148 default_global_properties,149 default_testcase_properties,150 default_testcase_elements):151 """JUnitXML sample representing a single passing test."""152 filename = tmpdir_factory.mktemp('data').join('config_file.xml').strpath153 config_json = \154 """{155 "environment_variables": {156 "BUILD_URL": "url",157 """158 with open(filename, 'w') as f:159 f.write(config_json)160 return filename161@pytest.fixture(scope='session')162def asc_zigzag_config_file(tmpdir_factory):163 """A config for zigzag used by the ASC team"""164 filename = tmpdir_factory.mktemp('data').join('config_file.json').strpath165 config_json = \166 """{167 "pytest_zigzag_env_vars": {168 "BUILD_URL": null,169 "BUILD_NUMBER": null,170 "RE_JOB_ACTION": null,171 "RE_JOB_IMAGE": null,172 "RE_JOB_SCENARIO": null,173 "RE_JOB_BRANCH": null,174 "RPC_RELEASE": null,175 "RPC_PRODUCT_RELEASE": null,176 "OS_ARTIFACT_SHA": null,177 "PYTHON_ARTIFACT_SHA": null,178 "APT_ARTIFACT_SHA": null,179 "REPO_URL": null,180 "GIT_URL": null,181 "JOB_NAME": null,182 "MOLECULE_TEST_REPO": null,183 "MOLECULE_SCENARIO_NAME": null,184 "PATH_TO_TEST_EXEC_DIR": null,185 "MOLECULE_GIT_COMMIT": null,186 "GIT_COMMIT": null187 },188 "zigzag": {189 "test_cycle": "{{ RPC_PRODUCT_RELEASE }}",190 "project_id": "12345",191 "module_hierarchy": [192 "{{RPC_RELEASE}}",193 "{{JOB_NAME}}",194 "{{MOLECULE_TEST_REPO}}",195 "{{zz_testcase_class}}"196 ],197 "path_to_test_exec_dir": "/molecule/default/tests",198 "build_url": "{{ BUILD_URL }}",199 "build_number": "{{ BUILD_NUMBER }}",200 "project_repo_name": "rpc-openstack",201 "project_branch": "{{ RE_JOB_BRANCH }}",202 "project_fork": "rcbops",203 "project_commit": null,204 "test_repo_name": "{{ MOLECULE_TEST_REPO }}",205 "test_branch": "{{ RE_JOB_BRANCH }}",206 "test_fork": "rcbops",207 "test_commit": "{{ MOLECULE_GIT_COMMIT }}"208 }209 }"""210 with open(filename, 'w') as f:211 f.write(config_json)212 return filename213@pytest.fixture(scope='session')214def mk8s_zigzag_config_file(tmpdir_factory):215 """A config for zigzag used by the ASC team"""216 filename = tmpdir_factory.mktemp('data').join('config_file.json').strpath217 config_json = \218 """{219 "pytest_zigzag_env_vars": {220 "BUILD_URL": null,221 "BUILD_NUMBER": null,222 "BUILD_ID": null,223 "JOB_NAME": null,224 "BUILD_TAG": null,225 "JENKINS_URL": null,226 "EXECUTOR_NUMBER": null,227 "WORKSPACE": null,228 "CVS_BRANCH": null,229 "GIT_COMMIT": null,230 "GIT_URL": null,231 "GIT_BRANCH": null,232 "GIT_LOCAL_BRANCH": null,233 "GIT_AUTHOR_NAME": null,234 "GIT_AUTHOR_EMAIL": null,235 "BRANCH_NAME": null,236 "CHANGE_AUTHOR_DISPLAY_NAME": null,237 "CHANGE_AUTHOR": null,238 "CHANGE_BRANCH": null,239 "CHANGE_FORK": null,240 "CHANGE_ID": null,241 "CHANGE_TARGET": null,242 "CHANGE_TITLE": null,243 "CHANGE_URL": null,244 "JOB_URL": null,245 "NODE_LABELS": null,246 "NODE_NAME": null,247 "PWD": null,248 "STAGE_NAME": null249 },250 "zigzag": {251 "test_cycle": "{{ 'PR' if CHANGE_BRANCH else BRANCH_NAME }}",252 "project_id": "12345",253 "module_hierarchy": [254 "{{ zz_testcase_class }}"255 ],256 "path_to_test_exec_dir": "tools/installer/tests",257 "build_url": "{{ BUILD_URL }}",258 "build_number": "{{ BUILD_NUMBER }}",259 "project_repo_name": "mk8s",260 "project_branch": "{{ CHANGE_BRANCH }}",261 "project_fork": "{{ CHANGE_FORK if CHANGE_FORK else 'rcbops' }}",262 "project_commit": "{{ GIT_COMMIT }}",263 "test_repo_name": "mk8s",264 "test_branch": "{{ CHANGE_BRANCH }}",265 "test_fork": "{{ CHANGE_FORK if CHANGE_FORK else 'rcbops' }}",266 "test_commit": "{{ GIT_COMMIT }}"267 }268 }"""269 with open(filename, 'w') as f:270 f.write(config_json)271 return filename272@pytest.fixture(scope='session')273def valid_zigzag_config_file(tmpdir_factory,274 default_global_properties,275 default_testcase_properties,276 default_testcase_elements):277 """JUnitXML sample representing a single passing test."""278 filename = tmpdir_factory.mktemp('data').join('config_file.xml').strpath279 config_json = \280 """{281 "pytest_zigzag_env_vars": {282 "BUILD_URL": "url",283 "BUILD_NUMBER": null,284 "RE_JOB_ACTION": null,285 "RE_JOB_IMAGE": null,286 "RE_JOB_SCENARIO": null,287 "RE_JOB_BRANCH": null,288 "RPC_RELEASE": null,289 "RPC_PRODUCT_RELEASE": null,290 "OS_ARTIFACT_SHA": null,291 "PYTHON_ARTIFACT_SHA": null,292 "APT_ARTIFACT_SHA": null,293 "REPO_URL": "https://github.com/rcbops/zigzag_asc",294 "GIT_URL": "https://github.com/rcbops/zigzag_mk8s",295 "JOB_NAME": null,296 "MOLECULE_TEST_REPO": "pytest-zigzag",297 "MOLECULE_SCENARIO_NAME": "molecule_scenario",298 "PATH_TO_TEST_EXEC_DIR": "custom_test_dir/",299 "MOLECULE_GIT_COMMIT": "8216c9449ef99216c922f2f2fd01f28e412cfe87",300 "GIT_COMMIT": "mk8s_gitsha"301 }302 }"""303 with open(filename, 'w') as f:304 f.write(config_json)305 return filename306@pytest.fixture(scope='session')307def single_fail_xml(tmpdir_factory,308 default_global_properties,309 default_testcase_properties,310 default_testcase_elements):311 """JUnitXML sample representing a single failing test."""312 filename = tmpdir_factory.mktemp('data').join('single_fail.xml').strpath313 junit_xml = \314 """<?xml version="1.0" encoding="utf-8"?>315 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">316 {global_properties}317 <testcase classname="tests.test_default" file="tests/test_default.py" line="16"318 name="test_fail[ansible://localhost]" time="0.00335693359375">319 {testcase_properties}320 <failure message="assert False">host = &lt;testinfra.host.Host object at 0x7f0921d98cd0&gt;321 def test_fail(host):322 &gt; assert False323 E assert False324 tests/test_default.py:18: AssertionError</failure>325 {testcase_elements}326 </testcase>327 </testsuite>328 """.format(global_properties=default_global_properties,329 testcase_properties=default_testcase_properties,330 testcase_elements=default_testcase_elements)331 with open(filename, 'w') as f:332 f.write(junit_xml)333 return filename334@pytest.fixture(scope='session')335def single_error_xml(tmpdir_factory,336 default_global_properties,337 default_testcase_properties,338 default_testcase_elements):339 """JUnitXML sample representing a single erroring test."""340 filename = tmpdir_factory.mktemp('data').join('single_error.xml').strpath341 junit_xml = \342 """<?xml version="1.0" encoding="utf-8"?>343 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">344 {global_properties}345 <testcase classname="tests.test_default" file="tests/test_default.py" line="20"346 name="test_error[ansible://localhost]" time="0.00208067893982">347 {testcase_properties}348 <error message="test setup failure">host = &lt;testinfra.host.Host object at 0x7f0921d98cd0&gt;349 @pytest.fixture350 def error_fixture(host):351 &gt; raise RuntimeError(&apos;oops&apos;)352 E RuntimeError: oops353 tests/test_default.py:10: RuntimeError</error>354 {testcase_elements}355 </testcase>356 </testsuite>357 """.format(global_properties=default_global_properties,358 testcase_properties=default_testcase_properties,359 testcase_elements=default_testcase_elements)360 with open(filename, 'w') as f:361 f.write(junit_xml)362 return filename363@pytest.fixture(scope='session')364def single_skip_xml(tmpdir_factory,365 default_global_properties,366 default_testcase_properties,367 default_testcase_elements):368 """JUnitXML sample representing a single skipping test."""369 filename = tmpdir_factory.mktemp('data').join('single_skip.xml').strpath370 junit_xml = \371 """<?xml version="1.0" encoding="utf-8"?>372 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">373 {global_properties}374 <testcase classname="tests.test_default" file="tests/test_default.py" line="24"375 name="test_skip[ansible://localhost]" time="0.00197100639343">376 {testcase_properties}377 <skipped message="unconditional skip" type="pytest.skip">378 tests/test_default.py:24: &lt;py._xmlgen.raw object at 0x7f0921ff4d50&gt;379 </skipped>380 {testcase_elements}381 </testcase>382 </testsuite>383 """.format(global_properties=default_global_properties,384 testcase_properties=default_testcase_properties,385 testcase_elements=default_testcase_elements)386 with open(filename, 'w') as f:387 f.write(junit_xml)388 return filename389@pytest.fixture(scope='session')390def flat_all_passing_xml(tmpdir_factory,391 default_global_properties,392 default_testcase_properties,393 default_testcase_elements):394 """JUnitXML sample representing multiple passing test cases."""395 filename = tmpdir_factory.mktemp('data').join('flat_all_passing.xml').strpath396 junit_xml = \397 """<?xml version="1.0" encoding="utf-8"?>398 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">399 {global_properties}400 <testcase classname="tests.test_default" file="tests/test_default.py" line="8"401 name="test_pass1[ansible://localhost]" time="0.00372695922852">402 {testcase_properties}403 {testcase_elements}404 </testcase>405 <testcase classname="tests.test_default" file="tests/test_default.py" line="12"406 name="test_pass2[ansible://localhost]" time="0.00341415405273">407 {testcase_properties}408 {testcase_elements}409 </testcase>410 <testcase classname="tests.test_default" file="tests/test_default.py" line="15"411 name="test_pass3[ansible://localhost]" time="0.00363945960999">412 {testcase_properties}413 {testcase_elements}414 </testcase>415 <testcase classname="tests.test_default" file="tests/test_default.py" line="18"416 name="test_pass4[ansible://localhost]" time="0.00314617156982">417 {testcase_properties}418 {testcase_elements}419 </testcase>420 <testcase classname="tests.test_default" file="tests/test_default.py" line="21"421 name="test_pass5[ansible://localhost]" time="0.00332307815552">422 {testcase_properties}423 {testcase_elements}424 </testcase>425 </testsuite>426 """.format(global_properties=default_global_properties,427 testcase_properties=default_testcase_properties,428 testcase_elements=default_testcase_elements)429 with open(filename, 'w') as f:430 f.write(junit_xml)431 return filename432@pytest.fixture(scope='session')433def suite_all_passing_xml(tmpdir_factory,434 default_global_properties,435 default_testcase_properties,436 default_testcase_elements):437 """JUnitXML sample representing multiple passing test cases in a test suite. (Tests within a Python class)"""438 filename = tmpdir_factory.mktemp('data').join('suite_all_passing.xml').strpath439 junit_xml = \440 """<?xml version="1.0" encoding="utf-8"?>441 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">442 {global_properties}443 <testcase classname="tests.test_default.TestSuite" file="tests/test_default.py" line="8"444 name="test_pass1[ansible://localhost]" time="0.00372695922852">445 {testcase_properties}446 {testcase_elements}447 </testcase>448 <testcase classname="tests.test_default.TestSuite" file="tests/test_default.py" line="12"449 name="test_pass2[ansible://localhost]" time="0.00341415405273">450 {testcase_properties}451 {testcase_elements}452 </testcase>453 <testcase classname="tests.test_default.TestSuite" file="tests/test_default.py" line="15"454 name="test_pass3[ansible://localhost]" time="0.00363945960999">455 {testcase_properties}456 {testcase_elements}457 </testcase>458 <testcase classname="tests.test_default.TestSuite" file="tests/test_default.py" line="18"459 name="test_pass4[ansible://localhost]" time="0.00314617156982">460 {testcase_properties}461 {testcase_elements}462 </testcase>463 <testcase classname="tests.test_default.TestSuite" file="tests/test_default.py" line="21"464 name="test_pass5[ansible://localhost]" time="0.00332307815552">465 {testcase_properties}466 {testcase_elements}467 </testcase>468 </testsuite>469 """.format(global_properties=default_global_properties,470 testcase_properties=default_testcase_properties,471 testcase_elements=default_testcase_elements)472 with open(filename, 'w') as f:473 f.write(junit_xml)474 return filename475@pytest.fixture(scope='session')476def flat_mix_status_xml(tmpdir_factory,477 default_global_properties,478 default_testcase_properties,479 default_testcase_elements):480 """JUnitXML sample representing mixed status for multiple test cases."""481 filename = tmpdir_factory.mktemp('data').join('flat_mix_status.xml').strpath482 junit_xml = \483 """<?xml version="1.0" encoding="utf-8"?>484 <testsuite errors="1" failures="1" name="pytest" skips="1" tests="4" time="1.901">485 {global_properties}486 <testcase classname="tests.test_default" file="tests/test_default.py" line="12"487 name="test_pass[ansible://localhost]" time="0.0034921169281">488 {testcase_properties}489 {testcase_elements}490 </testcase>491 <testcase classname="tests.test_default" file="tests/test_default.py" line="16"492 name="test_fail[ansible://localhost]" time="0.00335693359375">493 {testcase_properties}494 <failure message="assert False">host = &lt;testinfra.host.Host object at 0x7f0921d98cd0&gt;495 def test_fail(host):496 &gt; assert False497 E assert False498 tests/test_default.py:18: AssertionError</failure>499 {testcase_elements}500 </testcase>501 <testcase classname="tests.test_default" file="tests/test_default.py" line="20"502 name="test_error[ansible://localhost]" time="0.00208067893982">503 {testcase_properties}504 <error message="test setup failure">host = &lt;testinfra.host.Host object at 0x7f0921d98cd0&gt;505 @pytest.fixture506 def error_fixture(host):507 &gt; raise RuntimeError(&apos;oops&apos;)508 E RuntimeError: oops509 tests/test_default.py:10: RuntimeError</error>510 {testcase_elements}511 </testcase>512 <testcase classname="tests.test_default" file="tests/test_default.py" line="24"513 name="test_skip[ansible://localhost]" time="0.00197100639343">514 {testcase_properties}515 <skipped message="unconditional skip" type="pytest.skip">516 tests/test_default.py:24: &lt;py._xmlgen.raw object at 0x7f0921ff4d50&gt;517 </skipped>518 {testcase_elements}519 </testcase>520 </testsuite>521 """.format(global_properties=default_global_properties,522 testcase_properties=default_testcase_properties,523 testcase_elements=default_testcase_elements)524 with open(filename, 'w') as f:525 f.write(junit_xml)526 return filename527@pytest.fixture(scope='session')528def bad_xml(tmpdir_factory):529 """JUnitXML sample representing invalid XML."""530 filename = tmpdir_factory.mktemp('data').join('bad.xml').strpath531 junit_xml = "Totally Bogus Content"532 with open(filename, 'w') as f:533 f.write(junit_xml)534 return filename535@pytest.fixture(scope='session')536def bad_junit_root(tmpdir_factory):537 """JUnitXML sample representing XML that is missing all relevant content."""538 filename = tmpdir_factory.mktemp('data').join('bad_junit_root.xml').strpath539 junit_xml = \540 """<?xml version="1.0" encoding="utf-8"?>541 <bad>542 </bad>543 """544 with open(filename, 'w') as f:545 f.write(junit_xml)546 return filename547@pytest.fixture(scope='session')548def missing_testcase_properties_xml(tmpdir_factory, default_global_properties):549 """JUnitXML sample representing a test case that is missing the test case "properties" element."""550 filename = tmpdir_factory.mktemp('data').join('missing_testcase_properties.xml').strpath551 junit_xml = \552 """<?xml version="1.0" encoding="utf-8"?>553 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">554 {global_properties}555 <testcase classname="tests.test_default" file="tests/test_default.py" line="8"556 name="test_pass[ansible://localhost]" time="0.00372695922852"/>557 </testsuite>558 """.format(global_properties=default_global_properties)559 with open(filename, 'w') as f:560 f.write(junit_xml)561 return filename562@pytest.fixture(scope='session')563def missing_test_id_xml(tmpdir_factory, default_global_properties, default_testcase_elements):564 """JUnitXML sample representing a test case that has a missing test id property element."""565 filename = tmpdir_factory.mktemp('data').join('missing_test_id.xml').strpath566 junit_xml = \567 """<?xml version="1.0" encoding="utf-8"?>568 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">569 {global_properties}570 <testcase classname="tests.test_default" file="tests/test_default.py" line="8"571 name="test_pass[ansible://localhost]" time="0.00372695922852"/>572 <properties>573 <property name="start_time" value="2018-04-10T21:38:18Z"/>574 <property name="start_time" value="2018-04-10T21:38:18Z"/>575 <property name="end_time" value="2018-04-10T21:38:19Z"/>576 </properties>577 {testcase_elements}578 </testsuite>579 """.format(global_properties=default_global_properties, testcase_elements=default_testcase_elements)580 with open(filename, 'w') as f:581 f.write(junit_xml)582 return filename583@pytest.fixture(scope='session')584def xml_with_unknown_elements(tmpdir_factory, default_global_properties):585 """JUnitXML sample representing an xml document missing testcases."""586 filename = tmpdir_factory.mktemp('data').join('missing_test_id.xml').strpath587 junit_xml = \588 """<?xml version="1.0" encoding="utf-8"?>589 <testsuitefoo errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">590 {global_properties}591 </testsuitefoo>592 """.format(global_properties=default_global_properties)593 with open(filename, 'w') as f:594 f.write(junit_xml)595 return filename596@pytest.fixture(scope='session')597def missing_build_url_xml(tmpdir_factory, default_testcase_properties, default_testcase_elements):598 """JUnitXML sample representing a test suite that is missing the "BUILD_URL" property."""599 filename = tmpdir_factory.mktemp('data').join('missing_build_url.xml').strpath600 junit_xml = \601 """<?xml version="1.0" encoding="utf-8"?>602 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">603 <properties>604 <property name="BUILD_NUMBER" value="Unknown"/>605 <property name="BUILD_NUMBER" value="Unknown"/>606 <property name="RE_JOB_ACTION" value="Unknown"/>607 <property name="RE_JOB_IMAGE" value="Unknown"/>608 <property name="RE_JOB_SCENARIO" value="Unknown"/>609 <property name="RE_JOB_BRANCH" value="Unknown"/>610 <property name="RPC_RELEASE" value="Unknown"/>611 <property name="RPC_PRODUCT_RELEASE" value="Unknown"/>612 <property name="OS_ARTIFACT_SHA" value="Unknown"/>613 <property name="PYTHON_ARTIFACT_SHA" value="Unknown"/>614 <property name="APT_ARTIFACT_SHA" value="Unknown"/>615 <property name="REPO_URL" value="Unknown"/>616 </properties>617 <testcase classname="tests.test_default" file="tests/test_default.py" line="8"618 name="test_pass[ansible://localhost]" time="0.00372695922852"/>619 {testcase_properties}620 {testcase_elements}621 </testsuite>622 """.format(testcase_properties=default_testcase_properties, testcase_elements=default_testcase_elements)623 with open(filename, 'w') as f:624 f.write(junit_xml)625 return filename626@pytest.fixture(scope='session')627def classname_with_dashes_xml(tmpdir_factory,628 default_global_properties,629 default_testcase_properties,630 default_testcase_elements):631 """JUnitXML sample representing a testcase that has a 'classname' attribute which contains dashes for the py.test632 filename."""633 filename = tmpdir_factory.mktemp('data').join('classname_with_dashes.xml').strpath634 junit_xml = \635 """<?xml version="1.0" encoding="utf-8"?>636 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">637 {global_properties}638 <testcase classname="test.tests.test_for_acs-150.TestForRPC10PlusPostDeploymentQCProcess"639 file="tests/test_for_acs-150.py" line="140"640 name="test_verify_kibana_horizon_access_with_no_ssh[_testinfra_host0]" time="0.00372695922852">641 {testcase_properties}642 {testcase_elements}643 </testcase>644 </testsuite>645 """.format(global_properties=default_global_properties,646 testcase_properties=default_testcase_properties,647 testcase_elements=default_testcase_elements)648 with open(filename, 'w') as f:649 f.write(junit_xml)650 return filename651@pytest.fixture(scope='session')652def invalid_classname_xml(tmpdir_factory,653 default_global_properties,654 default_testcase_properties,655 default_testcase_elements):656 """JUnitXML sample representing a testcase that has an invalid 'classname' attribute which is used to build the657 results hierarchy in the '_generate_module_hierarchy' function."""658 filename = tmpdir_factory.mktemp('data').join('invalid_classname.xml').strpath659 junit_xml = \660 """<?xml version="1.0" encoding="utf-8"?>661 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">662 {global_properties}663 <testcase classname="this is not a valid classname" file="tests/test_default.py" line="8"664 name="test_pass[ansible://localhost]" time="0.00372695922852">665 {testcase_properties}666 {testcase_elements}667 </testcase>668 </testsuite>669 """.format(global_properties=default_global_properties,670 testcase_properties=default_testcase_properties,671 testcase_elements=default_testcase_elements)672 with open(filename, 'w') as f:673 f.write(junit_xml)674 return filename675@pytest.fixture(scope='session')676def test_without_test_step(tmpdir_factory,677 default_global_properties,678 default_testcase_elements):679 """An xml example without test_step property"""680 filename = tmpdir_factory.mktemp('data').join('single_passing.xml').strpath681 junit_xml = \682 """<?xml version="1.0" encoding="utf-8"?>683 <testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">684 {global_properties}685 <testcase classname="tests.test_default" file="tests/test_default.py" line="8"686 name="test_pass[ansible://localhost]" time="0.00372695922852">687 <properties>688 <property name="jira" value="ASC-123"/>689 <property name="jira" value="ASC-456"/>690 <property name="test_id" value="1"/>691 <property name="start_time" value="2018-04-10T21:38:18Z"/>692 <property name="end_time" value="2018-04-10T21:38:19Z"/>693 </properties>694 {testcase_elements}695 </testcase>696 </testsuite>697 """.format(global_properties=default_global_properties,698 testcase_elements=default_testcase_elements)699 with open(filename, 'w') as f:700 f.write(junit_xml)...

Full Screen

Full Screen

test_default_multi_user.py

Source:test_default_multi_user.py Github

copy

Full Screen

1# Copyright 2020 ForgeFlow S.L.2# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).3from odoo.tests import common4import json5class TestDefaultMultiUser(common.SavepointCase):6 @classmethod7 def setUpClass(cls):8 super().setUpClass()9 cls.env = cls.env(10 context=dict(cls.env.context, tracking_disable=True, no_reset_password=True)11 )12 cls.default_model = cls.env["ir.default"]13 cls.user_model = cls.env["res.users"]14 cls.partner_model = cls.env["res.partner"]15 cls.field = cls.env.ref("base.field_res_partner__phone")16 cls.group_user = cls.env.ref("base.group_user")17 cls.group_partner = cls.env.ref("base.group_partner_manager")18 cls.group_private = cls.env["res.groups"].create({19 "name": "Test Group",20 })21 cls.user_1 = cls._create_user("user_1", [22 cls.group_user, cls.group_partner, cls.group_private])23 cls.user_2 = cls._create_user("user_2", [cls.group_user, cls.group_partner])24 cls.user_3 = cls._create_user("user_3", [25 cls.group_user, cls.group_partner, cls.group_private])26 cls.test_value = "+34 666 777 888"27 @classmethod28 def _create_user(self, login, groups):29 group_ids = [group.id for group in groups]30 user = self.user_model.create({31 "name": "Test User",32 "login": login,33 "password": "demo",34 "email": "%s@yourcompany.com" % login,35 "groups_id": [(6, 0, group_ids)]36 })37 return user38 def test_01_no_multi_user(self):39 self.default_model.create({40 "field_id": self.field.id,41 "json_value": json.dumps(self.test_value, ensure_ascii=False),42 "user_id": self.user_1.id,43 })44 rec_1 = self.partner_model.sudo(self.user_1).create({"name": "Test"})45 self.assertEqual(rec_1.phone, self.test_value)46 rec_2 = self.partner_model.sudo(self.user_2).create({"name": "Test"})47 self.assertNotEqual(rec_2.phone, self.test_value)48 def test_02_multi_user(self):49 test_default = self.default_model.create({50 "field_id": self.field.id,51 "json_value": json.dumps(self.test_value, ensure_ascii=False),52 "user_id": self.user_1.id,53 "manual_user_ids": [(6, 0, (self.user_1 + self.user_2).ids)],54 })55 self.assertIn(self.user_1, test_default.user_ids)56 self.assertIn(self.user_2, test_default.user_ids)57 rec_1 = self.partner_model.sudo(self.user_1).create({"name": "Test"})58 self.assertEqual(rec_1.phone, self.test_value)59 rec_2 = self.partner_model.sudo(self.user_2).create({"name": "Test"})60 self.assertEqual(rec_2.phone, self.test_value)61 def test_03_group_default(self):62 # Global default - expected for user 263 global_value = "+01 564 879 123"64 self.default_model.create({65 "field_id": self.field.id,66 "json_value": json.dumps(global_value, ensure_ascii=False),67 })68 # Group specific default - expected for user 1 and 369 test_default = self.default_model.create({70 "field_id": self.field.id,71 "json_value": json.dumps(self.test_value, ensure_ascii=False),72 "group_ids": [(6, 0, self.group_private.ids)],73 })74 self.assertIn(self.user_1, test_default.user_ids)75 self.assertIn(self.user_3, test_default.user_ids)76 rec_1 = self.partner_model.sudo(self.user_1).create({"name": "Test"})77 self.assertEqual(rec_1.phone, self.test_value)78 rec_2 = self.partner_model.sudo(self.user_2).create({"name": "Test"})79 self.assertEqual(rec_2.phone, global_value)80 rec_3 = self.partner_model.sudo(self.user_3).create({"name": "Test"})81 self.assertEqual(rec_3.phone, self.test_value)82 def test_04_multi_user_no_alternative(self):83 test_default = self.default_model.create({84 "field_id": self.field.id,85 "json_value": json.dumps(self.test_value, ensure_ascii=False),86 "manual_user_ids": [(6, 0, self.user_2.ids)],87 })88 self.assertNotIn(self.user_1, test_default.user_ids)89 self.assertIn(self.user_2, test_default.user_ids)90 rec_1 = self.partner_model.sudo(self.user_1).create({"name": "Test"})91 self.assertNotEqual(rec_1.phone, self.test_value)92 rec_2 = self.partner_model.sudo(self.user_2).create({"name": "Test"})...

Full Screen

Full Screen

test_credentials.py

Source:test_credentials.py Github

copy

Full Screen

...23 def test_credentials_unsupported():24 return 'Credentials!'25 @self.app.route('/test_default')26 @cross_origin()27 def test_default():28 return 'Open!'29 def test_credentials_supported(self):30 ''' The specified route should return the31 Access-Control-Allow-Credentials header.32 '''33 resp = self.get('/test_credentials_supported', origin='www.example.com')34 self.assertEquals(resp.headers.get(ACL_CREDENTIALS), 'true')35 resp = self.get('/test_credentials_supported')36 self.assertEquals(resp.headers.get(ACL_CREDENTIALS), None )37 def test_default(self):38 ''' The default behavior should be to disallow credentials.39 '''40 resp = self.get('/test_default', origin='www.example.com')41 self.assertFalse(ACL_CREDENTIALS in resp.headers)42 resp = self.get('/test_default')43 self.assertFalse(ACL_CREDENTIALS in resp.headers)44 def test_credentials_unsupported(self):45 ''' The default behavior should be to disallow credentials.46 '''47 resp = self.get('/test_credentials_unsupported', origin='www.example.com')48 self.assertFalse(ACL_CREDENTIALS in resp.headers)49 resp = self.get('/test_credentials_unsupported')50 self.assertFalse(ACL_CREDENTIALS in resp.headers)51class AppConfigExposeHeadersTestCase(AppConfigTest, SupportsCredentialsCase):52 def __init__(self, *args, **kwargs):53 super(AppConfigExposeHeadersTestCase, self).__init__(*args, **kwargs)54 def test_credentials_supported(self):55 self.app.config['CORS_SUPPORTS_CREDENTIALS'] = True56 @self.app.route('/test_credentials_supported')57 @cross_origin()58 def test_credentials_supported():59 return 'Credentials!'60 super(AppConfigExposeHeadersTestCase, self).test_credentials_supported()61 def test_open_request(self):62 @self.app.route('/test_default')63 @cross_origin()64 def test_default():65 return 'Open!'66 super(AppConfigExposeHeadersTestCase, self).test_default()67if __name__ == "__main__":...

Full Screen

Full Screen

test_expose_headers.py

Source:test_expose_headers.py Github

copy

Full Screen

...12 def setUp(self):13 self.app = Flask(__name__)14 @self.app.route('/test_default')15 @cross_origin()16 def test_default():17 return 'Welcome!'18 @self.app.route('/test_override')19 @cross_origin(expose_headers=["X-My-Custom-Header", "X-Another-Custom-Header"])20 def test_override():21 return 'Welcome!'22 def test_default(self):23 for resp in self.iter_responses('/test_default', origin='www.example.com'):24 self.assertTrue(resp.headers.get(ACL_EXPOSE_HEADERS) is None,25 "No Access-Control-Expose-Headers by default")26 def test_override(self):27 ''' The specified headers should be returned in the ACL_EXPOSE_HEADERS28 and correctly serialized if it is a list.29 '''30 for resp in self.iter_responses('/test_override', origin='www.example.com'):31 self.assertEqual(resp.headers.get(ACL_EXPOSE_HEADERS),32 'X-Another-Custom-Header, X-My-Custom-Header')33class AppConfigExposeHeadersTestCase(AppConfigTest, ExposeHeadersTestCase):34 def __init__(self, *args, **kwargs):35 super(AppConfigExposeHeadersTestCase, self).__init__(*args, **kwargs)36 def test_default(self):37 @self.app.route('/test_default')38 @cross_origin()39 def test_default():40 return 'Welcome!'41 super(AppConfigExposeHeadersTestCase, self).test_default()42 def test_override(self):43 self.app.config['CORS_EXPOSE_HEADERS'] = ["X-My-Custom-Header",44 "X-Another-Custom-Header"]45 @self.app.route('/test_override')46 @cross_origin()47 def test_override():48 return 'Welcome!'49 super(AppConfigExposeHeadersTestCase, self).test_override()50if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful