--- /dev/null
+"""
+Define some alternate authentication methods
+"""
+from django.core.exceptions import PermissionDenied
+
+from htsworkflow.frontend import settings
+
+apidata = {'apiid': u'0', 'apikey': settings.DEFAULT_API_KEY}
+
+def require_api_key(request):
+ # make sure we have the api component
+ if not (request.REQUEST.has_key('apiid') or request.REQUEST.has_key('apikey')):
+ raise PermissionDenied
+
+ # make sure the id and key are right
+ if request.REQUEST['apiid'] == apidata['apiid'] and \
+ request.REQUEST['apikey'] == apidata['apikey']:
+ return True
+ else:
+ raise PermissionDenied
+
+
from htsworkflow.frontend import settings
from htsworkflow.frontend.experiments.models import FlowCell, DataRun
from htsworkflow.frontend.samples.models import Library
+from htsworkflow.frontend.auth import require_api_key
def flowcell_information(flowcell_id):
"""
'lane_number': int(lane.lane_number),
'library_name': lane.library.library_name,
'library_id': lane.library.library_id,
+ 'library_species': lane.library.library_species.scientific_name,
'pM': float(lane.pM),
}
info = {
return info
-@login_required
def flowcell_json(request, fc_id):
"""
Return a JSON blob containing enough information to generate a config file.
"""
+ require_api_key(request)
+
fc_dict = flowcell_information(fc_id)
if fc_dict is None:
"library_name": "Paired End Pfl #3 MP 7/24/9 a",
"creation_date": "2009-08-06",
"cell_line": 1,
- "library_species": 22,
+ "library_species": 2,
"library_type": 2,
"made_by": "Lorian",
"affiliations": [
from django.test import TestCase
from htsworkflow.frontend.experiments import models
from htsworkflow.frontend.experiments import experiments
+from htsworkflow.frontend.auth import apidata
class ExperimentsTestCases(TestCase):
fixtures = ['test_flowcells.json']
self.failUnlessEqual(lane_dict['library_name'], lane.library.library_name)
self.failUnlessEqual(lane_dict['library_id'], lane.library.library_id)
self.failUnlessAlmostEqual(lane_dict['pM'], float(lane.pM))
+ self.failUnlessEqual(lane_dict['library_species'],
+ lane.library.library_species.scientific_name)
- self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
- response = self.client.get('/experiments/config/%s/json' % (fc_id,))
+ response = self.client.get('/experiments/config/%s/json' % (fc_id,), apidata)
# strptime isoformat string = '%Y-%m-%dT%H:%M:%S'
fc_json = json.loads(response.content)
self.failUnlessEqual(fc_json['flowcell_id'], fc_id)
self.failUnlessEqual(lane_dict['library_name'], lane.library.library_name)
self.failUnlessEqual(lane_dict['library_id'], lane.library.library_id)
self.failUnlessAlmostEqual(lane_dict['pM'], float(lane.pM))
+ self.failUnlessEqual(lane_dict['library_species'],
+ lane.library.library_species.scientific_name)
def test_invalid_flowcell(self):
"""
Make sure we get a 404 if we request an invalid flowcell ID
"""
- self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
- response = self.client.get('/experiments/config/nottheone/json')
+ response = self.client.get('/experiments/config/nottheone/json', apidata)
self.failUnlessEqual(response.status_code, 404)
- def test_not_logged_in(self):
+ def test_no_key(self):
"""
Require logging in to retrieve meta data
"""
response = self.client.get(u'/experiments/config/303TUAAXX/json')
- self.failUnlessEqual(response.status_code, 302)
+ self.failUnlessEqual(response.status_code, 403)
def test_library_id(self):
"""
Library IDs should be flexible, so make sure we can retrive a non-numeric ID
"""
- self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
- response = self.client.get('/experiments/config/303TUAAXX/json')
+ response = self.client.get('/experiments/config/303TUAAXX/json', apidata)
self.failUnlessEqual(response.status_code, 200)
flowcell = json.loads(response.content)
self.failUnlessEqual(flowcell['lane_set']['3']['library_id'], 'SL039')
- response = self.client.get('/samples/library/SL039/json')
+ response = self.client.get('/samples/library/SL039/json', apidata)
self.failUnlessEqual(response.status_code, 200)
library_sl039 = json.loads(response.content)
self.failUnlessEqual(library_sl039['library_id'], 'SL039')
+
+#class RetriveConfigTestCases(TestCase):
+# fixtures = ['test_flowcells.json']
"name": "Multiplexed"
}
},
- {
- "model": "samples.Species",
- "pk": 1,
- "fields": {
- "scientific_name": "Mus musculus",
- "common_name": "mouse"
- }
- },
{
"model": "samples.Species",
"pk": 2,
"common_name": ""
}
},
+ {
+ "model": "samples.Species",
+ "pk": 6,
+ "fields": {
+ "scientific_name": "Arabidopsis thaliana"
+ }
+ },
{
"model": "samples.Species",
"pk": 8,
"scientific_name": "Homo sapiens",
"common_name": ""
}
+ },
+ {
+ "model": "samples.Species",
+ "pk": 9,
+ "fields": {
+ "scientific_name": "Mus musculus",
+ "common_name": "mouse"
+ }
+ },
+ {
+ "model": "samples.Species",
+ "pk": 10,
+ "fields": {
+ "scientific_name": "Strongylocentrotus purpuratus"
+ }
}
-
]
"library_name": "Paired End Pfl #3 MP 7/24/9 a",
"creation_date": "2009-08-06",
"cell_line": 1,
- "library_species": 1,
+ "library_species": 9,
"library_type": 2,
"made_by": "Lorian",
"affiliations": [
"library_name": "Paired End Pfl #3 MP 7/24/9",
"creation_date": "2009-08-05",
"cell_line": 1,
- "library_species": 1,
+ "library_species": 8,
"library_type": 2,
"made_by": "Lorian",
"affiliations": [
library_dict, \
library_json
+from htsworkflow.frontend.auth import apidata
+
# The django test runner flushes the database between test suites not cases,
# so to be more compatible with running via nose we flush the database tables
# of interest before creating our sample data.
for lib in Library.objects.all():
lib_dict = library_dict(lib.library_id)
- self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
url = '/samples/library/%s/json' % (lib.library_id,)
- lib_response = self.client.get(url)
+ lib_response = self.client.get(url, apidata)
self.failUnlessEqual(lib_response.status_code, 200)
lib_json = json.loads(lib_response.content)
"""
Make sure we get a 404 if we request an invalid library id
"""
- self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
- response = self.client.get('/samples/library/nottheone/json')
+ response = self.client.get('/samples/library/nottheone/json', apidata)
self.failUnlessEqual(response.status_code, 404)
- def test_library_not_logged_in(self):
+ def test_library_no_key(self):
"""
Make sure we get a 302 if we're not logged in
"""
response = self.client.get('/samples/library/10981/json')
- self.failUnlessEqual(response.status_code, 302)
- self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
- response = self.client.get('/samples/library/10981/json')
+ self.failUnlessEqual(response.status_code, 403)
+ response = self.client.get('/samples/library/10981/json', apidata)
self.failUnlessEqual(response.status_code, 200)
except ImportError, e:
import simplejson as json
+from htsworkflow.frontend.auth import require_api_key
from htsworkflow.frontend.experiments.models import FlowCell
from htsworkflow.frontend.samples.changelist import ChangeList
from htsworkflow.frontend.samples.models import Library
info['library_type'] = lib.library_type.name
return info
-@login_required
def library_json(request, library_id):
"""
Return a json formatted library dictionary
"""
+ require_api_key(request)
# what validation should we do on library_id?
lib = library_dict(library_id)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '(ekv^=gf(j9f(x25@a7r+8)hqlz%&_1!tw^75l%^041#vi=@4n'
+# some of our urls need an api key
+DEFAULT_API_KEY = 'n7HsXGHIi0vp9j5u4TIRJyqAlXYc4wrH'
+
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',