Ejemplo n.º 1
0
    def test_resolve_url_hits_counter(self):
        tables = ShortenerTables(self.account, self.conn)
        yield tables.create_tables()

        url = 'http://en.wikipedia.org/wiki/Cthulhu'
        yield self.service.shorten_url(url)

        yield self.service.get_row_by_short_url('qr0')
        yield self.service.get_row_by_short_url('qr0')
        result = yield self.service.get_row_by_short_url('qr0')

        audit = yield tables.get_audit_row(result['id'])
        self.assertEqual(audit['hits'], 3)
Ejemplo n.º 2
0
    def init_account(self, request):
        '''
        Initializes the account and creates the database tables
        '''
        conn = yield self.engine.connect()
        account = self.config['account']
        tables = ShortenerTables(account, conn)
        try:
            already_exists = yield tables.exists()
            if not already_exists:
                yield tables.create_tables()
        finally:
            yield conn.close()

        returnValue({'created': not already_exists})
Ejemplo n.º 3
0
    def init_account(self, request):
        '''
        Initializes the account and creates the database tables
        '''
        conn = yield self.engine.connect()
        account = self.config['account']
        tables = ShortenerTables(account, conn)
        try:
            already_exists = yield tables.exists()
            if not already_exists:
                yield tables.create_tables()
        finally:
            yield conn.close()

        returnValue({'created': not already_exists})
Ejemplo n.º 4
0
    def test_get_or_create_row(self):
        tables = ShortenerTables('test-account', self.conn)
        yield tables.create_tables()

        row = yield tables.get_or_create_row(
            'wiki.org', 'test', 'http://wiki.org/test/')
        self.assertEqual(row['domain'], 'wiki.org')
        self.assertEqual(row['short_url'], None)
        self.assertEqual(row['user_token'], 'test')
        self.assertEqual(row['long_url'], 'http://wiki.org/test/')
        self.assertEqual(row['id'], 1)

        row = yield tables.get_or_create_row(
            'wiki.org', 'test', 'http://wiki.org/test/')
        self.assertEqual(row['id'], 1)

        audit = yield tables.get_audit_row(1)
        self.assertEqual(audit['hits'], 0)
Ejemplo n.º 5
0
    def test_get_or_create_row(self):
        tables = ShortenerTables('test-account', self.conn)
        yield tables.create_tables()

        row = yield tables.get_or_create_row('wiki.org', 'test',
                                             'http://wiki.org/test/')
        self.assertEqual(row['domain'], 'wiki.org')
        self.assertEqual(row['short_url'], None)
        self.assertEqual(row['user_token'], 'test')
        self.assertEqual(row['long_url'], 'http://wiki.org/test/')
        self.assertEqual(row['id'], 1)

        row = yield tables.get_or_create_row('wiki.org', 'test',
                                             'http://wiki.org/test/')
        self.assertEqual(row['id'], 1)

        audit = yield tables.get_audit_row(1)
        self.assertEqual(audit['hits'], 0)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
 def test_tables_create(self):
     tables = ShortenerTables('test-account', self.conn)
     self.successResultOf(tables.create_tables())
Ejemplo n.º 9
0
 def test_tables_create(self):
     tables = ShortenerTables('test-account', self.conn)
     self.successResultOf(tables.create_tables())