Esempio n. 1
0
    def write(self, resource: Resource):
        if resource is None:
            raise ValueError("resource is required")

        # Query string params are required in addition to the POST body
        entry = resource.to_normalized_dict()

        query = urllib.parse.urlencode({
            'AccountId': entry["OwnerId"],
            'ResourceType': entry["ResourceType"],
            'Region': entry["Region"]
        })

        post_url = f'{self._url}?{query}'
        RequestHelper.post(post_url, json=[entry])
    def test_write_with_resource(self, mock_post):
        provider = self._create_provider()

        resource_json = {
            "id": "/subscriptions/foo/resourcegroups/bar/Microsoft.Test/resources/baz",
            "accountId": "abcxyz123",
            "name": "Test Resource",
            "type": "Microsoft.Test",
            "location": "westus",
            "tags": {
                "a": "1",
                "b": "2"
            }
        }

        resource = Resource(resource_json)

        expected_url = f"{TestRestResourceStorage.test_url}?AccountId=abcxyz123&ResourceType=Microsoft_Test&Region=westus"
        expected_entry = resource.to_normalized_dict()

        provider.write_entries([resource])
        mock_post.assert_called_once_with(expected_url, json=[expected_entry])