Best Python code snippet using tempest_python
test_quotas.py
Source:test_quotas.py  
...35        self.assertGreater(int(quotas["shares"]), -2)36        self.assertGreater(int(quotas["snapshots"]), -2)37        self.assertGreater(int(quotas["share_networks"]), -2)38    @test.attr(type=["gate", "smoke", ])39    def test_show_quotas(self):40        quotas = self.shares_v2_client.show_quotas(self.tenant_id)41        self.assertGreater(int(quotas["gigabytes"]), -2)42        self.assertGreater(int(quotas["snapshot_gigabytes"]), -2)43        self.assertGreater(int(quotas["shares"]), -2)44        self.assertGreater(int(quotas["snapshots"]), -2)45        self.assertGreater(int(quotas["share_networks"]), -2)46    @test.attr(type=["gate", "smoke", ])47    def test_show_quotas_for_user(self):48        quotas = self.shares_v2_client.show_quotas(49            self.tenant_id, self.user_id)50        self.assertGreater(int(quotas["gigabytes"]), -2)51        self.assertGreater(int(quotas["snapshot_gigabytes"]), -2)52        self.assertGreater(int(quotas["shares"]), -2)53        self.assertGreater(int(quotas["snapshots"]), -2)54        self.assertGreater(int(quotas["share_networks"]), -2)55class SharesAdminQuotasUpdateTest(base.BaseSharesAdminTest):56    force_tenant_isolation = True57    client_version = '2'58    @classmethod59    def resource_setup(cls):60        if not CONF.share.run_quota_tests:61            msg = "Quota tests are disabled."62            raise cls.skipException(msg)63        cls.os = clients.AdminManager()64        super(SharesAdminQuotasUpdateTest, cls).resource_setup()65    def setUp(self):66        super(self.__class__, self).setUp()67        self.client = self.get_client_with_isolated_creds(68            client_version=self.client_version)69        self.tenant_id = self.client.tenant_id70        self.user_id = self.client.user_id71    @test.attr(type=["gate", "smoke", ])72    def test_update_tenant_quota_shares(self):73        # get current quotas74        quotas = self.client.show_quotas(self.tenant_id)75        new_quota = int(quotas["shares"]) + 276        # set new quota for shares77        updated = self.client.update_quotas(self.tenant_id, shares=new_quota)78        self.assertEqual(new_quota, int(updated["shares"]))79    @test.attr(type=["gate", "smoke", ])80    def test_update_user_quota_shares(self):81        # get current quotas82        quotas = self.client.show_quotas(self.tenant_id, self.user_id)83        new_quota = int(quotas["shares"]) - 184        # set new quota for shares85        updated = self.client.update_quotas(86            self.tenant_id, self.user_id, shares=new_quota)87        self.assertEqual(new_quota, int(updated["shares"]))88    @test.attr(type=["gate", "smoke", ])89    def test_update_tenant_quota_snapshots(self):90        # get current quotas91        quotas = self.client.show_quotas(self.tenant_id)92        new_quota = int(quotas["snapshots"]) + 293        # set new quota for snapshots94        updated = self.client.update_quotas(95            self.tenant_id, snapshots=new_quota)96        self.assertEqual(new_quota, int(updated["snapshots"]))97    @test.attr(type=["gate", "smoke", ])98    def test_update_user_quota_snapshots(self):99        # get current quotas100        quotas = self.client.show_quotas(self.tenant_id, self.user_id)101        new_quota = int(quotas["snapshots"]) - 1102        # set new quota for snapshots103        updated = self.client.update_quotas(104            self.tenant_id, self.user_id, snapshots=new_quota)105        self.assertEqual(new_quota, int(updated["snapshots"]))106    @test.attr(type=["gate", "smoke", ])107    def test_update_tenant_quota_gigabytes(self):108        # get current quotas109        custom = self.client.show_quotas(self.tenant_id)110        # make quotas for update111        gigabytes = int(custom["gigabytes"]) + 2112        # set new quota for shares113        updated = self.client.update_quotas(114            self.tenant_id, gigabytes=gigabytes)115        self.assertEqual(gigabytes, int(updated["gigabytes"]))116    @test.attr(type=["gate", "smoke", ])117    def test_update_tenant_quota_snapshot_gigabytes(self):118        # get current quotas119        custom = self.client.show_quotas(self.tenant_id)120        # make quotas for update121        snapshot_gigabytes = int(custom["snapshot_gigabytes"]) + 2122        # set new quota for shares123        updated = self.client.update_quotas(124            self.tenant_id,125            snapshot_gigabytes=snapshot_gigabytes)126        self.assertEqual(snapshot_gigabytes,127                         int(updated["snapshot_gigabytes"]))128    @test.attr(type=["gate", "smoke", ])129    def test_update_user_quota_gigabytes(self):130        # get current quotas131        custom = self.client.show_quotas(self.tenant_id, self.user_id)132        # make quotas for update133        gigabytes = int(custom["gigabytes"]) - 1134        # set new quota for shares135        updated = self.client.update_quotas(136            self.tenant_id, self.user_id, gigabytes=gigabytes)137        self.assertEqual(gigabytes, int(updated["gigabytes"]))138    @test.attr(type=["gate", "smoke", ])139    def test_update_user_quota_snapshot_gigabytes(self):140        # get current quotas141        custom = self.client.show_quotas(self.tenant_id, self.user_id)142        # make quotas for update143        snapshot_gigabytes = int(custom["snapshot_gigabytes"]) - 1144        # set new quota for shares145        updated = self.client.update_quotas(146            self.tenant_id, self.user_id,147            snapshot_gigabytes=snapshot_gigabytes)148        self.assertEqual(snapshot_gigabytes,149                         int(updated["snapshot_gigabytes"]))150    @test.attr(type=["gate", "smoke", ])151    def test_update_tenant_quota_share_networks(self):152        # get current quotas153        quotas = self.client.show_quotas(self.tenant_id)154        new_quota = int(quotas["share_networks"]) + 2155        # set new quota for share-networks156        updated = self.client.update_quotas(157            self.tenant_id, share_networks=new_quota)158        self.assertEqual(new_quota, int(updated["share_networks"]))159    @test.attr(type=["gate", "smoke", ])160    def test_update_user_quota_share_networks(self):161        # get current quotas162        quotas = self.client.show_quotas(163            self.tenant_id, self.user_id)164        new_quota = int(quotas["share_networks"]) - 1165        # set new quota for share-networks166        updated = self.client.update_quotas(167            self.tenant_id, self.user_id,168            share_networks=new_quota)169        self.assertEqual(new_quota, int(updated["share_networks"]))170    @test.attr(type=["gate", "smoke", ])171    def test_reset_tenant_quotas(self):172        # get default_quotas173        default = self.client.default_quotas(self.tenant_id)174        # get current quotas175        custom = self.client.show_quotas(self.tenant_id)176        # make quotas for update177        shares = int(custom["shares"]) + 2178        snapshots = int(custom["snapshots"]) + 2179        gigabytes = int(custom["gigabytes"]) + 2180        snapshot_gigabytes = int(custom["snapshot_gigabytes"]) + 2181        share_networks = int(custom["share_networks"]) + 2182        # set new quota183        updated = self.client.update_quotas(184            self.tenant_id,185            shares=shares,186            snapshots=snapshots,187            gigabytes=gigabytes,188            snapshot_gigabytes=snapshot_gigabytes,189            share_networks=share_networks)190        self.assertEqual(shares, int(updated["shares"]))191        self.assertEqual(snapshots, int(updated["snapshots"]))192        self.assertEqual(gigabytes, int(updated["gigabytes"]))193        self.assertEqual(snapshot_gigabytes,194                         int(updated["snapshot_gigabytes"]))195        self.assertEqual(share_networks, int(updated["share_networks"]))196        # reset customized quotas197        self.client.reset_quotas(self.tenant_id)198        # verify quotas199        reseted = self.client.show_quotas(self.tenant_id)200        self.assertEqual(int(default["shares"]), int(reseted["shares"]))201        self.assertEqual(int(default["snapshots"]), int(reseted["snapshots"]))202        self.assertEqual(int(default["gigabytes"]), int(reseted["gigabytes"]))203        self.assertEqual(int(default["share_networks"]),204                         int(reseted["share_networks"]))205    @test.attr(type=["gate", "smoke", ])206    def test_unlimited_quota_for_shares(self):207        self.client.update_quotas(self.tenant_id, shares=-1)208        quotas = self.client.show_quotas(self.tenant_id)209        self.assertEqual(-1, quotas.get('shares'))210    @test.attr(type=["gate", "smoke", ])211    def test_unlimited_user_quota_for_shares(self):212        self.client.update_quotas(213            self.tenant_id, self.user_id, shares=-1)214        quotas = self.client.show_quotas(self.tenant_id, self.user_id)215        self.assertEqual(-1, quotas.get('shares'))216    @test.attr(type=["gate", "smoke", ])217    def test_unlimited_quota_for_snapshots(self):218        self.client.update_quotas(self.tenant_id, snapshots=-1)219        quotas = self.client.show_quotas(self.tenant_id)220        self.assertEqual(-1, quotas.get('snapshots'))221    @test.attr(type=["gate", "smoke", ])222    def test_unlimited_user_quota_for_snapshots(self):223        self.client.update_quotas(224            self.tenant_id, self.user_id, snapshots=-1)225        quotas = self.client.show_quotas(self.tenant_id, self.user_id)226        self.assertEqual(-1, quotas.get('snapshots'))227    @test.attr(type=["gate", "smoke", ])228    def test_unlimited_quota_for_gigabytes(self):229        self.client.update_quotas(self.tenant_id, gigabytes=-1)230        quotas = self.client.show_quotas(self.tenant_id)231        self.assertEqual(-1, quotas.get('gigabytes'))232    @test.attr(type=["gate", "smoke", ])233    def test_unlimited_quota_for_snapshot_gigabytes(self):234        self.client.update_quotas(235            self.tenant_id, snapshot_gigabytes=-1)236        quotas = self.client.show_quotas(self.tenant_id)237        self.assertEqual(-1, quotas.get('snapshot_gigabytes'))238    @test.attr(type=["gate", "smoke", ])239    def test_unlimited_user_quota_for_gigabytes(self):240        self.client.update_quotas(241            self.tenant_id, self.user_id, gigabytes=-1)242        quotas = self.client.show_quotas(self.tenant_id, self.user_id)243        self.assertEqual(-1, quotas.get('gigabytes'))244    @test.attr(type=["gate", "smoke", ])245    def test_unlimited_user_quota_for_snapshot_gigabytes(self):246        self.client.update_quotas(247            self.tenant_id, self.user_id, snapshot_gigabytes=-1)248        quotas = self.client.show_quotas(self.tenant_id, self.user_id)249        self.assertEqual(-1, quotas.get('snapshot_gigabytes'))250    @test.attr(type=["gate", "smoke", ])251    def test_unlimited_quota_for_share_networks(self):252        self.client.update_quotas(self.tenant_id, share_networks=-1)253        quotas = self.client.show_quotas(self.tenant_id)254        self.assertEqual(-1, quotas.get('share_networks'))255    @test.attr(type=["gate", "smoke", ])256    def test_unlimited_user_quota_for_share_networks(self):257        self.client.update_quotas(258            self.tenant_id, self.user_id, share_networks=-1)259        quotas = self.client.show_quotas(self.tenant_id, self.user_id)...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!!
