Skip to content

Commit

Permalink
pytest stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
markmcdowall committed Jul 3, 2017
1 parent 90b64cd commit 4f566b8
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Copyright 2017 EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import sys
import os

BASEDIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, BASEDIR + '/../')

from rest import app
61 changes: 61 additions & 0 deletions test/test_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
.. Copyright 2017 EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import print_function

import os
import tempfile
import json
import pytest

from context import app

@pytest.fixture
def client(request):
"""
Definges the client object to make requests against
"""
db_fd, app.APP.config['DATABASE'] = tempfile.mkstemp()
app.APP.config['TESTING'] = True
client = app.APP.test_client()

def teardown():
"""
Close the client once testing has completed
"""
os.close(db_fd)
os.unlink(app.APP.config['DATABASE'])
request.addfinalizer(teardown)

return client

def test_endpoints(client):
"""
Test that the root endpoint is returning the expected keys
"""
rest_value = client.get('/mug/api/3dcoord')
details = json.loads(rest_value.data)
#print(details)
assert '_links' in details

def test_ping(client):
"""
Test that the ping function is returning the status key
"""
rest_value = client.get('/mug/api/3dcoord/ping')
details = json.loads(rest_value.data)
#print(details)
assert 'status' in details

0 comments on commit 4f566b8

Please sign in to comment.