Implemented item indexer on Repository class.
This commit is contained in:
		
							
								
								
									
										60
									
								
								tests.py
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								tests.py
									
									
									
									
									
								
							@@ -1,20 +1,19 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
import unittest
 | 
			
		||||
from devops import Organization, Repository, Project, Item
 | 
			
		||||
from azure.identity import DefaultAzureCredential
 | 
			
		||||
from devops import DEVOPS_SCOPE, Organization, Repository, Project, Item
 | 
			
		||||
 | 
			
		||||
# Setup the Organization object outside the test class to speed up tests.
 | 
			
		||||
# Get the token outside the test class to speed up tests.
 | 
			
		||||
# Each Unit test instantinates the class, so doing it here avoids repeated authentication.
 | 
			
		||||
org = Organization("https://dev.azure.com/mcovsandbox")
 | 
			
		||||
token = DefaultAzureCredential().get_token(DEVOPS_SCOPE).token
 | 
			
		||||
 | 
			
		||||
class Test01(unittest.TestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.org = org
 | 
			
		||||
        self.org = Organization("https://dev.azure.com/mcovsandbox", token=token)
 | 
			
		||||
 | 
			
		||||
    def test_01(self):
 | 
			
		||||
        """Listing projects in the organization"""
 | 
			
		||||
        org = self.org
 | 
			
		||||
        projects = list(org.projects)
 | 
			
		||||
        self.assertGreater(len(projects), 0)
 | 
			
		||||
        self.assertGreater(len(list(self.org.projects)), 0)
 | 
			
		||||
    def test_02(self):
 | 
			
		||||
        """Getting a specific project by ID (object instantiation)"""
 | 
			
		||||
        project = Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727")
 | 
			
		||||
@@ -33,7 +32,7 @@ class Test01(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
class Test02(unittest.TestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.org = org
 | 
			
		||||
        self.org = Organization("https://dev.azure.com/mcovsandbox", token=token)
 | 
			
		||||
 | 
			
		||||
    def test_01(self):
 | 
			
		||||
        """Listing repositories in a project"""
 | 
			
		||||
@@ -41,9 +40,29 @@ class Test02(unittest.TestCase):
 | 
			
		||||
        repos = list(project.repositories)
 | 
			
		||||
        self.assertGreater(len(repos), 0)
 | 
			
		||||
 | 
			
		||||
    def test_02(self):
 | 
			
		||||
        """Getting a specific repository by ID (object instantiation)"""
 | 
			
		||||
        repo = Repository(Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727"), id="feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        self.assertEqual(repo.id, "feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        self.assertEqual(repo.name, "ado-auth-lab")
 | 
			
		||||
 | 
			
		||||
    def test_03(self):
 | 
			
		||||
        """Getting a specific repository by name using project indexing (object retrieval)"""
 | 
			
		||||
        project = Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727")
 | 
			
		||||
        repo = project["ado-auth-lab"]
 | 
			
		||||
        self.assertEqual(repo.id, "feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        self.assertEqual(repo.name, "ado-auth-lab")
 | 
			
		||||
 | 
			
		||||
    def test_04(self):
 | 
			
		||||
        """Getting a specific repository by ID using project indexing (object retrieval)"""
 | 
			
		||||
        project = Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727")
 | 
			
		||||
        repo = project["feac266f-84d2-41bc-839b-736925a85eaa"]
 | 
			
		||||
        self.assertEqual(repo.id, "feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        self.assertEqual(repo.name, "ado-auth-lab")
 | 
			
		||||
 | 
			
		||||
class Test03(unittest.TestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.org = org
 | 
			
		||||
        self.org = Organization("https://dev.azure.com/mcovsandbox", token=token)
 | 
			
		||||
 | 
			
		||||
    def test_01(self):
 | 
			
		||||
        """Getting details of a specific item in a repository"""
 | 
			
		||||
@@ -58,9 +77,29 @@ class Test03(unittest.TestCase):
 | 
			
		||||
        children = list(docs_item.children)
 | 
			
		||||
        self.assertGreater(len(children), 0)
 | 
			
		||||
 | 
			
		||||
    def test_03(self):
 | 
			
		||||
        """Getting a specific item from a repository using indexing"""
 | 
			
		||||
        repo = Repository(Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727"), id="feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        item = repo["/container"]
 | 
			
		||||
        self.assertEqual(item.path, "/container")
 | 
			
		||||
        self.assertTrue(item.is_folder)
 | 
			
		||||
 | 
			
		||||
    def test_04(self):
 | 
			
		||||
        """Getting a specific item from a repository using indexing"""
 | 
			
		||||
        repo = Repository(Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727"), id="feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        item = repo["/generate-pat.py"]
 | 
			
		||||
        self.assertEqual(item.path, "/generate-pat.py")
 | 
			
		||||
        self.assertFalse(item.is_folder)
 | 
			
		||||
 | 
			
		||||
    def test_05(self):
 | 
			
		||||
        """Attempting to get a non-existent item from a repository using indexing"""
 | 
			
		||||
        repo = Repository(Project(self.org, id="bafe0cf1-6c97-4088-864a-ea6dc02b2727"), id="feac266f-84d2-41bc-839b-736925a85eaa")
 | 
			
		||||
        with self.assertRaises(KeyError):
 | 
			
		||||
            repo["/non-existent-file.txt"] # This file does not exist
 | 
			
		||||
 | 
			
		||||
class Test04(unittest.TestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.org = org
 | 
			
		||||
        self.org = Organization("https://dev.azure.com/mcovsandbox", token=token)
 | 
			
		||||
 | 
			
		||||
    def test_01(self):
 | 
			
		||||
        """Getting details of a specific item in a repository"""
 | 
			
		||||
@@ -75,6 +114,5 @@ class Test04(unittest.TestCase):
 | 
			
		||||
        children = list(docs_item.children)
 | 
			
		||||
        self.assertGreater(len(children), 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    unittest.main()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user