def test_method_extend(self):
        """Test that method extend increments appropriate instance variables"""
        original_data = {
            "Entities": {
                "@total": "100",
                "@results": "5",
                "@page": "1",
                "@page-size": "5",
                "@href": "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5",
                "Ticket": [{'test': '123'}]
            }
        }
        additional_data = {
            "Entities": {
                "@total": "100",
                "@results": "5",
                "@page": "2",
                "@page-size": "5",
                "@href": "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5",
                "Ticket": [{'test': '456'}]
            }
        }
        expected_data = {
            'total': 100,
            'number_returned': 10,
            'request_url': "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5",
            'page': 2,
            'resource': 'Ticket',
            'has_next_page': True,
            'results': [{'test': '123'}, {'test': '456'}]
        }
        response = Response(original_data)
        response.extend(additional_data)

        self.assertEqual(expected_data, response.dict())
    def get(self, query_parameters=None):
        """Fetch data from the Parature API"""
        if not query_parameters:
            query_parameters = {}

        paginate = query_parameters.get('paginate', False)
        request_url = self._create_request_url(query_parameters)

        r = requests.get(request_url)
        if r.status_code != 200:
            raise Exception

        response = Response(r.json())

        while paginate and response.has_next_page:
            request_url = response.get_next_page_url(self.token)
            r = requests.get(request_url)

            response.extend(r.json())

        return response
 def setUp(self):
     self.response = Response(TEST_DATA)
class ResponseTestCase(TestCase):
    """Unit tests for Response class"""
    @classmethod
    def setUpClass(cls):
        pass

    @classmethod
    def tearDownClass(cls):
        pass

    def setUp(self):
        self.response = Response(TEST_DATA)

    def tearDown(self):
        pass

    def test_instance_variable_number_returned_is_int(self):
        """Test that instance variable number_returned is an int"""
        self.assertIsInstance(self.response.number_returned, int)

    def test_instance_variable_total_is_int(self):
        """Test that instance variable total is an int"""
        self.assertIsInstance(self.response.total, int)

    def test_instance_variable_request_url_is_str(self):
        """Test that instance variable request_url is an str"""
        self.assertIsInstance(self.response.request_url, str)

    def test_instance_variable_page_is_int(self):
        """Test that instance variable page is an int"""
        self.assertIsInstance(self.response.page, int)

    def test_instance_variable_results_is_list(self):
        """Test that instance variable results is list"""
        self.assertIsInstance(self.response.results, list)

    def test_instance_variable_resource(self):
        """Test that instance variable resource is str"""
        self.assertIsInstance(self.response.resource, str)

    def test_method_extract_number_returned(self):
        """Test that method returns number of results returned"""
        number_returned = self.response._extract_number_returned(TEST_DATA)

        expected_results_returned = 5

        self.assertEqual(number_returned, expected_results_returned)

    def test_method_extract_total(self):
        """Test that method returns total of results matching query parameters provided"""
        total = self.response._extract_total(TEST_DATA)

        expected_total = 132640

        self.assertEqual(total, expected_total)

    def test_method_extract_request_url(self):
        """Test that method returns request url"""
        request_url = self.response._extract_request_url(TEST_DATA)

        expected_url = "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5"

        self.assertEqual(request_url, expected_url)

    def test_method_extract_page(self):
        """Test that method returns page"""
        page = self.response._extract_page(TEST_DATA)

        expected_page = 1

        self.assertEqual(page, expected_page)

    def test_method_extract_results_returns_list(self):
        """Test that method returns results list"""
        results = self.response._extract_results(TEST_DATA)

        self.assertIsInstance(results, list)

    def test_method_extract_resource_name(self):
        """Test that method returns a valid resource name"""
        resource = self.response._extract_resource_name()

        is_valid = True

        if resource not in ['Ticket', 'Csr', 'Account', 'Customer']:
            is_valid = False

        self.assertTrue(is_valid)

    def test_method_get_next_page_url_returns_str(self):
        """Test that instance variable total is an str"""
        next_page_url = self.response.get_next_page_url('TOKEN')

        self.assertIsInstance(next_page_url, str)

    def test_property_has_next_page(self):
        """Test that method returns true if response has paginated results"""
        has_next_page = self.response.has_next_page

        self.assertTrue(has_next_page)

    def test_property_has_next_page_is_bool(self):
        """Test that method returns true if response has paginated results"""
        has_next_page = self.response.has_next_page

        self.assertIsInstance(has_next_page, bool)

    def test_method_dict(self):
        """Test that method returns a dict representation of Response"""
        dict_of_class = self.response.dict()

        self.assertIsInstance(dict_of_class, dict)

    def test_method_extend(self):
        """Test that method extend increments appropriate instance variables"""
        original_data = {
            "Entities": {
                "@total": "100",
                "@results": "5",
                "@page": "1",
                "@page-size": "5",
                "@href": "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5",
                "Ticket": [{'test': '123'}]
            }
        }
        additional_data = {
            "Entities": {
                "@total": "100",
                "@results": "5",
                "@page": "2",
                "@page-size": "5",
                "@href": "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5",
                "Ticket": [{'test': '456'}]
            }
        }
        expected_data = {
            'total': 100,
            'number_returned': 10,
            'request_url': "https://supportcenteronline.com/api/v1/1234/1234/Ticket?_output_=json&_pageSize_=5",
            'page': 2,
            'resource': 'Ticket',
            'has_next_page': True,
            'results': [{'test': '123'}, {'test': '456'}]
        }
        response = Response(original_data)
        response.extend(additional_data)

        self.assertEqual(expected_data, response.dict())