How to use _mock_call method in autotest

Best Python code snippet using autotest_python

dns_schlundtech_test.py

Source:dns_schlundtech_test.py Github

copy

Full Screen

...42 system_ns = "ns1." + DOMAIN43 def setUp(self):44 from certbot_dns_schlundtech.dns_schlundtech import _SchlundtechGatewayClient45 self.gateway_client = _SchlundtechGatewayClient(USER, PASSWORD, CONTEXT, TTL)46 self._mock_call({}) # Safety mock47 def test_auth(self):48 self.assertDictEqual(49 {50 'user': USER,51 'password': PASSWORD,52 'context': CONTEXT53 },54 self.gateway_client._auth()55 )56 def test_zone_info(self):57 self._mock_zone_info('success', {'name': DOMAIN})58 zone = self.gateway_client._zone_info(DOMAIN, self.record_fqdn)59 self.assertDictEqual(zone, {'name': DOMAIN})60 def test_zone_info_domain_missing(self):61 self._mock_zone_info('error')62 self.assertRaises(errors.PluginError, self.gateway_client._zone_info, DOMAIN, self.record_fqdn)63 def test_add_txt_record(self):64 self._mock_zone_info('success', {'name': DOMAIN, 'system_ns': self.system_ns, 'soa': {'level': '1'}}, False)65 self._mock_call({'status': {'type': 'success'}})66 self.gateway_client.add_txt_record(DOMAIN, self.record_name, self.record_content)67 self.gateway_client._call.assert_called_with({68 'code': '0202001',69 'zone': {70 'name': DOMAIN,71 'system_ns': self.system_ns72 },73 'default': {74 'rr_add': {75 'name': self.record_name,76 'type': 'TXT',77 'value': self.record_content,78 'ttl': TTL79 },80 'soa': {'level': '1'}81 }82 })83 def test_add_txt_record_domain_missing(self):84 self._mock_zone_info('error')85 self.assertRaises(errors.PluginError,86 self.gateway_client.add_txt_record, DOMAIN, self.record_name, self.record_content)87 def test_add_txt_record_already_exists(self):88 self._mock_zone_info('success',89 {90 'name': DOMAIN, 'system_ns': self.system_ns, 'soa': {'level': '1'},91 'rr': [{'name': self.record_name, 'value': self.record_name}]92 },93 False)94 self._mock_call({'status': {'type': 'success'}})95 self.gateway_client.add_txt_record(DOMAIN, self.record_name, self.record_content)96 self.gateway_client._call.assert_called_with({97 'code': '0202001',98 'zone': {99 'name': DOMAIN,100 'system_ns': self.system_ns101 },102 'default': {103 'rr_add': {104 'name': self.record_name,105 'type': 'TXT',106 'value': self.record_content,107 'ttl': TTL108 },109 'soa': {'level': '1'}110 }111 })112 def test_add_txt_record_error(self):113 self._mock_zone_info('success', {'name': DOMAIN, 'system_ns': self.system_ns, 'soa': {'level': '1'}}, False)114 self._mock_call({'status': {'type': 'error'}})115 self.assertRaises(errors.PluginError,116 self.gateway_client.add_txt_record, DOMAIN, self.record_name, self.record_content)117 def test_del_txt_record(self):118 self._mock_zone_info('success', {'name': DOMAIN, 'system_ns': self.system_ns, 'soa': {'level': '1'}}, False)119 self._mock_call({'status': {'type': 'success'}})120 self.gateway_client.del_txt_record(DOMAIN, self.record_name, self.record_content)121 self.gateway_client._call.assert_called_with({122 'code': '0202001',123 'zone': {124 'name': DOMAIN,125 'system_ns': self.system_ns126 },127 'default': {128 'rr_rem': {129 'name': self.record_name,130 'type': 'TXT',131 'value': self.record_content,132 'ttl': TTL133 }134 }135 })136 def test_del_txt_record_domain_missing(self):137 self._mock_zone_info('error')138 self.assertRaises(errors.PluginError,139 self.gateway_client.del_txt_record, DOMAIN, self.record_name, self.record_content)140 def test_del_txt_record_error(self):141 self._mock_zone_info('success', {'name': DOMAIN, 'system_ns': self.system_ns, 'soa': {'level': '1'}}, False)142 self._mock_call({'status': {'type': 'error'}})143 self.assertRaises(errors.PluginError,144 self.gateway_client.del_txt_record, DOMAIN, self.record_name, self.record_content)145 def _mock_zone_info(self, status, zone=None, mock_call=True):146 if mock_call:147 self._mock_call({'status': {'type': status}, 'data': {'zone': zone}})148 else:149 # _zone_info | pylint: disable=protected-access150 self.gateway_client._zone_info = mock.MagicMock(return_value=zone)151 def _mock_call(self, return_value):152 # _call | pylint: disable=protected-access153 self.gateway_client._call = mock.MagicMock(return_value=return_value)154class XmlTest(unittest.TestCase):155 tag = 'test'156 data = '<' + tag + '><a>1</a><a>2</a><b>hello</b></' + tag + '>'157 obj = {'a': ['1', '2'], 'b': 'hello'}158 encoding = 'UTF-8'159 def setUp(self):160 from certbot_dns_schlundtech.dns_schlundtech import _XML161 self.xml = _XML()162 def test_fromstring(self):163 r = self.xml.fromstring(self.data)164 self.assertDictEqual(self.obj, r)165 def test_tostring(self):...

Full Screen

Full Screen

test_parser.py

Source:test_parser.py Github

copy

Full Screen

1##############################################################################2# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.3#4# All rights reserved. This program and the accompanying materials5# are made available under the terms of the Apache License, Version 2.06# which accompanies this distribution, and is available at7# http://www.apache.org/licenses/LICENSE-2.08##############################################################################9import subprocess10import unittest11import mock12from oslo_serialization import jsonutils13from yardstick.benchmark.scenarios.parser import parser14class ParserTestCase(unittest.TestCase):15 def setUp(self):16 args = {17 'options': {'yangfile': '/root/yardstick/samples/yang.yaml',18 'toscafile': '/root/yardstick/samples/tosca.yaml'},19 }20 self.scenario = parser.Parser(scenario_cfg=args, context_cfg={})21 self._mock_popen = mock.patch.object(subprocess, 'Popen')22 self.mock_popen = self._mock_popen.start()23 self._mock_call = mock.patch.object(subprocess, 'call')24 self.mock_call = self._mock_call.start()25 self.addCleanup(self._stop_mock)26 def _stop_mock(self):27 self._mock_popen.stop()28 self._mock_call.stop()29 def test_setup_successful(self):30 self.mock_call.return_value = 031 self.scenario.setup()32 self.assertTrue(self.scenario.setup_done)33 def test_run_successful(self):34 result = {}35 self.mock_popen().returncode = 036 expected_result = jsonutils.loads('{"yangtotosca": "success"}')37 self.scenario.run(result)38 self.assertEqual(result, expected_result)39 def test_run_fail(self):40 result = {}41 self.mock_popen().returncode = 142 expected_result = jsonutils.loads('{"yangtotosca": "fail"}')43 self.scenario.run(result)44 self.assertEqual(result, expected_result)45 def test_teardown_successful(self):46 self.mock_call.return_value = 047 self.scenario.teardown()...

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

2from unittest.mock import patch3import pytest4from surepy import MESTART_RESOURCE5from . import MOCK_API_DATA6async def _mock_call(method, resource):7 if method == "GET" and resource == MESTART_RESOURCE:8 return {"data": MOCK_API_DATA}9@pytest.fixture10async def surepetcare():11 """Mock the SurePetcare for easier testing."""12 with patch("surepy.SureAPIClient", autospec=True) as mock_client_class:13 client = mock_client_class.return_value14 client.resources = {}15 client.call = _mock_call16 client.get_token.return_value = "token"...

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 autotest 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