Reorganized test setup to avoid repeated authentication during tests.
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
import requests
 | 
					import requests
 | 
				
			||||||
import urllib.parse
 | 
					import urllib.parse
 | 
				
			||||||
from uuid import UUID
 | 
					from uuid import UUID
 | 
				
			||||||
 | 
					from azure.identity import DefaultAzureCredential
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEVOPS_SCOPE = "https://app.vssps.visualstudio.com/.default"
 | 
					DEVOPS_SCOPE = "https://app.vssps.visualstudio.com/.default"
 | 
				
			||||||
DEVOPS_API_VERSION = "7.1"
 | 
					DEVOPS_API_VERSION = "7.1"
 | 
				
			||||||
@@ -105,7 +106,9 @@ class DevOps():
 | 
				
			|||||||
        return entities_list
 | 
					        return entities_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Organization(DevOps):
 | 
					class Organization(DevOps):
 | 
				
			||||||
    def __init__(self, org_url: str, token: str, api_version: str = DEVOPS_API_VERSION):
 | 
					    def __init__(self, org_url: str, token: str | None = None, api_version: str = DEVOPS_API_VERSION):
 | 
				
			||||||
 | 
					        if token is None:
 | 
				
			||||||
 | 
					            token = DefaultAzureCredential().get_token(DEVOPS_SCOPE).token
 | 
				
			||||||
        super().__init__(org_url, token, api_version)
 | 
					        super().__init__(org_url, token, api_version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								tests.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								tests.py
									
									
									
									
									
								
							@@ -1,15 +1,14 @@
 | 
				
			|||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
from devops import DEVOPS_SCOPE, Organization, Repository, Project, Item
 | 
					from devops import Organization, Repository, Project, Item
 | 
				
			||||||
from azure.identity import DefaultAzureCredential
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Example: set up your org here if possible, or mock as needed
 | 
					# Setup the Organization object outside the test class to speed up tests.
 | 
				
			||||||
# org = Organization("https://dev.azure.com/mcovsandbox", DefaultAzureCredential().get_token(DEVOPS_SCOPE).token)
 | 
					# Each Unit test instantinates the class, so doing it here avoids repeated authentication.
 | 
				
			||||||
 | 
					org = Organization("https://dev.azure.com/mcovsandbox")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestDevOps(unittest.TestCase):
 | 
					class TestDevOps(unittest.TestCase):
 | 
				
			||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        # Set up your Organization object here if possible
 | 
					        self.org = org
 | 
				
			||||||
        self.org = Organization("https://dev.azure.com/mcovsandbox", DefaultAzureCredential().get_token(DEVOPS_SCOPE).token)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_listing_projects_in_organization(self):
 | 
					    def test_listing_projects_in_organization(self):
 | 
				
			||||||
        org = self.org
 | 
					        org = self.org
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user