def test_list_permissions_empty(mock_service): service, _ = mock_service("account_get.json", "empty.json") account = GTMAccount(path="accounts/1234567", service=service) permissions_list = account.list_permissions() assert permissions_list == [] account.list_permissions(refresh=False)
def test_list_containers_empty(mock_service): service, _ = mock_service("account_get.json", "empty.json") account = GTMAccount(path="accounts/1234567", service=service) container_list = account.list_containers() assert container_list == [] account.list_containers(refresh=False)
def test_update(mock_service): service, repsonses = mock_service("account_get.json", "account_update.json") account_update = repsonses[1] account = GTMAccount(path="accounts/1234567", service=service) account.update("name", True) assert account.name == account_update["name"] assert account.shareData == account_update["shareData"]
def test_list_containers(mock_service): service, responses = mock_service("account_get.json", "containers_list.json") container_list_dict = responses[1] account = GTMAccount(path="accounts/1234567", service=service) container_list = account.list_containers() assert len(container_list) == len(container_list_dict["container"]) assert isinstance(container_list[0], GTMContainer) account.list_containers(refresh=False)
def test_list_permissions(mock_service): service, responses = mock_service("account_get.json", "permissions_list.json") permissions_list_dict = responses[1] account = GTMAccount(path="accounts/1234567", service=service) permissions_list = account.list_permissions() assert len(permissions_list) == len( permissions_list_dict["userPermission"]) assert isinstance(permissions_list[0], GTMPermission) account.list_permissions(refresh=False)
def test_create_container(mock_service): service, repsonses = mock_service("account_get.json", "container_get.json") container_get = repsonses[1] account = GTMAccount(path="accounts/1234567", service=service) container = account.create_container(container_get["name"]) assert isinstance(container, GTMContainer) assert container.name == container_get["name"] assert container.publicId == container_get["publicId"] assert container.containerId == container_get["containerId"] assert container.domainName == container_get.get("domainName", "") assert container.notes == container_get.get("notes", "") assert container.tagManagerUrl == container_get["tagManagerUrl"] assert container.usageContext == container_get["usageContext"] assert container.fingerprint == container_get["fingerprint"] assert container.path == container_get["path"] assert container.accountId == container_get["accountId"]
def test_init(mock_service): service, responses = mock_service("account_get.json") account_get_dict = responses[0] account = GTMAccount(path="accounts/1234567", service=service) assert account.path == account_get_dict["path"] assert account.accountId == account_get_dict["accountId"] assert account.name == account_get_dict["name"] assert account.fingerprint == account_get_dict["fingerprint"] assert account.tagManagerUrl == account_get_dict["tagManagerUrl"] account_2 = GTMAccount(account=account_get_dict, service=service) assert account.path == account_2.path assert account.accountId == account_2.accountId assert account.name == account_2.name assert account.fingerprint == account_2.fingerprint assert account.tagManagerUrl == account_2.tagManagerUrl
from gtm_manager.manager import GTMManager # connecting to the Google OAuth credentials and secret ( stored in the same file? ) gtm_manager.CLIENT_SECRET_FILE = "" gtm_manager.CREDENTIALS_FILE_NAME = "" # Adding AUTH Scopes (permissions to edit and publish) gtm_manager.AUTH_SCOPES = [ gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERS, gtm_manager.GoogleTagManagerScopes.PUBLISH, gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERVERSIONS, gtm_manager.GoogleTagManagerScopes.MANAGE_ACCOUNTS, gtm_manager.GoogleTagManagerScopes.MANAGE_USERS, ] # connecting to the GTM account, in the Google account provided - format: path="accounts/accountNumber" account = GTMAccount(path="accounts/") # making a list of the cotainers of the account containers = account.list_containers() #making an empty list, to hold unknown workspaces unknownWorkspaces = [] #catching containers id, if a publish is done with error errorPublishVersion = [] #contianers that already have a GA ID containerWithGaID = [] print("\nDu er ved at køre et script på containeren: " + account.name.upper() + ".")
def useAccount(nameOfAccountToUse): account = GTMAccount(path="accounts/" + str(nameOfAccountToUse)) return account
from gtm_manager.trigger import GTMTrigger from gtm_manager.workspace import GTMWorkspace # #### __2. Authorise GTM API__ # In[2]: gtm_manager.CLIENT_SECRET_FILE = "client_secret.json" gtm_manager.CREDENTIALS_FILE_NAME = "auth_credentials.json" gtm_manager.AUTH_SCOPES = [ gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERS, gtm_manager.GoogleTagManagerScopes.PUBLISH, gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERVERSIONS, ] try: account = GTMAccount(path="accounts/6001493098") except: print("Error: Issue finding account") try: container = GTMContainer(path="accounts/6001493098/containers/31768050") print("Active Container: ", container) print("Auth Successful") except: print("Error: Issue finding container, auth failed") # #### 3. Define workspace name # If the workspace name does not exist, it will be created and set active. # If the workspace name does exist, it will be set active. # In[3]: