Best Python code snippet using avocado_python
test_services.py
Source:test_services.py
...8import dsmr_backend.services9class TestServices(InterceptStdoutMixin, TestCase):10 support_gas_readings = None11 def test_data_capabilities(self):12 capabilities = dsmr_backend.services.get_capabilities()13 self.assertIn('electricity', capabilities.keys())14 self.assertIn('electricity_returned', capabilities.keys())15 self.assertIn('gas', capabilities.keys())16 self.assertIn('weather', capabilities.keys())17 self.assertIn('any', capabilities.keys())18 def test_empty_capabilities(self):19 """ Capability check for empty database. """20 capabilities = dsmr_backend.services.get_capabilities()21 self.assertFalse(WeatherSettings.get_solo().track)22 self.assertFalse(capabilities['electricity'])23 self.assertFalse(capabilities['electricity_returned'])24 self.assertFalse(capabilities['gas'])25 self.assertFalse(capabilities['multi_phases'])26 self.assertFalse(capabilities['weather'])27 self.assertFalse(capabilities['any'])28 self.assertFalse(dsmr_backend.services.get_capabilities('electricity'))29 self.assertFalse(dsmr_backend.services.get_capabilities('electricity_returned'))30 self.assertFalse(dsmr_backend.services.get_capabilities('gas'))31 self.assertFalse(dsmr_backend.services.get_capabilities('multi_phases'))32 self.assertFalse(dsmr_backend.services.get_capabilities('weather'))33 self.assertFalse(dsmr_backend.services.get_capabilities('any'))34 def test_electricity_capabilities(self):35 """ Capability check for electricity consumption. """36 capabilities = dsmr_backend.services.get_capabilities()37 self.assertFalse(capabilities['electricity'])38 self.assertFalse(capabilities['any'])39 ElectricityConsumption.objects.create(40 read_at=timezone.now(),41 delivered_1=0,42 returned_1=0,43 delivered_2=0,44 returned_2=0,45 currently_delivered=0,46 currently_returned=0,47 )48 capabilities = dsmr_backend.services.get_capabilities()49 self.assertTrue(dsmr_backend.services.get_capabilities('electricity'))50 self.assertTrue(capabilities['electricity'])51 self.assertTrue(capabilities['any'])52 def test_multi_phases_capabilities(self):53 """ Capability check for multiple phases. """54 capabilities = dsmr_backend.services.get_capabilities()55 self.assertFalse(capabilities['multi_phases'])56 self.assertFalse(capabilities['any'])57 ElectricityConsumption.objects.create(58 read_at=timezone.now(),59 delivered_1=0,60 returned_1=0,61 delivered_2=0,62 returned_2=0,63 currently_delivered=0,64 currently_returned=0,65 phase_currently_delivered_l1=1,66 )67 # Should fail.68 self.assertFalse(dsmr_backend.services.get_capabilities('multi_phases'))69 ElectricityConsumption.objects.create(70 read_at=timezone.now() + timezone.timedelta(minutes=1),71 delivered_1=0,72 returned_1=0,73 delivered_2=0,74 returned_2=0,75 currently_delivered=0,76 currently_returned=0,77 phase_currently_delivered_l2=1,78 phase_currently_delivered_l3=1,79 )80 capabilities = dsmr_backend.services.get_capabilities()81 self.assertTrue(dsmr_backend.services.get_capabilities('multi_phases'))82 self.assertTrue(capabilities['multi_phases'])83 self.assertTrue(capabilities['any'])84 def test_electricity_returned_capabilities(self):85 """ Capability check for electricity returned. """86 capabilities = dsmr_backend.services.get_capabilities()87 self.assertFalse(capabilities['electricity_returned'])88 self.assertFalse(capabilities['any'])89 # Should not have any affect.90 consumption = ElectricityConsumption.objects.create(91 read_at=timezone.now(),92 delivered_1=0,93 returned_1=0,94 delivered_2=0,95 returned_2=0,96 currently_delivered=0,97 currently_returned=0,98 )99 capabilities = dsmr_backend.services.get_capabilities()100 self.assertFalse(capabilities['electricity_returned'])101 consumption.currently_returned = 0.001102 consumption.save(update_fields=['currently_returned'])103 capabilities = dsmr_backend.services.get_capabilities()104 self.assertTrue(dsmr_backend.services.get_capabilities('electricity_returned'))105 self.assertTrue(capabilities['electricity_returned'])106 self.assertTrue(capabilities['any'])107 def test_gas_capabilities(self):108 """ Capability check for gas consumption. """109 capabilities = dsmr_backend.services.get_capabilities()110 self.assertFalse(capabilities['gas'])111 self.assertFalse(capabilities['any'])112 GasConsumption.objects.create(113 read_at=timezone.now(),114 delivered=0,115 currently_delivered=0,116 )117 capabilities = dsmr_backend.services.get_capabilities()118 self.assertTrue(dsmr_backend.services.get_capabilities('gas'))119 self.assertTrue(capabilities['gas'])120 self.assertTrue(capabilities['any'])121 def test_weather_capabilities(self):122 """ Capability check for gas consumption. """123 weather_settings = WeatherSettings.get_solo()124 self.assertFalse(weather_settings.track)125 self.assertFalse(TemperatureReading.objects.exists())126 capabilities = dsmr_backend.services.get_capabilities()127 self.assertFalse(capabilities['weather'])128 self.assertFalse(capabilities['any'])129 # Should not have any affect.130 weather_settings.track = True131 weather_settings.save(update_fields=['track'])132 self.assertTrue(WeatherSettings.get_solo().track)133 capabilities = dsmr_backend.services.get_capabilities()134 self.assertFalse(capabilities['weather'])135 TemperatureReading.objects.create(read_at=timezone.now(), degrees_celcius=0.0)136 capabilities = dsmr_backend.services.get_capabilities()137 self.assertTrue(dsmr_backend.services.get_capabilities('weather'))138 self.assertTrue(capabilities['weather'])139 self.assertTrue(capabilities['any'])140@mock.patch('requests.get')141class TestIslatestVersion(TestCase):142 response_older = b"from django.utils.version import get_version\n" \143 b"VERSION = (1, 2, 0, 'final', 0)\n" \144 b"__version__ = get_version(VERSION)\n"145 response_newer = b"from django.utils.version import get_version\n" \146 b"VERSION = (1, 25, 1, 'final', 0)\n" \147 b"__version__ = get_version(VERSION)\n"148 def test_true(self, request_mock):149 response_mock = mock.MagicMock(content=self.response_older)150 request_mock.return_value = response_mock151 self.assertTrue(dsmr_backend.services.is_latest_version())...
test_zapper_proxy.py
Source:test_zapper_proxy.py
...74 ret_val = [{'foo': 'bar'}]75 self._mocked_conn.root.get_capabilities = Mock(return_value=ret_val)76 zapctl = ZapperControlV1(self._mocked_conn)77 with patch('builtins.print') as mocked_print:78 zapctl.get_capabilities()79 mocked_print.assert_called_once_with('foo: bar')80 def test_get_capabilities_empty(self):81 """Check if get_capabilities prints nothing on no capabilities."""82 ret_val = []83 self._mocked_conn.root.get_capabilities = Mock(return_value=ret_val)84 zapctl = ZapperControlV1(self._mocked_conn)85 with patch('builtins.print') as mocked_print:86 zapctl.get_capabilities()87 mocked_print.assert_called_once_with('')88 def test_get_capabilities_multiple_caps(self):89 """90 Check if get_capabilities properly prints multiple records.91 The records should be in Checkbox resource syntax. Records should be92 separated by an empty line.93 """94 ret_val = [{'foo': 'bar'}, {'baz': 'biz'}]95 self._mocked_conn.root.get_capabilities = Mock(return_value=ret_val)96 zapctl = ZapperControlV1(self._mocked_conn)97 with patch('builtins.print') as mocked_print:98 zapctl.get_capabilities()99 mocked_print.assert_called_once_with('foo: bar\n\nbaz: biz')100 def test_get_capabilities_one_cap_multi_rows(self):101 """102 Check if get_capabilities properly prints a record with multiple caps.103 Each capability should be printed in a separate line.104 No additional newlines should be printed.105 """106 ret_val = [{'foo': 'bar', 'foo2': 'bar2'}]107 self._mocked_conn.root.get_capabilities = Mock(return_value=ret_val)108 zapctl = ZapperControlV1(self._mocked_conn)109 with patch('builtins.print') as mocked_print:110 zapctl.get_capabilities()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!