Ejemplo n.º 1
0
def get_vcf_comments(vcf_id):
    """Return all user comments in the following format:

    {
      "comments": {
        "<row_key STRING>": [<comment_fields>, ...],
        "<row_key STRING>": [...], ...
      }
    }
    """
    def _row_key(comment, table):
        cols = ['contig', 'position', 'reference', 'alternates', 'sample_name']
        return ':'.join([str(comment[col]) for col in cols])

    with tables(db.engine, 'user_comments') as (conn, user_comments):
        cols = user_comments.c
        stmt = select(cols.values()).where(cols.vcf_id == vcf_id)
        results = conn.execute(stmt)
        results_map = defaultdict(list)
        for comment in (dict(c) for c in results):
            row_key = _row_key(comment, user_comments)
            comment['last_modified'] = to_epoch(comment['last_modified'])
            comment['created'] = to_epoch(comment['created'])
            comment = camelcase_dict(comment)
            results_map[row_key].append(comment)
    return {'comments': results_map}
Ejemplo n.º 2
0
 def test_delete_with_out_of_date_timestamp(self):
     comment = create_comment_with_text(self.run['id'], 'some text')
     now = datetime.datetime.now()
     r = self.delete('/api/runs/{}/comments/{}'.format(self.run['id'], comment['id']),
                      data={'lastModified': to_epoch(now)})
     assert r.status_code == 409
     assert 'out of date' in json.loads(r.data)['message']
Ejemplo n.º 3
0
 def test_delete_comment(self):
     comment = create_comment_with_text(self.run['id'], 'some text')
     r = self.delete('/api/runs/{}/comments/{}'.format(self.run['id'], comment['id']),
                         data={'lastModified': to_epoch(comment['last_modified'])})
     assert r.status_code == 200
     assert json.loads(r.data)['id'] == comment['id']
     r = self.get('/api/runs/{}/comments/{}'.format(self.run['id'], comment['id']))
     assert r.status_code == 404
Ejemplo n.º 4
0
def _ensure_not_out_of_date(comment, last_modified):
    """Assert that the comment has the same last_modified time,
    otherwise abort(409).
    """
    current_time = to_epoch(comment['last_modified'])
    if current_time != last_modified:
        abort(409, message=('Comment id={} is out of date.'
                            .format(comment['id'])),
              current_time=current_time)
Ejemplo n.º 5
0
 def test_update_with_out_of_date_timestamp(self):
     comment = create_comment_with_text(self.run["id"], "some text")
     now = datetime.datetime.now()
     r = self.put(
         "/api/runs/{}/comments/{}".format(self.run["id"], comment["id"]),
         data={"commentText": "blah", "lastModified": to_epoch(now)},
     )
     assert r.status_code == 409
     assert "out of date" in json.loads(r.data)["message"]
Ejemplo n.º 6
0
 def test_delete_comment(self):
     comment = create_comment_with_text(self.run["id"], "some text")
     r = self.delete(
         "/api/runs/{}/comments/{}".format(self.run["id"], comment["id"]),
         data={"lastModified": to_epoch(comment["last_modified"])},
     )
     assert r.status_code == 200
     assert json.loads(r.data)["id"] == comment["id"]
     r = self.get("/api/runs/{}/comments/{}".format(self.run["id"], comment["id"]))
     assert r.status_code == 404
Ejemplo n.º 7
0
 def test_update_comment(self):
     new_text = 'NEW TEXT!'
     new_author = 'NEW AUTHOR!'
     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,
                        '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
Ejemplo n.º 8
0
 def test_update_comment(self):
     new_text = "NEW TEXT!"
     new_author = "NEW AUTHOR!"
     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
Ejemplo n.º 9
0
def epochify_comments(comments):
    """Sets `lastModified` and `created` to be epoch time instead of iso8061."""
    for c in comments:
        c['lastModified'] = to_epoch(c['lastModified'])
        c['created'] = to_epoch(c['created'])
    return comments
Ejemplo n.º 10
0
 def format(self, value):
     return to_epoch(value)