aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2015-08-03 10:51:03 -0500
committerAndy Doan <andy.doan@linaro.org>2015-08-24 12:52:09 -0500
commitb2fae238aea6f6bf5dafeabdcf8504107477daa2 (patch)
treec9fe2b6b3512153c3f9678eed4f2b80e87dc0787
parent57c8878f3fefc5d8d483b19d0a04e1547958ef23 (diff)
downloadlinaro-license-protection-b2fae238aea6f6bf5dafeabdcf8504107477daa2.tar.gz
s3: start a v3 api
To keep things simple, this is just the "token" portion of our API which isn't changing for v3. Change-Id: I9ba3b0b7ae9c132b2b5dd2704653702884b0246d
-rw-r--r--license_protected_downloads/api/v3.py4
-rw-r--r--license_protected_downloads/tests/__init__.py1
-rw-r--r--license_protected_downloads/tests/test_api_v3.py38
-rw-r--r--urls.py3
4 files changed, 46 insertions, 0 deletions
diff --git a/license_protected_downloads/api/v3.py b/license_protected_downloads/api/v3.py
new file mode 100644
index 0000000..b84a446
--- /dev/null
+++ b/license_protected_downloads/api/v3.py
@@ -0,0 +1,4 @@
+from license_protected_downloads.api import v2
+
+# no changes required for tokens in v3
+token = v2.token
diff --git a/license_protected_downloads/tests/__init__.py b/license_protected_downloads/tests/__init__.py
index de81959..87541c5 100644
--- a/license_protected_downloads/tests/__init__.py
+++ b/license_protected_downloads/tests/__init__.py
@@ -2,6 +2,7 @@
from license_protected_downloads.tests.test_buildinfo import *
from license_protected_downloads.tests.test_api_v1 import *
from license_protected_downloads.tests.test_api_v2 import *
+from license_protected_downloads.tests.test_api_v3 import *
from license_protected_downloads.tests.test_common import *
from license_protected_downloads.tests.test_custom_commands import *
from license_protected_downloads.tests.test_models import *
diff --git a/license_protected_downloads/tests/test_api_v3.py b/license_protected_downloads/tests/test_api_v3.py
new file mode 100644
index 0000000..e3bb40c
--- /dev/null
+++ b/license_protected_downloads/tests/test_api_v3.py
@@ -0,0 +1,38 @@
+import datetime
+import json
+
+from django.test import Client, TestCase
+
+from license_protected_downloads.models import (
+ APIKeyStore,
+ APIToken,
+)
+
+
+class APIv3TokenTests(TestCase):
+ '''A subset of token tests since this *should* just be v2 token code'''
+ def setUp(self):
+ self.client = Client(enforce_csrf_checks=True)
+ self.api_key = APIKeyStore.objects.create(key='foo', public=True)
+
+ def test_token_no_auth(self):
+ resp = self.client.get('/api/v3/token/')
+ self.assertEqual(401, resp.status_code)
+
+ def test_token_list(self):
+ keys = 3
+ for x in range(keys):
+ APIToken.objects.create(key=self.api_key)
+
+ resp = self.client.get(
+ '/api/v3/token/', HTTP_AUTHTOKEN=self.api_key.key)
+ self.assertEqual(200, resp.status_code)
+ tokens = json.loads(resp.content)
+ self.assertEqual(keys, len(tokens))
+
+ def test_token_create(self):
+ expires = datetime.datetime.now() + datetime.timedelta(minutes=1)
+ data = {'expires': expires.isoformat()}
+ resp = self.client.post(
+ '/api/v3/token/', data=data, HTTP_AUTHTOKEN=self.api_key.key)
+ self.assertEqual(201, resp.status_code)
diff --git a/urls.py b/urls.py
index 8399ee9..dfd14c9 100644
--- a/urls.py
+++ b/urls.py
@@ -65,6 +65,9 @@ urlpatterns = patterns(
url(r'^api/v2/link_latest/(?P<path>.*)$',
'license_protected_downloads.api.v2.link_latest'),
+ url(r'^api/v3/token/(?P<token>.*)$',
+ 'license_protected_downloads.api.v3.token'),
+
# Catch-all. We always return a file (or try to) if it exists.
# This handler does that.
url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),