def test_hybridconnetion_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        #Create a Namespace
        namespace_name = "testingpythontestcasenamespacehybridconnection"

        namespaceparameter = RelayNamespace(location=location, tags={'tag1': 'value1', 'tag2': 'value2'}, sku=Sku(tier=SkuTier.standard))
        creatednamespace = self.relay_client.namespaces.create_or_update(resource_group_name, namespace_name, namespaceparameter).result()
        self.assertEqual(creatednamespace.name, namespace_name)

        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.relay_client.namespaces.get(resource_group_name, namespace_name)
        self.assertEqual(getnamespaceresponse.name, namespace_name)

        # Create a HybridConnection
        hybridconnection_name = "testingpythontestcasehybridconnection"

        createdhybridconnectionresponse = self.relay_client.hybrid_connections.create_or_update(resource_group_name, namespace_name, hybridconnection_name, True, "User data for HybridConnection")

        self.assertEqual(createdhybridconnectionresponse.name, hybridconnection_name)
        self.assertEqual(createdhybridconnectionresponse.requires_client_authorization, True)

        #Get the created Hybridconnection
        gethybridconnectionresponse = self.relay_client.hybrid_connections.get(resource_group_name, namespace_name, hybridconnection_name)
        self.assertEqual(gethybridconnectionresponse.name, hybridconnection_name)
        self.assertEqual(gethybridconnectionresponse.user_metadata, "User data for HybridConnection")

        #Get the List of Hybridconnection by namespaces
        getlistbynamespacehybridconnectionresponse = list(self.relay_client.hybrid_connections.list_by_namespace(resource_group_name, namespace_name))
        self.assertGreater(len(getlistbynamespacehybridconnectionresponse), 0)

        updatehybridconnectionresponse = self.relay_client.hybrid_connections.create_or_update(resource_group_name, namespace_name, hybridconnection_name, None, "User data for HybridConnection updated")

        self.assertEqual(updatehybridconnectionresponse.name, hybridconnection_name)
        self.assertEqual(updatehybridconnectionresponse.requires_client_authorization, True)
        self.assertEqual(updatehybridconnectionresponse.user_metadata, "User data for HybridConnection updated")

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createhybridconnectionauthorule = self.relay_client.hybrid_connections.create_or_update_authorization_rule(resource_group_name, namespace_name, hybridconnection_name, authoRule_name,[AccessRights('Send'),AccessRights('Listen')])
        self.assertEqual(createhybridconnectionauthorule.name, authoRule_name, "Authorization rule name not as created - create_or_update_authorization_rule ")
        self.assertEqual(len(createhybridconnectionauthorule.rights), 2)

        # Get the created authorizationrule
        gethybridconnectionauthorule = self.relay_client.hybrid_connections.get_authorization_rule(resource_group_name, namespace_name, hybridconnection_name, authoRule_name)
        self.assertEqual(gethybridconnectionauthorule.name, authoRule_name, "Authorization rule name not as passed as parameter - get_authorization_rule ")
        self.assertEqual(len(gethybridconnectionauthorule.rights), 2, "Access rights mis match as created  - get_authorization_rule ")

        # update the rights of the authorizatiorule
        gethybridconnectionauthorule.rights.append('Manage')
        updatehybridconnectionauthorule = self.relay_client.hybrid_connections.create_or_update_authorization_rule(resource_group_name, namespace_name, hybridconnection_name, authoRule_name, gethybridconnectionauthorule.rights)
        self.assertEqual(updatehybridconnectionauthorule.name, authoRule_name, "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule ")
        self.assertEqual(len(updatehybridconnectionauthorule.rights), 3, "Access rights mis match as updated  - create_or_update_authorization_rule ")

        #list all the authorization ruels for the given namespace
        hybridconnectionauthorulelist = list(self.relay_client.hybrid_connections.list_authorization_rules(resource_group_name, namespace_name, hybridconnection_name))
        self.assertEqual(len(hybridconnectionauthorulelist), 1, "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules")

        #List keys for the authorization rule
        listkeysauthorizationrule = self.relay_client.hybrid_connections.list_keys(resource_group_name, namespace_name, hybridconnection_name, authoRule_name)
        self.assertIsNotNone(listkeysauthorizationrule)

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.relay_client.hybrid_connections.regenerate_keys(resource_group_name, namespace_name, hybridconnection_name, authoRule_name, 'PrimaryKey')
        self.assertNotEqual(listkeysauthorizationrule.primary_key,regenratePrimarykeyauthorizationrule.primary_key)

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.relay_client.hybrid_connections.regenerate_keys(resource_group_name,namespace_name, hybridconnection_name, authoRule_name, 'SecondaryKey')
        self.assertNotEqual(listkeysauthorizationrule.secondary_key, regenrateSecondarykeyauthorizationrule.secondary_key)

        # delete the authorizationrule
        self.relay_client.hybrid_connections.delete_authorization_rule(resource_group_name, namespace_name, hybridconnection_name, authoRule_name)

        # Delete the created HybridConnection
        gethybridconnectionresponse = self.relay_client.hybrid_connections.delete(resource_group_name, namespace_name, hybridconnection_name)

        # Delete the create namespace
        self.relay_client.namespaces.delete(resource_group_name, namespace_name).result()
Example #2
0
    def test_relay_namespace_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        # Create a Namespace
        namespace_name = "testingpythontestcasenamespace"
        namespaceparameter = RelayNamespace(location=location,
                                            tags={
                                                'tag1': 'value1',
                                                'tag2': 'value2'
                                            },
                                            sku=Sku(tier=SkuTier.standard))
        creatednamespace = self.relay_client.namespaces.create_or_update(
            resource_group_name, namespace_name, namespaceparameter).result()
        self.assertEqual(creatednamespace.name, namespace_name)
        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.relay_client.namespaces.get(
            resource_group_name, namespace_name)
        self.assertEqual(getnamespaceresponse.name, namespace_name)

        # Update a Namespace
        namespaceparameter = {'tags': {'tag1': 'value1', 'tag2': 'value2'}}
        updatenamespace = self.relay_client.namespaces.update(
            resource_group_name, namespace_name, namespaceparameter)

        # Get the List of Namespaces under the resourceGroup - list_by_resource_group
        listbyresourcegroupresponse = list(
            self.relay_client.namespaces.list_by_resource_group(
                resource_group_name, False, False))
        self.assertGreater(len(listbyresourcegroupresponse), 0,
                           "No Namespace returned, List is empty")
        self.assertEqual(listbyresourcegroupresponse[0].name, namespace_name,
                         "Created namespace not found - ListByResourgroup")

        # Get the List of namespace under the subscription  - list
        listbysubscriptionresponse = list(self.relay_client.namespaces.list())
        self.assertGreater(len(listbysubscriptionresponse), 0,
                           "No Namespace returned, List is empty")

        # get the default authorizationrule
        defaultauthorule_name = "RootManageSharedAccessKey"
        defaultamespaceauthorule = self.relay_client.namespaces.get_authorization_rule(
            resource_group_name, namespace_name, defaultauthorule_name)
        self.assertEqual(
            defaultamespaceauthorule.name, defaultauthorule_name,
            "Default Authorization rule not returned - RootManageSharedAccessKey"
        )
        self.assertEqual(
            len(defaultamespaceauthorule.rights), 3,
            "rights for deafult not as required - send, listen and manage ")

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createnamespaceauthorule = self.relay_client.namespaces.create_or_update_authorization_rule(
            resource_group_name, namespace_name, authoRule_name,
            [AccessRights('Send'),
             AccessRights('Listen')])
        self.assertEqual(
            createnamespaceauthorule.name, authoRule_name,
            "Authorization rule name not as created - create_or_update_authorization_rule "
        )
        self.assertEqual(len(createnamespaceauthorule.rights), 2)

        # Get the created authorizationrule
        getnamespaceauthorule = self.relay_client.namespaces.get_authorization_rule(
            resource_group_name, namespace_name, authoRule_name)
        self.assertEqual(
            getnamespaceauthorule.name, authoRule_name,
            "Authorization rule name not as passed as parameter - get_authorization_rule "
        )
        self.assertEqual(
            len(getnamespaceauthorule.rights), 2,
            "Access rights mis match as created  - get_authorization_rule ")

        # update the rights of the authorizatiorule
        getnamespaceauthorule.rights.append('Manage')
        updatenamespaceauthorule = self.relay_client.namespaces.create_or_update_authorization_rule(
            resource_group_name, namespace_name, authoRule_name,
            getnamespaceauthorule.rights)
        self.assertEqual(
            updatenamespaceauthorule.name, authoRule_name,
            "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule "
        )
        self.assertEqual(
            len(updatenamespaceauthorule.rights), 3,
            "Access rights mis match as updated  - create_or_update_authorization_rule "
        )

        # list all the authorization ruels for the given namespace
        createnamespaceauthorule = list(
            self.relay_client.namespaces.list_authorization_rules(
                resource_group_name, namespace_name))
        self.assertEqual(
            len(createnamespaceauthorule), 2,
            "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules"
        )

        # List keys for the authorization rule
        listkeysauthorizationrule = self.relay_client.namespaces.list_keys(
            resource_group_name, namespace_name, authoRule_name)
        self.assertIsNotNone(listkeysauthorizationrule)

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.relay_client.namespaces.regenerate_keys(
            resource_group_name, namespace_name, authoRule_name, 'PrimaryKey')
        self.assertNotEqual(listkeysauthorizationrule.primary_key,
                            regenratePrimarykeyauthorizationrule.primary_key)

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.relay_client.namespaces.regenerate_keys(
            resource_group_name, namespace_name, authoRule_name,
            'SecondaryKey')
        self.assertNotEqual(
            listkeysauthorizationrule.secondary_key,
            regenrateSecondarykeyauthorizationrule.secondary_key)

        # delete the authorizationrule
        self.relay_client.namespaces.delete_authorization_rule(
            resource_group_name, namespace_name, authoRule_name)

        # list all the authorization ruels for the given namespace
        createnamespaceauthorule = list(
            self.relay_client.namespaces.list_authorization_rules(
                resource_group_name, namespace_name))
        self.assertEqual(len(createnamespaceauthorule), 1)
        self.assertEqual(createnamespaceauthorule[0].name,
                         defaultauthorule_name)

        # Delete the create namespace
        deletenamespace = self.relay_client.namespaces.delete(
            resource_group_name, namespace_name).result()
Example #3
0
    def test_wcfrelay_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        #Create a Namespace
        namespace_name = "testingpythontestcaseeventhubnamespaceEventhub"

        namespaceparameter = RelayNamespace(location, {
            'tag1': 'value1',
            'tag2': 'value2'
        }, Sku(SkuTier.standard))
        creatednamespace = self.relay_client.namespaces.create_or_update(
            resource_group_name, namespace_name, namespaceparameter).result()
        self.assertEqual(creatednamespace.name, namespace_name)

        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.relay_client.namespaces.get(
            resource_group_name, namespace_name)
        self.assertEqual(getnamespaceresponse.name, namespace_name)

        # Create a WcfRelay
        wcfrelay_name = "testingpythontestcasewcfrelay"
        wcfrelayparameter = WcfRelay(relay_type=Relaytype.net_tcp,
                                     requires_client_authorization=True,
                                     requires_transport_security=True,
                                     user_metadata="User data for WcfRelay")

        createdwcfrelayresponse = self.relay_client.wcf_relays.create_or_update(
            resource_group_name, namespace_name, wcfrelay_name,
            wcfrelayparameter)

        self.assertEqual(createdwcfrelayresponse.name, wcfrelay_name)
        self.assertEqual(createdwcfrelayresponse.requires_client_authorization,
                         True)

        #Get the created wcfRelay
        geteventhubresponse = self.relay_client.wcf_relays.get(
            resource_group_name, namespace_name, wcfrelay_name)
        self.assertEqual(geteventhubresponse.name, wcfrelay_name)
        self.assertEqual(geteventhubresponse.requires_transport_security, True)
        self.assertEqual(geteventhubresponse.user_metadata,
                         "User data for WcfRelay")

        #Get the List of wcfRealy by namespaces
        getlistbynamespacewcfrelayresponse = list(
            self.relay_client.wcf_relays.list_by_namespace(
                resource_group_name, namespace_name))
        self.assertGreater(len(getlistbynamespacewcfrelayresponse), 0)

        # update the Created eventhub

        wcfrelayupdateparameter = WcfRelay(
            relay_type=Relaytype.net_tcp,
            user_metadata="User data for WcfRelay updated")

        updatewcfrelayresponse = self.relay_client.wcf_relays.create_or_update(
            resource_group_name, namespace_name, wcfrelay_name,
            wcfrelayupdateparameter)

        self.assertEqual(updatewcfrelayresponse.name, wcfrelay_name)
        self.assertEqual(updatewcfrelayresponse.requires_transport_security,
                         True)
        self.assertEqual(updatewcfrelayresponse.requires_client_authorization,
                         True)
        self.assertEqual(updatewcfrelayresponse.user_metadata,
                         "User data for WcfRelay updated")

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createwcfrelayauthorule = self.relay_client.wcf_relays.create_or_update_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            [AccessRights('Send'),
             AccessRights('Listen')])
        self.assertEqual(
            createwcfrelayauthorule.name, authoRule_name,
            "Authorization rule name not as created - create_or_update_authorization_rule "
        )
        self.assertEqual(len(createwcfrelayauthorule.rights), 2)

        # Get the created authorizationrule
        getwcfrelayauthorule = self.relay_client.wcf_relays.get_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name)
        self.assertEqual(
            getwcfrelayauthorule.name, authoRule_name,
            "Authorization rule name not as passed as parameter - get_authorization_rule "
        )
        self.assertEqual(
            len(getwcfrelayauthorule.rights), 2,
            "Access rights mis match as created  - get_authorization_rule ")

        # update the rights of the authorizatiorule
        getwcfrelayauthorule.rights.append('Manage')
        updatewcfrelayauthorule = self.relay_client.wcf_relays.create_or_update_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            getwcfrelayauthorule.rights)
        self.assertEqual(
            updatewcfrelayauthorule.name, authoRule_name,
            "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule "
        )
        self.assertEqual(
            len(updatewcfrelayauthorule.rights), 3,
            "Access rights mis match as updated  - create_or_update_authorization_rule "
        )

        #list all the authorization ruels for the given namespace
        wcfrelayauthorulelist = list(
            self.relay_client.wcf_relays.list_authorization_rules(
                resource_group_name, namespace_name, wcfrelay_name))
        self.assertEqual(
            len(wcfrelayauthorulelist), 1,
            "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules"
        )

        #List keys for the authorization rule
        listkeysauthorizationrule = self.relay_client.wcf_relays.list_keys(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name)
        self.assertIsNotNone(listkeysauthorizationrule)

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.relay_client.wcf_relays.regenerate_keys(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            'PrimaryKey')
        self.assertNotEqual(listkeysauthorizationrule.primary_key,
                            regenratePrimarykeyauthorizationrule.primary_key)

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.relay_client.wcf_relays.regenerate_keys(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            'SecondaryKey')
        self.assertNotEqual(
            listkeysauthorizationrule.secondary_key,
            regenrateSecondarykeyauthorizationrule.secondary_key)

        # delete the authorizationrule
        self.relay_client.wcf_relays.delete_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name)

        # Delete the created WcfRelay
        getwcfrelayresponse = self.relay_client.wcf_relays.delete(
            resource_group_name, namespace_name, wcfrelay_name)

        # Delete the create namespace
        self.relay_client.namespaces.delete(resource_group_name,
                                            namespace_name).result()
Example #4
0
    def test_hybridconnetion_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        #Create a Namespace
        namespace_name = "testingpythontestcasenamespacehybridconnection"

        namespaceparameter = RelayNamespace(location=location,
                                            tags={
                                                'tag1': 'value1',
                                                'tag2': 'value2'
                                            },
                                            sku=Sku(tier="standard"))
        creatednamespace = self.relay_client.namespaces.begin_create_or_update(
            resource_group_name, namespace_name, namespaceparameter).result()
        assert creatednamespace.name == namespace_name

        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.relay_client.namespaces.get(
            resource_group_name, namespace_name)
        assert getnamespaceresponse.name == namespace_name

        # Create a HybridConnection
        hybridconnection_name = "testingpythontestcasehybridconnection"

        createdhybridconnectionresponse = self.relay_client.hybrid_connections.create_or_update(
            resource_group_name, namespace_name, hybridconnection_name, {
                "requires_client_authorization": True,
                "user_metadata": "User data for HybridConnection"
            })

        assert createdhybridconnectionresponse.name == hybridconnection_name
        assert createdhybridconnectionresponse.requires_client_authorization == True

        #Get the created Hybridconnection
        gethybridconnectionresponse = self.relay_client.hybrid_connections.get(
            resource_group_name, namespace_name, hybridconnection_name)
        assert gethybridconnectionresponse.name == hybridconnection_name
        assert gethybridconnectionresponse.user_metadata == "User data for HybridConnection"

        #Get the List of Hybridconnection by namespaces
        getlistbynamespacehybridconnectionresponse = list(
            self.relay_client.hybrid_connections.list_by_namespace(
                resource_group_name, namespace_name))
        assert len(getlistbynamespacehybridconnectionresponse) > 0

        updatehybridconnectionresponse = self.relay_client.hybrid_connections.create_or_update(
            resource_group_name, namespace_name, hybridconnection_name,
            {"user_metadata": "User data for HybridConnection updated"})

        assert updatehybridconnectionresponse.name == hybridconnection_name
        assert updatehybridconnectionresponse.requires_client_authorization == True
        assert updatehybridconnectionresponse.user_metadata == "User data for HybridConnection updated"

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createhybridconnectionauthorule = self.relay_client.hybrid_connections.create_or_update_authorization_rule(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name,
            {"rights": [AccessRights('Send'),
                        AccessRights('Listen')]})
        assert createhybridconnectionauthorule.name, authoRule_name == "Authorization rule name not as created - create_or_update_authorization_rule "
        assert len(createhybridconnectionauthorule.rights) == 2

        # Get the created authorizationrule
        gethybridconnectionauthorule = self.relay_client.hybrid_connections.get_authorization_rule(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name)
        assert gethybridconnectionauthorule.name, authoRule_name == "Authorization rule name not as passed as parameter - get_authorization_rule "
        assert len(
            gethybridconnectionauthorule.rights
        ), 2 == "Access rights mis match as created  - get_authorization_rule "

        # update the rights of the authorizatiorule
        gethybridconnectionauthorule.rights.append('Manage')
        updatehybridconnectionauthorule = self.relay_client.hybrid_connections.create_or_update_authorization_rule(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name, gethybridconnectionauthorule)
        assert updatehybridconnectionauthorule.name, authoRule_name == "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule "
        assert len(
            updatehybridconnectionauthorule.rights
        ), 3 == "Access rights mis match as updated  - create_or_update_authorization_rule "

        #list all the authorization ruels for the given namespace
        hybridconnectionauthorulelist = list(
            self.relay_client.hybrid_connections.list_authorization_rules(
                resource_group_name, namespace_name, hybridconnection_name))
        assert len(
            hybridconnectionauthorulelist
        ), 1 == "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules"

        #List keys for the authorization rule
        listkeysauthorizationrule = self.relay_client.hybrid_connections.list_keys(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name)
        assert listkeysauthorizationrule is not None

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.relay_client.hybrid_connections.regenerate_keys(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name, {"key_type": 'PrimaryKey'})
        assert listkeysauthorizationrule.primary_key != regenratePrimarykeyauthorizationrule.primary_key

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.relay_client.hybrid_connections.regenerate_keys(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name, {"key_type": 'SecondaryKey'})
        assert listkeysauthorizationrule.secondary_key != regenrateSecondarykeyauthorizationrule.secondary_key

        # delete the authorizationrule
        self.relay_client.hybrid_connections.delete_authorization_rule(
            resource_group_name, namespace_name, hybridconnection_name,
            authoRule_name)

        # Delete the created HybridConnection
        gethybridconnectionresponse = self.relay_client.hybrid_connections.delete(
            resource_group_name, namespace_name, hybridconnection_name)

        # Delete the create namespace
        self.relay_client.namespaces.begin_delete(resource_group_name,
                                                  namespace_name).result()
    def test_relay_namespace_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        # Create a Namespace
        namespace_name = "testingpythontestcasenamespace"
        namespaceparameter = RelayNamespace(location=location,
                                            tags={
                                                'tag1': 'value1',
                                                'tag2': 'value2'
                                            },
                                            sku=Sku(tier="standard"))
        creatednamespace = self.relay_client.namespaces.begin_create_or_update(
            resource_group_name, namespace_name, namespaceparameter).result()
        assert creatednamespace.name == namespace_name
        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.relay_client.namespaces.get(
            resource_group_name, namespace_name)
        assert getnamespaceresponse.name == namespace_name

        # Update a Namespace
        namespaceparameter = {'tags': {'tag1': 'value1', 'tag2': 'value2'}}
        updatenamespace = self.relay_client.namespaces.update(
            resource_group_name, namespace_name, namespaceparameter)

        # Get the List of Namespaces under the resourceGroup - list_by_resource_group
        listbyresourcegroupresponse = list(
            self.relay_client.namespaces.list_by_resource_group(
                resource_group_name))
        assert len(listbyresourcegroupresponse
                   ) > 0, "No Namespace returned > List is empty"
        assert listbyresourcegroupresponse[
            0].name == namespace_name, "Created namespace not found - ListByResourgroup"

        # Get the List of namespace under the subscription  - list
        listbysubscriptionresponse = list(self.relay_client.namespaces.list())
        assert len(listbysubscriptionresponse
                   ) > 0, "No Namespace returned > List is empty"
        # get the default authorizationrule
        defaultauthorule_name = "RootManageSharedAccessKey"
        defaultamespaceauthorule = self.relay_client.namespaces.get_authorization_rule(
            resource_group_name, namespace_name, defaultauthorule_name)
        assert defaultamespaceauthorule.name == defaultauthorule_name, "Default Authorization rule not returned - RootManageSharedAccessKey"
        assert len(
            defaultamespaceauthorule.rights
        ) == 3, "rights for deafult not as required - send == listen and manage "

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createnamespaceauthorule = self.relay_client.namespaces.create_or_update_authorization_rule(
            resource_group_name, namespace_name, authoRule_name,
            {"rights": [AccessRights('Send'),
                        AccessRights('Listen')]})
        assert createnamespaceauthorule.name, authoRule_name == "Authorization rule name not as created - create_or_update_authorization_rule "
        assert len(createnamespaceauthorule.rights) == 2

        # Get the created authorizationrule
        getnamespaceauthorule = self.relay_client.namespaces.get_authorization_rule(
            resource_group_name, namespace_name, authoRule_name)
        assert getnamespaceauthorule.name, authoRule_name == "Authorization rule name not as passed as parameter - get_authorization_rule "
        assert len(
            getnamespaceauthorule.rights
        ), 2 == "Access rights mis match as created  - get_authorization_rule "

        # update the rights of the authorizatiorule
        getnamespaceauthorule.rights.append('Manage')
        updatenamespaceauthorule = self.relay_client.namespaces.create_or_update_authorization_rule(
            resource_group_name, namespace_name, authoRule_name,
            getnamespaceauthorule)
        assert updatenamespaceauthorule.name, authoRule_name == "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule "
        assert len(
            updatenamespaceauthorule.rights
        ), 3 == "Access rights mis match as updated  - create_or_update_authorization_rule "

        # list all the authorization ruels for the given namespace
        createnamespaceauthorule = list(
            self.relay_client.namespaces.list_authorization_rules(
                resource_group_name, namespace_name))
        assert len(
            createnamespaceauthorule
        ), 2 == "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules"

        # List keys for the authorization rule
        listkeysauthorizationrule = self.relay_client.namespaces.list_keys(
            resource_group_name, namespace_name, authoRule_name)
        assert listkeysauthorizationrule is not None

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.relay_client.namespaces.regenerate_keys(
            resource_group_name, namespace_name, authoRule_name,
            {"key_type": 'PrimaryKey'})
        assert listkeysauthorizationrule.primary_key != regenratePrimarykeyauthorizationrule.primary_key

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.relay_client.namespaces.regenerate_keys(
            resource_group_name, namespace_name, authoRule_name,
            {"key_type": 'SecondaryKey'})
        assert listkeysauthorizationrule.secondary_key != regenrateSecondarykeyauthorizationrule.secondary_key

        # delete the authorizationrule
        self.relay_client.namespaces.delete_authorization_rule(
            resource_group_name, namespace_name, authoRule_name)

        # list all the authorization ruels for the given namespace
        createnamespaceauthorule = list(
            self.relay_client.namespaces.list_authorization_rules(
                resource_group_name, namespace_name))
        assert len(createnamespaceauthorule) == 1
        assert createnamespaceauthorule[0].name == defaultauthorule_name

        # Delete the create namespace
        deletenamespace = self.relay_client.namespaces.begin_delete(
            resource_group_name, namespace_name).result()
Example #6
0
    def test_wcfrelay_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        #Create a Namespace
        namespace_name = "testingpythontestcaseeventhubnamespaceEventhub"

        namespaceparameter = RelayNamespace(location=location,
                                            tags={
                                                'tag1': 'value1',
                                                'tag2': 'value2'
                                            },
                                            sku=Sku(tier="standard"))
        creatednamespace = self.relay_client.namespaces.begin_create_or_update(
            resource_group_name, namespace_name, namespaceparameter).result()
        assert creatednamespace.name == namespace_name

        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.relay_client.namespaces.get(
            resource_group_name, namespace_name)
        assert getnamespaceresponse.name == namespace_name

        # Create a WcfRelay
        wcfrelay_name = "testingpythontestcasewcfrelay"
        wcfrelayparameter = WcfRelay(relay_type=Relaytype.net_tcp,
                                     requires_client_authorization=True,
                                     requires_transport_security=True,
                                     user_metadata="User data for WcfRelay")

        createdwcfrelayresponse = self.relay_client.wcf_relays.create_or_update(
            resource_group_name, namespace_name, wcfrelay_name,
            wcfrelayparameter)

        assert createdwcfrelayresponse.name == wcfrelay_name
        assert createdwcfrelayresponse.requires_client_authorization == True

        #Get the created wcfRelay
        geteventhubresponse = self.relay_client.wcf_relays.get(
            resource_group_name, namespace_name, wcfrelay_name)
        assert geteventhubresponse.name == wcfrelay_name
        assert geteventhubresponse.requires_transport_security == True
        assert geteventhubresponse.user_metadata == "User data for WcfRelay"

        #Get the List of wcfRealy by namespaces
        getlistbynamespacewcfrelayresponse = list(
            self.relay_client.wcf_relays.list_by_namespace(
                resource_group_name, namespace_name))
        assert len(getlistbynamespacewcfrelayresponse) > 0

        # update the Created eventhub
        wcfrelayupdateparameter = WcfRelay(
            relay_type=Relaytype.net_tcp,
            user_metadata="User data for WcfRelay updated")
        updatewcfrelayresponse = self.relay_client.wcf_relays.create_or_update(
            resource_group_name, namespace_name, wcfrelay_name,
            wcfrelayupdateparameter)
        assert updatewcfrelayresponse.name == wcfrelay_name
        assert updatewcfrelayresponse.requires_transport_security == True
        assert updatewcfrelayresponse.requires_client_authorization == True
        assert updatewcfrelayresponse.user_metadata == "User data for WcfRelay updated"

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createwcfrelayauthorule = self.relay_client.wcf_relays.create_or_update_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            {"rights": [AccessRights('Send'),
                        AccessRights('Listen')]})
        assert createwcfrelayauthorule.name, authoRule_name == "Authorization rule name not as created - create_or_update_authorization_rule "
        assert len(createwcfrelayauthorule.rights) == 2

        # Get the created authorizationrule
        getwcfrelayauthorule = self.relay_client.wcf_relays.get_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name)
        assert getwcfrelayauthorule.name, authoRule_name == "Authorization rule name not as passed as parameter - get_authorization_rule "
        assert len(
            getwcfrelayauthorule.rights
        ), 2 == "Access rights mis match as created  - get_authorization_rule "

        # update the rights of the authorizatiorule
        getwcfrelayauthorule.rights.append('Manage')
        updatewcfrelayauthorule = self.relay_client.wcf_relays.create_or_update_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            getwcfrelayauthorule)
        assert updatewcfrelayauthorule.name, authoRule_name == "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule "
        assert len(
            updatewcfrelayauthorule.rights
        ), 3 == "Access rights mis match as updated  - create_or_update_authorization_rule "

        #list all the authorization ruels for the given namespace
        wcfrelayauthorulelist = list(
            self.relay_client.wcf_relays.list_authorization_rules(
                resource_group_name, namespace_name, wcfrelay_name))
        assert len(
            wcfrelayauthorulelist
        ), 1 == "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules"

        #List keys for the authorization rule
        listkeysauthorizationrule = self.relay_client.wcf_relays.list_keys(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name)
        assert listkeysauthorizationrule is not None

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.relay_client.wcf_relays.regenerate_keys(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            {"key_type": 'PrimaryKey'})
        assert listkeysauthorizationrule.primary_key != regenratePrimarykeyauthorizationrule.primary_key

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.relay_client.wcf_relays.regenerate_keys(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name,
            {"key_type": 'SecondaryKey'})
        assert listkeysauthorizationrule.secondary_key != regenrateSecondarykeyauthorizationrule.secondary_key

        # delete the authorizationrule
        self.relay_client.wcf_relays.delete_authorization_rule(
            resource_group_name, namespace_name, wcfrelay_name, authoRule_name)

        # Delete the created WcfRelay
        getwcfrelayresponse = self.relay_client.wcf_relays.delete(
            resource_group_name, namespace_name, wcfrelay_name)

        # Delete the create namespace
        self.relay_client.namespaces.begin_delete(resource_group_name,
                                                  namespace_name).result()