Skip to content

Commit

Permalink
add restapi to get all crosslinks
Browse files Browse the repository at this point in the history
  • Loading branch information
xzheng902 committed Aug 7, 2019
1 parent a77a291 commit cf0979c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bcforms/core.py
Expand Up @@ -1929,7 +1929,7 @@ def get_structure(self):
atom_type[i_atom] = atom+n_atoms[i_subunit]
atom_maps.append(atom_map)

print(atom_maps)
# print(atom_maps)

for atom_map in atom_maps:
for subunit_map in atom_map.values():
Expand Down
30 changes: 30 additions & 0 deletions bcforms/rest.py
Expand Up @@ -209,5 +209,35 @@ def post(self):

return ret

xlink_ns = flask_restplus.Namespace('crosslink', description='List crosslinks and get information about crosslinks')
api.add_namespace(xlink_ns)

@xlink_ns.route("/")
@xlink_ns.doc(params={})

class CrosslinkResource(flask_restplus.Resource):
""" Get crosslinks """

def get(self):
""" Get crosslinks
Returns:
:obj:`dict`: dictionary representation of all crosslinks
"""
return get_crosslinks()


@bcforms.core.cache.memoize(typed=False, expire=30 * 24 * 60 * 60)
def get_crosslinks():
""" Get an alphabet
Returns:
:obj:`dict`: dictionary representation of crosslinks
"""

crosslink_dict = dict(bcforms.core.parse_yaml(bcforms.core._xlink_filename))

return crosslink_dict

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
6 changes: 6 additions & 0 deletions tests/test_rest.py
Expand Up @@ -456,3 +456,9 @@ def test_get_bcform_properties_errors(self):
]
})
self.assertEqual(rv.status_code, 400)

def test_get_crosslinks(self):

client = rest.app.test_client()
rv = client.get('/api/crosslink/')
self.assertEqual(rv.status_code, 200)

0 comments on commit cf0979c

Please sign in to comment.