Best Python code snippet using tempest_python
test_account_services.py
Source:test_account_services.py  
...38        # list of all containers should not be empty39        params = {'format': 'json'}40        resp, container_list = \41            self.account_client.list_account_containers(params=params)42        self.assertHeaders(resp, 'Account', 'GET')43        self.assertIsNotNone(container_list)44        container_names = [c['name'] for c in container_list]45        for container_name in self.containers:46            self.assertIn(container_name, container_names)47    @attr(type='smoke')48    def test_list_containers_with_limit(self):49        # list containers one of them, half of them then all of them50        for limit in (1, self.containers_count / 2, self.containers_count):51            params = {'limit': limit}52            resp, container_list = \53                self.account_client.list_account_containers(params=params)54            self.assertHeaders(resp, 'Account', 'GET')55            self.assertEqual(len(container_list), limit)56    @attr(type='smoke')57    def test_list_containers_with_marker(self):58        # list containers using marker param59        # first expect to get 0 container as we specified last60        # the container as marker61        # second expect to get the bottom half of the containers62        params = {'marker': self.containers[-1]}63        resp, container_list = \64            self.account_client.list_account_containers(params=params)65        self.assertHeaders(resp, 'Account', 'GET')66        self.assertEqual(len(container_list), 0)67        params = {'marker': self.containers[self.containers_count / 2]}68        resp, container_list = \69            self.account_client.list_account_containers(params=params)70        self.assertHeaders(resp, 'Account', 'GET')71        self.assertEqual(len(container_list), self.containers_count / 2 - 1)72    @attr(type='smoke')73    def test_list_containers_with_end_marker(self):74        # list containers using end_marker param75        # first expect to get 0 container as we specified first container as76        # end_marker77        # second expect to get the top half of the containers78        params = {'end_marker': self.containers[0]}79        resp, container_list = \80            self.account_client.list_account_containers(params=params)81        self.assertHeaders(resp, 'Account', 'GET')82        self.assertEqual(len(container_list), 0)83        params = {'end_marker': self.containers[self.containers_count / 2]}84        resp, container_list = \85            self.account_client.list_account_containers(params=params)86        self.assertHeaders(resp, 'Account', 'GET')87        self.assertEqual(len(container_list), self.containers_count / 2)88    @attr(type='smoke')89    def test_list_containers_with_limit_and_marker(self):90        # list containers combining marker and limit param91        # result are always limitated by the limit whatever the marker92        for marker in random.choice(self.containers):93            limit = random.randint(0, self.containers_count - 1)94            params = {'marker': marker,95                      'limit': limit}96            resp, container_list = \97                self.account_client.list_account_containers(params=params)98            self.assertHeaders(resp, 'Account', 'GET')99            self.assertTrue(len(container_list) <= limit, str(container_list))100    @attr(type='smoke')101    def test_list_account_metadata(self):102        # list all account metadata103        resp, metadata = self.account_client.list_account_metadata()104        self.assertIn(int(resp['status']), HTTP_SUCCESS)105        self.assertHeaders(resp, 'Account', 'HEAD')106    @attr(type='smoke')107    def test_create_and_delete_account_metadata(self):108        header = 'test-account-meta'109        data = 'Meta!'110        # add metadata to account111        resp, _ = self.account_client.create_account_metadata(112            metadata={header: data})113        self.assertIn(int(resp['status']), HTTP_SUCCESS)114        self.assertHeaders(resp, 'Account', 'POST')115        resp, _ = self.account_client.list_account_metadata()116        self.assertHeaders(resp, 'Account', 'HEAD')117        self.assertIn('x-account-meta-' + header, resp)118        self.assertEqual(resp['x-account-meta-' + header], data)119        # delete metadata from account120        resp, _ = \121            self.account_client.delete_account_metadata(metadata=[header])122        self.assertIn(int(resp['status']), HTTP_SUCCESS)123        self.assertHeaders(resp, 'Account', 'POST')124        resp, _ = self.account_client.list_account_metadata()125        self.assertHeaders(resp, 'Account', 'HEAD')126        self.assertNotIn('x-account-meta-' + header, resp)127    @attr(type=['negative', 'gate'])128    def test_list_containers_with_non_authorized_user(self):129        # list containers using non-authorized user130        # create user131        self.data.setup_test_user()132        resp, body = \133            self.token_client.auth(self.data.test_user,134                                   self.data.test_password,135                                   self.data.test_tenant)136        new_token = \137            self.token_client.get_token(self.data.test_user,138                                        self.data.test_password,139                                        self.data.test_tenant)...test_assertHeaders.py
Source:test_assertHeaders.py  
...29        headers = {**baseHeaders}30        headers.pop("strict-transport-security")31        schema = {**baseSchema}32        with self.assertRaises(HeaderAssertionError):33            assertHeaders(headers, schema)34    def test_passes_on_presence_of_required_header(self):35        headers = {36          **baseHeaders,37          "strict-transport-security": "abcd"38        }39        schema = {**baseSchema}40        # shouldn't throw41        assertHeaders(headers, schema)42    def test_errs_on_presence_of_excluded_header(self):43        headers = {44          **baseHeaders,45          "cache-control": "abcd"46        }47        schema = {**baseSchema}48        with self.assertRaises(HeaderAssertionError):49            assertHeaders(headers, schema)50    def test_passes_on_missing_excluded_header(self):51        headers = {**baseHeaders}52        self.assertFalse(hasattr(headers, "cache-control"))53        schema = {**baseSchema}54        # shouldn't throw55        assertHeaders(headers, schema)56    def test_errs_for_presence_of_disallowed_header_value(self):57        headers = {58          **baseHeaders,59          "x-frame-options": "SAMEORIGIN"60        }61        schema = {**baseSchema}62        with self.assertRaises(HeaderAssertionError):63            assertHeaders(headers, schema)64    def test_errs_for_presence_of_missing_header_value(self):65        headers = {66          **baseHeaders,67          "x-frame-options": "ALLOW-FROM eaxmple.com"68        }69        schema = {**baseSchema}70        with self.assertRaises(HeaderAssertionError):71            assertHeaders(headers, schema)72    def test_passes_for_allowed_header_value(self):73        headers = {74          **baseHeaders,75          "x-frame-options": "DENY"76        }77        schema = {**baseSchema}78        # shouldn't throw79        assertHeaders(headers, schema)80    def test_reports_multiple_errors(self):81        headers = {82          **baseHeaders,83          "cache-control": "abcd",84          "x-content-type-options": "abcd",85          "x-frame-options": "SAMEORIGIN"86        }87        headers.pop("strict-transport-security")88        schema = {**baseSchema}89        try:90            assertHeaders(headers, schema)91            self.assertTrue(False) # Should not get reached92        except HeaderAssertionError as headerAssertionError:93            self.assertEqual(len(headerAssertionError.errors), 4)94            for err in headerAssertionError.errors:95                self.assertTrue("type" in err)96                self.assertTrue("headerName" in err)...test_requests.py
Source:test_requests.py  
...3from .helper import DashboardTestCase4class RequestsTest(DashboardTestCase):5    def test_gzip(self):6        self._get('/api/summary')7        self.assertHeaders({8            'Content-Encoding': 'gzip',9            'Content-Type': 'application/json',10        })11    def test_force_no_gzip(self):12        self._get('/api/summary', params=dict(13            headers={'Accept-Encoding': 'identity'}14        ))15        self.assertNotIn('Content-Encoding', self._resp.headers)16        self.assertHeaders({17            'Content-Type': 'application/json',18        })19    def test_server(self):20        self._get('/api/summary')21        self.assertHeaders({22            'server': 'Ceph-Dashboard'...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!!
