'Verify that `construct_url` works correctly.'

@ddt.unpack
@ddt.data({'previous_api_url': None, 'next_api_url': None}, {'previous_api_url': None, 'next_api_url': 'edxnotes/?course_id=abc&page=2&page_size=10&user=123'}, {'previous_api_url': 'edxnotes.org/?course_id=abc&page=2&page_size=10&user=123', 'next_api_url': None}, {'previous_api_url': 'edxnotes.org/?course_id=abc&page_size=10&user=123', 'next_api_url': 'edxnotes.org/?course_id=abc&page=3&page_size=10&user=123'}, {'previous_api_url': 'edxnotes.org/?course_id=abc&page=2&page_size=10&text=wow&user=123', 'next_api_url': 'edxnotes.org/?course_id=abc&page=4&page_size=10&text=wow&user=123'})
def test_construct_url(self, previous_api_url, next_api_url):

    if self.request.is_secure():
        host = ('https://' + self.request.get_host())
    else:
        host = ('http://' + self.request.get_host())
    notes_url = (host + reverse('notes', args=[unicode(self.course.id)]))
    def verify_url(constructed, expected):
        '\n                                                Verify    that    constructed    url    is    correct.\n                                                '
        if (expected is None):
            self.assertEqual(expected, constructed)
        else:
            self.assertTrue(constructed.startswith(notes_url))
            self.assertNotIn('user', constructed)
            allowed_params = ('page', 'page_size', 'text')
            parsed = urlparse.urlparse(constructed)
            params = urlparse.parse_qs(parsed.query)
            for (param, value) in params.items():
                self.assertIn(param, allowed_params)
                self.assertIn('{}={}'.format(param, value[0]), expected)
    (next_url, previous_url) = helpers.construct_pagination_urls(self.request, self.course.id, next_api_url, previous_api_url)
    verify_url(next_url, next_api_url)
    verify_url(previous_url, previous_api_url)
