Best Python code snippet using tempest_python
test_client.py
Source:test_client.py  
...67            aggregates=aggregates)68        mock_update_aggs.assert_called_once_with(69            self.context, aggregates)70    @mock.patch.object(scheduler_rpcapi.SchedulerAPI, 'delete_aggregate')71    def test_delete_aggregate(self, mock_delete_agg):72        aggregate = objects.Aggregate(id=1)73        self.client.delete_aggregate(74            context=self.context,75            aggregate=aggregate)76        mock_delete_agg.assert_called_once_with(77            self.context, aggregate)78class SchedulerClientTestCase(test.NoDBTestCase):79    def setUp(self):80        super(SchedulerClientTestCase, self).setUp()81        self.client = scheduler_client.SchedulerClient()82    def test_constructor(self):83        self.assertIsNotNone(self.client.queryclient)84        self.assertIsNotNone(self.client.reportclient)85    @mock.patch.object(scheduler_query_client.SchedulerQueryClient,86                       'select_destinations')87    def test_select_destinations(self, mock_select_destinations):88        self.assertIsNone(self.client.queryclient.instance)89        self.client.select_destinations('ctxt', 'fake_spec', 'fake_prop')90        self.assertIsNotNone(self.client.queryclient.instance)91        mock_select_destinations.assert_called_once_with(92            'ctxt', 'fake_spec', 'fake_prop')93    @mock.patch.object(scheduler_query_client.SchedulerQueryClient,94                       'select_destinations',95                       side_effect=messaging.MessagingTimeout())96    def test_select_destinations_timeout(self, mock_select_destinations):97        # check if the scheduler service times out properly98        fake_args = ['ctxt', 'fake_spec', 'fake_prop']99        self.assertRaises(messaging.MessagingTimeout,100                          self.client.select_destinations, *fake_args)101        mock_select_destinations.assert_has_calls([mock.call(*fake_args)] * 2)102    @mock.patch.object(scheduler_query_client.SchedulerQueryClient,103                       'select_destinations', side_effect=[104                           messaging.MessagingTimeout(), mock.DEFAULT])105    def test_select_destinations_timeout_once(self, mock_select_destinations):106        # scenario: the scheduler service times out & recovers after failure107        fake_args = ['ctxt', 'fake_spec', 'fake_prop']108        self.client.select_destinations(*fake_args)109        mock_select_destinations.assert_has_calls([mock.call(*fake_args)] * 2)110    @mock.patch.object(scheduler_query_client.SchedulerQueryClient,111                       'update_aggregates')112    def test_update_aggregates(self, mock_update_aggs):113        aggregates = [objects.Aggregate(id=1)]114        self.client.update_aggregates(115            context='context',116            aggregates=aggregates)117        mock_update_aggs.assert_called_once_with(118            'context', aggregates)119    @mock.patch.object(scheduler_query_client.SchedulerQueryClient,120                       'delete_aggregate')121    def test_delete_aggregate(self, mock_delete_agg):122        aggregate = objects.Aggregate(id=1)123        self.client.delete_aggregate(124            context='context',125            aggregate=aggregate)126        mock_delete_agg.assert_called_once_with(127            'context', aggregate)128    @mock.patch.object(scheduler_report_client.SchedulerReportClient,129                       'update_resource_stats')130    def test_update_resource_stats(self, mock_update_resource_stats):131        self.assertIsNone(self.client.reportclient.instance)132        self.client.update_resource_stats(mock.sentinel.cn)133        self.assertIsNotNone(self.client.reportclient.instance)...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!!
