def test_method_create_request_url(self): """Test that method returns full request url (resource_url + query params)""" resource = Resource(PARATURE_URL, 'FAKETOKEN', "Ticket") params = { 'Initial_Resolution_Date': '_today_', '_output_': 'xml' } request_url = resource._create_request_url(params) expected_url = PARATURE_URL + 'Ticket?_token_=FAKETOKEN&_output_=xml&_pageSize_=50&Initial_Resolution_Date=_today_' self.assertEqual(request_url, expected_url)
class ResourceTestCase(TestCase): """Unit tests for Resource class""" @classmethod def setUpClass(cls): pass @classmethod def tearDownClass(cls): pass def setUp(self): self.resource = Resource(PARATURE_URL, PARATURE_TOKEN, RESOURCE) def tearDown(self): self.resource = None def test_instance_variable_base_url(self): """Test that instance variable url is created on instantiation""" self.assertIsNotNone(self.resource.base_url) def test_instance_variable_token(self): """Test that instance variable token is created on instantiation""" self.assertIsNotNone(self.resource.token) def test_instance_variable_resource(self): """Test that instance variable resource is created on instantiation""" self.assertIsNotNone(self.resource.resource) def test_property_resource_url_exists(self): """Test that property resource_url exists""" self.assertIsNotNone(self.resource.resource_url) def test_property_resource_url_is_valid(self): """Test that property resource_url returns correctly formed string""" resource_url = self.resource.resource_url valid_resource_url = PARATURE_URL + 'Ticket' self.assertIsInstance(resource_url, str) self.assertTrue(resource_url == valid_resource_url) def test_method_create_request_url(self): """Test that method returns full request url (resource_url + query params)""" resource = Resource(PARATURE_URL, 'FAKETOKEN', "Ticket") params = { 'Initial_Resolution_Date': '_today_', '_output_': 'xml' } request_url = resource._create_request_url(params) expected_url = PARATURE_URL + 'Ticket?_token_=FAKETOKEN&_output_=xml&_pageSize_=50&Initial_Resolution_Date=_today_' self.assertEqual(request_url, expected_url) def test_method_get_returns_response(self): """Test that method returns a dict""" response = self.resource.get() self.assertIsInstance(response, Response)
def setUp(self): self.resource = Resource(PARATURE_URL, PARATURE_TOKEN, RESOURCE)