def setUp(self):
        # Usage:
        #       Constructor for TestDB, TestURLGenerator,which is used for setting
        # Arguments:
        #       None

        # Need to call parent's setup
        super(TestURLGenerator, self).setUp()

        # Create a url generator
        self.url_generator = AsyncRandomURLGenerator()
class TestURLGenerator(AsyncTestCase):
    #   Usage:
    #       Tests for the random url generator. This class inherits from the
    #       AsyncTestCase class in order to test coroutines, and futures.

    def setUp(self):
        # Usage:
        #       Constructor for TestDB, TestURLGenerator,which is used for setting
        # Arguments:
        #       None

        # Need to call parent's setup
        super(TestURLGenerator, self).setUp()

        # Create a url generator
        self.url_generator = AsyncRandomURLGenerator()

    @tornado.testing.gen_test
    def test_00_url_generated_length(self):
        # Usage:
        #       Test Case to determine if the url is in generated length
        # Arguments:
        #       None

        # Generate a new URL
        url = yield self.url_generator.generate_url()

        # Test to see if the generated path is equal to the length defined in
        # random_url_settings.py
        self.assertEqual(len(urlparse.urlsplit(url).path.split("/")[-1]),
                         length_url)

    @tornado.testing.gen_test
    def test_01_change_to_url(self):
        # Usage:
        #       Test Case to determine if the url is in generated length
        # Arguments:
        #       None

        # Change the last path to something else
        change_to_url = "Dummy"

        # Generate a new URL
        url = yield self.url_generator.generate_url(change_to_url)

        # Test to see if the generated path is equal to the length defined in
        # random_url_settings.py
        self.assertEqual(
            urlparse.urlsplit(url).path.split("/")[-1], change_to_url)
Beispiel #3
0
def create_application(url_generator=AsyncRandomURLGenerator(),
                       db=AsyncMomokoDBQueryExecutor(),
                       cursor_parser=AsyncSQLDataParser(),
                       logger=log,
                       executor=executors,
                       url_shortener_path=router_settings.url_shortener_path):
    return tornado.web.Application(
        [
            # Map the "/" url to main handler
            (r"/url_gen", URLGenHandler,
             dict(url_generator=url_generator,
                  db=db,
                  cursor_parser=cursor_parser,
                  url_shortener=url_shortener_path,
                  logger=logger)),
            (r'^%s\w+' % url_shortener_path, URLRedirectHandler,
             dict(db=db, cursor_parser=cursor_parser, logger=logger)),
            (r'^/url_latest_100', URLLatest100Handler,
             dict(db=db,
                  cursor_parser=cursor_parser,
                  executor=executor,
                  logger=logger)),
            (r'^/url_top_10_domain_30_days', URLTop10Domain30Days,
             dict(db=db, cursor_parser=cursor_parser, logger=logger)),
            (r'^/url_info', URLGetURLInfo,
             dict(db=db, cursor_parser=cursor_parser, logger=logger))
        ],
        **settings)
class TestURLGenerator(AsyncTestCase):
    #   Usage:
    #       Tests for the random url generator. This class inherits from the
    #       AsyncTestCase class in order to test coroutines, and futures.

    def setUp(self):
        # Usage:
        #       Constructor for TestDB, TestURLGenerator,which is used for setting
        # Arguments:
        #       None

        # Need to call parent's setup
        super(TestURLGenerator, self).setUp()

        # Create a url generator
        self.url_generator = AsyncRandomURLGenerator()

    @tornado.testing.gen_test
    def test_00_url_generated_length(self):
        # Usage:
        #       Test Case to determine if the url is in generated length
        # Arguments:
        #       None

        # Generate a new URL
        url = yield self.url_generator.generate_url()

        # Test to see if the generated path is equal to the length defined in
        # random_url_settings.py
        self.assertEqual(len(urlparse.urlsplit(url).path.split("/")[-1]), length_url)

    @tornado.testing.gen_test
    def test_01_change_to_url(self):
        # Usage:
        #       Test Case to determine if the url is in generated length
        # Arguments:
        #       None

        # Change the last path to something else
        change_to_url = "Dummy"

        # Generate a new URL
        url = yield self.url_generator.generate_url(change_to_url)

        # Test to see if the generated path is equal to the length defined in
        # random_url_settings.py
        self.assertEqual(urlparse.urlsplit(url).path.split("/")[-1], change_to_url)
    def setUp(self):
        # Usage:
        #       Constructor for TestDB, TestURLGenerator,which is used for setting
        # Arguments:
        #       None

        # Need to call parent's setup
        super(TestURLGenerator, self).setUp()

        # Create a url generator
        self.url_generator = AsyncRandomURLGenerator()