Test Overview
This test verifies that a Postman collection contains a specific folder and that the folder has the expected number of requests. It ensures the collection structure is correct for organized API testing.
This test verifies that a Postman collection contains a specific folder and that the folder has the expected number of requests. It ensures the collection structure is correct for organized API testing.
import unittest from postman_collection import Collection class TestPostmanCollection(unittest.TestCase): def setUp(self): # Load collection JSON file with open('sample_collection.json', 'r', encoding='utf-8') as f: self.collection = Collection.from_json(f.read()) def test_folder_exists_and_request_count(self): # Check if folder named 'User APIs' exists folder = next((f for f in self.collection.folders if f.name == 'User APIs'), None) self.assertIsNotNone(folder, 'Folder "User APIs" should exist in collection') # Check folder has exactly 3 requests self.assertEqual(len(folder.requests), 3, 'Folder "User APIs" should contain 3 requests') if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Python unittest framework initialized | - | PASS |
| 2 | Loads 'sample_collection.json' file | Collection JSON content loaded into memory | - | PASS |
| 3 | Parses collection JSON into Collection object | Collection object created with folders and requests | - | PASS |
| 4 | Searches for folder named 'User APIs' | Folder list scanned | Folder 'User APIs' is found (not None) | PASS |
| 5 | Counts requests inside 'User APIs' folder | Folder contains requests | Folder has exactly 3 requests | PASS |
| 6 | Test ends | All assertions passed | - | PASS |