Skip to content

Commit

Permalink
start AudioAnnotationTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon committed Dec 18, 2014
1 parent aea4f89 commit 506a188
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from models import db


class TestCase(TestCase):
class RankoTestCase(TestCase):
def create_app(self):
return create_app(config_file='conf/testing.py')

Expand All @@ -23,9 +23,20 @@ def tearDown(self):
db.session.remove()
# db.drop_all()

def test_home(self):
r = self.client.get('/')
self.assertIn('Upload and review', r.data)
def _login(self, username, password, signup=False):
if signup:
self._signup(username, password)
return self.client.post('/login', data=dict(
username=username,
password=password
), follow_redirects=True)

def _signup(self, username, password):
return self.client.post('/signup', data=dict(
username=username,
password=password,
confirm=password
), follow_redirects=True)

def _upload(self, filename, title=None):
storage = FileStorage(filename=filename, stream=BytesIO())
Expand All @@ -40,6 +51,18 @@ def _new_upload_id(self, filename):
docid = self._extract_docid(r)
return koremutake.decode(docid)

def _extract_docid(self, r):
m = re.search('/view/(\w+)', r.location)
self.assertIsNotNone(m)
docid = m.group(1)
return docid


class DocTestCase(RankoTestCase):
def test_home(self):
r = self.client.get('/')
self.assertIn('Upload and review', r.data)

def test_upload(self):
r = self._login('a', 'a', signup=True)
r = self._upload('toto.pdf')
Expand Down Expand Up @@ -139,12 +162,6 @@ def test_annotation(self):
d = json.loads(r.data)
self.assertNotIn('2', d['data'])

def _extract_docid(self, r):
m = re.search('/view/(\w+)', r.location)
self.assertIsNotNone(m)
docid = m.group(1)
return docid

def test_upload_rev(self):
r = self._upload('toto.pdf')
docid = self._extract_docid(r)
Expand All @@ -166,21 +183,6 @@ def test_upload_rev(self):
for docb in [docid, docid2]:
self.assertIn(docb, r.data)

def _signup(self, username, password):
return self.client.post('/signup', data=dict(
username=username,
password=password,
confirm=password
), follow_redirects=True)

def _login(self, username, password, signup=False):
if signup:
self._signup(username, password)
return self.client.post('/login', data=dict(
username=username,
password=password
), follow_redirects=True)

def _logout(self):
return self.client.get('/logout', follow_redirects=True)

Expand Down Expand Up @@ -328,3 +330,15 @@ def _can_comment_on(self, docid):
follow_redirects=True,
)
return r.status_code == 200

class AudioAnnotationTestCase(RankoTestCase):
def test_create_audio_annotation(self):
self._login('a', 'a', signup=True)
docid = self._new_upload_id('x.mp3')
data = {'doc': docid,
'start': 1,
'length': 2,
'text': "Bla",
}
r = self.client.post(url_for('audioann.audioann_new'), data=data)
self.assert200(r)

0 comments on commit 506a188

Please sign in to comment.