Skip to content

Commit

Permalink
Merge branch 'feature/issue-5-use-yaml-config' of github.com:praekelt…
Browse files Browse the repository at this point in the history
…/url-shortening-service into feature/issue-6-push-metrics-to-graphite
  • Loading branch information
miltontony committed Mar 11, 2014
2 parents d66b7b3 + f1e4986 commit e8e46ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ install:
before_script:
- psql -c 'create database shortener_test;' -U postgres
script:
- trial shortener
- SHORTENER_TEST_CONNECTION_STRING='postgresql://postgres@localhost:5432/shortener_test' coverage run --source=shortener `which trial` shortener
after_success:
- coveralls
29 changes: 21 additions & 8 deletions shortener/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from aludel.database import MetaData
from shortener.api import ShortenerServiceApp
from shortener.models import ShortenerTables


class TestShortenerServiceApp(TestCase):
Expand All @@ -28,9 +29,10 @@ def setUp(self):
connection_string = os.environ.get(
"SHORTENER_TEST_CONNECTION_STRING", "sqlite://")

self.account = 'test-account'
cfg = {
'host_domain': 'http://wtxt.io',
'account': 'milton-test-account',
'account': self.account,
'connection_string': connection_string,
}
self.pool = HTTPConnectionPool(reactor, persistent=False)
Expand All @@ -41,13 +43,7 @@ def setUp(self):
site = Site(self.service.app.resource())
self.listener = reactor.listenTCP(0, site, interface='localhost')
self.listener_port = self.listener.getHost().port
self._drop_tables()
self.conn = yield self.service.engine.connect()
yield treq.get(
self.make_url('/api/init'),
allow_redirects=False,
pool=self.pool
)
self.addCleanup(self.listener.loseConnection)
self.addCleanup(self.pool.closeCachedConnections)

Expand All @@ -62,6 +58,8 @@ def make_url(self, path):

@inlineCallbacks
def test_create_url_simple(self):
yield ShortenerTables(self.account, self.conn).create_tables()

payload = {
'long_url': 'foo',
'user_token': 'bar',
Expand All @@ -77,6 +75,8 @@ def test_create_url_simple(self):

@inlineCallbacks
def test_create_url_no_user_token(self):
yield ShortenerTables(self.account, self.conn).create_tables()

payload = {
'long_url': 'foo'
}
Expand All @@ -91,6 +91,8 @@ def test_create_url_no_user_token(self):

@inlineCallbacks
def test_resolve_url_simple(self):
yield ShortenerTables(self.account, self.conn).create_tables()

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

Expand All @@ -105,6 +107,8 @@ def test_resolve_url_simple(self):

@inlineCallbacks
def test_resolve_url_404(self):
yield ShortenerTables(self.account, self.conn).create_tables()

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

Expand All @@ -117,12 +121,16 @@ def test_resolve_url_404(self):

@inlineCallbacks
def test_url_shortening(self):
yield ShortenerTables(self.account, self.conn).create_tables()

long_url = 'http://en.wikipedia.org/wiki/Cthulhu'
short_url = yield self.service.shorten_url(long_url)
self.assertEqual(short_url, 'http://wtxt.io/qr0')

@inlineCallbacks
def test_short_url_generation(self):
yield ShortenerTables(self.account, self.conn).create_tables()

url = 'http://en.wikipedia.org/wiki/Cthulhu'
url1 = yield self.service.shorten_url(url + '1')
url2 = yield self.service.shorten_url(url + '2')
Expand All @@ -133,6 +141,8 @@ def test_short_url_generation(self):

@inlineCallbacks
def test_repeat_url_generation(self):
yield ShortenerTables(self.account, self.conn).create_tables()

url = 'http://en.wikipedia.org/wiki/Cthulhu'
url1 = yield self.service.shorten_url(url + '1')
url2 = yield self.service.shorten_url(url + '2')
Expand All @@ -143,6 +153,8 @@ def test_repeat_url_generation(self):

@inlineCallbacks
def test_resolve_url(self):
yield ShortenerTables(self.account, self.conn).create_tables()

url = 'http://en.wikipedia.org/wiki/Cthulhu'
yield self.service.shorten_url(url + '1')
yield self.service.shorten_url(url + '2')
Expand All @@ -154,6 +166,8 @@ def test_resolve_url(self):

@inlineCallbacks
def test_short_url_sequencing(self):
yield ShortenerTables(self.account, self.conn).create_tables()

url = 'http://en.wikipedia.org/wiki/Cthulhu'
urls = [''.join([url, str(a)]) for a in range(1, 10)]
for u in urls:
Expand All @@ -167,7 +181,6 @@ def test_short_url_sequencing(self):

@inlineCallbacks
def test_account_init(self):
self._drop_tables()
resp = yield treq.get(
self.make_url('/api/init'),
allow_redirects=False,
Expand Down

0 comments on commit e8e46ec

Please sign in to comment.