# Path: protector/tests/fixtures/loader.py
# def load_fixture(name):
#     path = os.path.dirname(os.path.abspath(__file__))
#     urls_file = "{}/{}".format(path, name)
#     return open(urls_file)
# 
# Path: protector/urlhandler/urlhandler.py
# class UrlHandler(object):
#     @staticmethod
#     def get_query(url):
#         parsed = urlparse(url)
#         parameters = parse_qs(parsed.query)
#         if 'q' in parameters:
#             return ''.join(parameters['q'])
#         return None


import unittest
from protector.tests.fixtures.loader import load_fixture
from protector.urlhandler.urlhandler import UrlHandler


class TestUrlHandler(unittest.TestCase):
    def test_url_handling(self):
        """
        Test URL parameter handling
        """
        self.assertIsNone(UrlHandler.get_query(""))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com"))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com/"))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com/bla=1"))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com?bla=1"))
        self.assertEqual(UrlHandler.get_query("http://www.example.com?q=1"), '1')
        self.assertIsNone(UrlHandler.get_query("http://example.com/over/there?name=ferret"))
        self.assertEqual(UrlHandler.get_query("http://example.com/over/there?q=ferret"), 'ferret')
        self.assertIsNone(UrlHandler.get_query("http://www.example.com/dff&q=1"))
        self.assertEqual(UrlHandler.get_query("http://www.example.com/?q=1"), '1')

    def test_query_extraction(self):
        """
        Test extraction of query from URL
        """
        urls = load_fixture("sample_urls.txt")

# Path: protector/tests/fixtures/loader.py
# def load_fixture(name):
#     path = os.path.dirname(os.path.abspath(__file__))
#     urls_file = "{}/{}".format(path, name)
#     return open(urls_file)
# 
# Path: protector/urlhandler/urlhandler.py
# class UrlHandler(object):
#     @staticmethod
#     def get_query(url):
#         parsed = urlparse(url)
#         parameters = parse_qs(parsed.query)
#         if 'q' in parameters:
#             return ''.join(parameters['q'])
#         return None


# Path: protector/tests/urlhandler_test/test_urlhandler.py
import unittest
from protector.tests.fixtures.loader import load_fixture
from protector.urlhandler.urlhandler import UrlHandler



class TestUrlHandler(unittest.TestCase):
    def test_url_handling(self):
        """
        Test URL parameter handling
        """
        self.assertIsNone(UrlHandler.get_query(""))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com"))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com/"))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com/bla=1"))
        self.assertIsNone(UrlHandler.get_query("http://www.example.com?bla=1"))
        self.assertEqual(UrlHandler.get_query("http://www.example.com?q=1"), '1')
        self.assertIsNone(UrlHandler.get_query("http://example.com/over/there?name=ferret"))
        self.assertEqual(UrlHandler.get_query("http://example.com/over/there?q=ferret"), 'ferret')
        self.assertIsNone(UrlHandler.get_query("http://www.example.com/dff&q=1"))
        self.assertEqual(UrlHandler.get_query("http://www.example.com/?q=1"), '1')

    def test_query_extraction(self):
        """
        Test extraction of query from URL
        """
        urls = load_fixture("sample_urls.txt")

        queries = load_fixture("sample_queries.txt")