Beispiel #1
0
    def get_row_by_short_url(self, short_url):
        account = self.config['account']
        conn = yield self.engine.connect()
        try:
            tables = ShortenerTables(account, conn)

            row = yield tables.get_row_by_short_url(short_url)
            returnValue(row)
        finally:
            yield conn.close()
Beispiel #2
0
    def get_row_by_short_url(self, short_url):
        account = self.config['account']
        conn = yield self.engine.connect()
        try:
            tables = ShortenerTables(account, conn)

            row = yield tables.get_row_by_short_url(short_url)
            returnValue(row)
        finally:
            yield conn.close()
    def test_resolve_url(self):
        tables = ShortenerTables('test-account', self.conn)
        yield tables.create_tables()

        yield tables.get_or_create_row(
            'wiki.org', 'test', 'http://wiki.org/test/')
        yield tables.update_short_url(1, 'aaa')

        row = yield tables.get_row_by_short_url('aaa')

        self.assertEqual(row['domain'], 'wiki.org')
        self.assertEqual(row['short_url'], 'aaa')
        self.assertEqual(row['id'], 1)

        audit = yield tables.get_audit_row(1)
        self.assertEqual(audit['hits'], 1)

        #multiple hits
        for i in range(0, 10):
            yield tables.get_row_by_short_url('aaa')

        audit = yield tables.get_audit_row(1)
        self.assertEqual(audit['hits'], 11)
    def test_resolve_url(self):
        tables = ShortenerTables('test-account', self.conn)
        yield tables.create_tables()

        yield tables.get_or_create_row('wiki.org', 'test',
                                       'http://wiki.org/test/')
        yield tables.update_short_url(1, 'aaa')

        row = yield tables.get_row_by_short_url('aaa')

        self.assertEqual(row['domain'], 'wiki.org')
        self.assertEqual(row['short_url'], 'aaa')
        self.assertEqual(row['id'], 1)

        audit = yield tables.get_audit_row(1)
        self.assertEqual(audit['hits'], 1)

        #multiple hits
        for i in range(0, 10):
            yield tables.get_row_by_short_url('aaa')

        audit = yield tables.get_audit_row(1)
        self.assertEqual(audit['hits'], 11)
Beispiel #5
0
    def render(self, request):
        short_url = request.args.get('url')
        conn = yield self.engine.connect()
        try:
            tables = ShortenerTables(self.config['account'], conn)
            if not short_url:
                request.setResponseCode(http.BAD_REQUEST)
                returnValue({'error': 'expected "?url=<short_url>"'})
            else:
                row = yield tables.get_row_by_short_url(short_url[0], False)

                if row:
                    audit = yield tables.get_audit_row(row['id'])
                    returnValue(self._format(row, audit))
                else:
                    request.setResponseCode(http.NOT_FOUND)
                    returnValue({'error': 'short url not found'})
        finally:
            yield conn.close()