Skip to content

Commit

Permalink
make tests work with the new comment schema
Browse files Browse the repository at this point in the history
  • Loading branch information
armish committed Sep 2, 2015
1 parent b585a95 commit d5bac7d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
6 changes: 2 additions & 4 deletions cycledash/api/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ def get(self, run_id):
with tables(db.engine, 'user_comments') as (con, comments):
q = select(comments.c).where(
comments.c.vcf_id == run_id).order_by(desc(comments.c.id))
return [userify_comments(dict(c) for c in q.execute().fetchall())]
return [dict(c) for c in q.execute().fetchall()]

@validate_with(CreateComment)
@marshal_with(CommentFields)
def post(self, run_id):
"""Create a comment."""
print current_user

with tables(db.engine, 'user_comments') as (con, comments):
q = comments.insert().values(
vcf_id=run_id,
Expand Down Expand Up @@ -232,4 +230,4 @@ def _get_comment(comment_table, id=None, **query_kwargs):
for colname, val in query_kwargs.items():
q = q.where(comment_table.c[colname] == val)
comment = q.execute().fetchone()
return userify_comment(dict(abort_if_none_for('comment')(comment, id)))
return dict(abort_if_none_for('comment')(comment, id))
1 change: 1 addition & 0 deletions tests/js/ExaminePage-comments-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('ExaminePage Comments', function() {
return TestUtils.renderIntoDocument(
<ExaminePage recordStore={recordStore}
recordActions={recordActions}
currentUser={Utils.fakeCurrentUser()}
igvHttpfsUrl={igvHttpfsUrl}
vcf={run} comparableVcfs={[]} />);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/js/ExaminePage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function renderExamine(fakeServer) {
created_at: '',
uri: '/tests/data/snv.vcf'
};

var igvHttpfsUrl = ''; // not needed

var dispatcher = new Dispatcher(),
Expand All @@ -38,6 +39,7 @@ function renderExamine(fakeServer) {
recordActions={recordActions}
igvHttpfsUrl={igvHttpfsUrl}
vcf={run}
currentUser={Utils.fakeCurrentUser()}
comparableVcfs={[]} />);
}

Expand Down
1 change: 1 addition & 0 deletions tests/js/IGVLink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('IGV Links', function() {

it('should display load/jump initially', function() {
var commentBox = renderCommentBox({
currentUser: Utils.fakeCurrentUser(),
selectedRow: 0,
hasOpenedIGV: false
});
Expand Down
12 changes: 11 additions & 1 deletion tests/js/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ function mapValues(o, fn) {
});
}

function fakeCurrentUser() {
return {
username: 'currentUser',
email: 'current@user.com',
id: 1,
password: 'dummy'
};
}

module.exports = {
findInComponent,
makeObj,
mapValues,
stubReactMethod
stubReactMethod,
fakeCurrentUser
};
10 changes: 3 additions & 7 deletions tests/python/test_comments_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def create_comment_with_text(run_id, text):
'contig': 'chr101',
'position': 909090,
'reference': 'Q',
'alternates': 'WHOA'
'alternates': 'WHOA',
'user_id': None
}).returning(*comments.c).execute()
return dict(res.fetchone())


class TestCommentsAPI(helpers.ResourceTest):
@classmethod
def setUpClass(cls):
Expand All @@ -43,14 +43,12 @@ def test_create_comment(self):
'position': 123,
'reference': 'C',
'alternates': 'A,G',
'commentText': comment_text,
'authorName': 'Tester McGee'})
'commentText': comment_text})
data = json.loads(r.data)
assert r.status_code == 201
assert isinstance(json.loads(r.data)['id'], int)
assert data['vcfId'] == self.run['id']
assert data['sampleName'] == 'samp'
assert data['authorName'] == 'Tester McGee'
assert data['commentText'] == comment_text
assert data['reference'] == 'C'
assert data['alternates'] == 'A,G'
Expand Down Expand Up @@ -84,12 +82,10 @@ def test_update_comment(self):
comment = create_comment_with_text(self.run['id'], 'some text')
r = self.put('/api/runs/{}/comments/{}'.format(self.run['id'], comment['id']),
data={'commentText': new_text,
'authorName': new_author,
'last_modified': to_epoch(comment['last_modified'])})
assert r.status_code == 200
assert json.loads(r.data)['id'] == comment['id']
assert json.loads(r.data)['commentText'] == new_text
assert json.loads(r.data)['authorName'] == new_author

def test_update_comment_without_timestamp(self):
comment = create_comment_with_text(self.run['id'], 'some text')
Expand Down

0 comments on commit d5bac7d

Please sign in to comment.