def test_no_org_depts(self): """The function should not error out if the departments field doesn't appear in any orgs.""" org_data = [{ "id": 1234, "name": "Some Organization", "certTypes": [] }, { "id": 4321, "name": "Another Organization", "certTypes": [] }, { "id": 9999, "name": "Some Organization", "certTypes": [], "departments": [ { "id": 8888, "name": "Org Unit 1", "certTypes": ["CodeSign", "SMIME", "SSL"] }, ] }] # Setup the mocked response responses.add(responses.GET, self.api_url, json=org_data, status=200) org = Organization(client=self.client) data = org.find(dept_name="abc123") # Verify all the query information # There should only be one call the first time "all" is called in the constructor. self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(data, [])
def test_no_params(self): """The function should return the entire list of orgs if no parameters are passed.""" # Setup the mocked response responses.add(responses.GET, self.api_url, json=self.valid_response, status=200) org = Organization(client=self.client) data = org.find() # Verify all the query information # There should only be one call the first time "all" is called in the constructor. self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(data, self.valid_response)
def test_ne_dept(self): """The function should return an empty list if the department name doesn't exist.""" # Setup the mocked response responses.add(responses.GET, self.api_url, json=self.valid_response, status=200) org = Organization(client=self.client) data = org.find(dept_name="Nonexistent Department") # Verify all the query information # There should only be one call the first time "all" is called in the constructor. self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(data, [])
def test_org_and_dept(self): """The function should return department data for department under a specific org.""" # Setup the mocked response responses.add(responses.GET, self.api_url, json=self.valid_response, status=200) org = Organization(client=self.client) data = org.find(org_name="Some Organization", dept_name="Org Unit 1") # Verify all the query information # There should only be one call the first time "all" is called in the constructor. self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(data[0], self.valid_response[0]["departments"][0])
def test_org(self): """The function should return all the data about the specified organization name.""" # Setup the mocked response responses.add(responses.GET, self.api_url, json=self.valid_response, status=200) org = Organization(client=self.client) data = org.find(org_name="Some Organization") # Verify all the query information # There should only be one call the first time "all" is called in the constructor. self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(data, self.valid_response)
def test_cached(self): """The function should return all the data, but should not query the API twice.""" # Setup the mocked response responses.add(responses.GET, self.api_url, json=self.valid_response, status=200) org = Organization(client=self.client) data = org.all() # Verify all the query information # There should only be one call the first time "all" is called in the constructor. self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(data, self.valid_response)
def test_defaults(self): """Parameters should be set correctly inside the class using defaults.""" # Setup the mocked response responses.add(responses.GET, self.api_url, json=self.valid_response, status=200) org = Organization(client=self.client) # Verify all the query information self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.api_url) self.assertEqual(org._Organization__orgs, self.valid_response)
def test_param(self): """The URL should change if api_version is passed as a parameter.""" # Set a new version version = "v3" api_url = f"{self.cfixt.base_url}/organization/{version}" # Setup the mocked response responses.add(responses.GET, api_url, json=self.valid_response, status=200) org = Organization(client=self.client, api_version=version) # Verify all the query information self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, api_url) self.assertEqual(org._Organization__orgs, self.valid_response)