-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 326f0f7
Showing
24 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# pyvenv | ||
bin/ | ||
*.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: python | ||
python: | ||
- 3.4 | ||
|
||
install: | ||
- pip install -r requirements.txt | ||
- pip install coveralls | ||
|
||
script: | ||
coverage run --source=ember_index setup.py test | ||
|
||
after_success: | ||
coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Jan Bobisud | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include LICENSE | ||
include README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
PY := bin/python | ||
PY_VERSION := $(shell ${PY} --version 2>&1 | cut -f 2 -d ' ') | ||
|
||
APP := ember_index | ||
COVERAGE := bin/coverage-3.4 | ||
|
||
|
||
coverage: | ||
${COVERAGE} run --source=${APP} setup.py test | ||
${COVERAGE} report | ||
|
||
test: | ||
${PY} setup.py test | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Django Ember Index | ||
|
||
A Django app to serve an [Ember](http://emberjs.com) index files deployed with [ember-cli-deploy](https://github.com/ember-cli/ember-cli-deploy). | ||
|
||
## Installation | ||
|
||
1. Install application using `$ pip install django-ember-index`. | ||
|
||
2. Add `ember_index` to your `INSTALLED_APPS` setting like this: | ||
|
||
```python | ||
INSTALLED_APPS = ( | ||
... | ||
'ember_index', | ||
) | ||
``` | ||
|
||
3. Register Ember application at `urls.py` with [redis](http://redis.io)'s adapter: | ||
|
||
```python | ||
from ember_index.adapters import RedisAdapter | ||
from ember_index.conf.urls import index | ||
|
||
urlpatterns = [ | ||
index(r'^', 'my-app', RedisAdapter()), | ||
] | ||
``` | ||
|
||
_All keyword arguments will be passed into the [StrictRedis](https://redis-py.readthedocs.org/en/latest/#redis.StrictRedis) object on initialization._ | ||
|
||
## License | ||
|
||
Django Ember Index is available under the MIT license. See the LICENSE file for more info. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .redis import RedisAdapter | ||
|
||
|
||
__all__ = ['RedisAdapter'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from redis import Redis | ||
|
||
|
||
class RedisAdapter(object): | ||
|
||
def __init__(self, **kwargs): | ||
self.redis = Redis(**kwargs) | ||
|
||
def index_for(self, key): | ||
return self.redis.get(key) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.conf.urls import include, url | ||
|
||
from ember_index.views import IndexView | ||
|
||
|
||
def index(regex, manifest, adapter, view_class=IndexView): | ||
view = view_class.as_view(manifest=manifest, adapter=adapter) | ||
return url(regex, include([ | ||
url(r'^r/(?P<revision>\w+)', view), | ||
url(r'^', view) | ||
])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.http import HttpResponse, HttpResponseNotFound | ||
from django.views.generic import View | ||
|
||
|
||
class IndexView(View): | ||
|
||
http_method_names = ['get', 'head', 'options'] | ||
|
||
manifest = None | ||
adapter = None | ||
|
||
def get(self, request, revision='current'): | ||
index_key = self.index_key(self.manifest, revision) | ||
index = self.adapter.index_for(index_key) | ||
|
||
if not index: | ||
return self.index_not_found(self.manifest, revision) | ||
|
||
index = self.process_index(index) | ||
return self.index_response(index) | ||
|
||
def head(self, request, revision='current'): | ||
response = self.get(request, revision) | ||
response.content = b'' | ||
return response | ||
|
||
def index_key(self, manifest, revision): | ||
return ':'.join([manifest, revision]) | ||
|
||
def index_response(self, index): | ||
return HttpResponse(index) | ||
|
||
def index_not_found(self, manifest, revision): | ||
content = 'No index found for revision `{1}` of the manifest `{0}`.' | ||
return HttpResponseNotFound(content.format(manifest, revision)) | ||
|
||
def process_index(self, index): | ||
return index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Django==1.8.0 | ||
redis==2.10.3 | ||
coverage==3.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
from setuptools import setup | ||
|
||
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme: | ||
README = readme.read() | ||
|
||
# allow setup.py to be run from any path | ||
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) | ||
|
||
setup( | ||
name='django-ember-index', | ||
version='0.1.0', | ||
packages=['ember_index'], | ||
include_package_data=True, | ||
test_suite='tests.runner.run_tests', | ||
license='MIT License', | ||
description='A Django app to serve an Ember index files.', | ||
long_description=README, | ||
url='https://github.com/bobisjan/django-ember-index', | ||
author='Jan Bobisud', | ||
author_email='me@bobisjan.com', | ||
classifiers=[ | ||
'Environment :: Web Environment', | ||
'Framework :: Django', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.2', | ||
'Programming Language :: Python :: 3.3', | ||
'Topic :: Internet :: WWW/HTTP', | ||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content', | ||
], | ||
) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.test import Client, SimpleTestCase | ||
|
||
|
||
class GetIndexTestCase(SimpleTestCase): | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
def test_should_get_current_index(self): | ||
response = self.client.get('/') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
self.assertTrue('7fabf72' in response.content.decode('utf-8')) | ||
|
||
response = self.client.get('/abc/def') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
self.assertTrue('7fabf72' in response.content.decode('utf-8')) | ||
|
||
def test_should_get_specific_index(self): | ||
response = self.client.get('/r/d696248') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
self.assertTrue('d696248' in response.content.decode('utf-8')) | ||
|
||
response = self.client.get('/r/d696248/') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
self.assertTrue('d696248' in response.content.decode('utf-8')) | ||
|
||
response = self.client.get('/r/d696248/abc/def') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
self.assertTrue('d696248' in response.content.decode('utf-8')) | ||
|
||
def test_should_get_not_found_for_non_existing_index(self): | ||
response = self.client.get('/r/aaaaaa') | ||
self.assertEqual(response.status_code, 404) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
|
||
response = self.client.get('/r/aaaaaa/') | ||
self.assertEqual(response.status_code, 404) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') | ||
|
||
response = self.client.get('/r/aaaaaa/abc/def') | ||
self.assertEqual(response.status_code, 404) | ||
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.test import Client, SimpleTestCase | ||
|
||
|
||
class HeadIndexTestCase(SimpleTestCase): | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
def test_should_head_current_index(self): | ||
response = self.client.head('/') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(response.content) | ||
|
||
def test_should_head_specific_index(self): | ||
response = self.client.head('/r/d696248') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(response.content) | ||
|
||
def test_should_head_not_found_for_non_existing_index(self): | ||
response = self.client.head('/r/aaaaaa') | ||
self.assertEqual(response.status_code, 404) | ||
self.assertFalse(response.content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Adapter(object): | ||
|
||
indices = { | ||
'my-app:ed54cda': '<html><body><h1>ed54cda</h1></body></html>', | ||
'my-app:d696248': '<html><body><h1>d696248</h1></body></html>', | ||
'my-app:7fabf72': '<html><body><h1>7fabf72</h1></body></html>', | ||
'my-app:current': '<html><body><h1>7fabf72</h1></body></html>', | ||
} | ||
|
||
def index_for(self, key): | ||
return self.indices.get(key, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import sys | ||
|
||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
TESTS_DIR = os.path.join(BASE_DIR, 'tests') | ||
|
||
sys.path.insert(0, TESTS_DIR) | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') | ||
|
||
|
||
import django | ||
from django.test.utils import get_runner | ||
from django.conf import settings | ||
|
||
|
||
def run_tests(): | ||
runner_class = get_runner(settings) | ||
test_runner = runner_class(pattern='*.py', verbosity=1, interactive=True) | ||
django.setup() | ||
|
||
failures = test_runner.run_tests(['unit', 'acceptance']) | ||
sys.exit(bool(failures)) | ||
|
||
|
||
if __name__ == '__main__': | ||
run_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
INSTALLED_APPS = ( | ||
'ember_index', | ||
) | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'testdb', | ||
} | ||
} | ||
|
||
ROOT_URLCONF = 'urls' | ||
|
||
SECRET_KEY = 'a1b2c3d4' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import inspect | ||
from unittest import TestCase | ||
|
||
from ember_index.adapters import RedisAdapter | ||
|
||
|
||
class AdaptersTestCase(TestCase): | ||
|
||
def test_should_export_redis_adapter(self): | ||
self.assertTrue(inspect.isclass(RedisAdapter)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from ember_index.conf.urls import index | ||
|
||
from fixtures import Adapter | ||
|
||
|
||
urlpatterns = [ | ||
index(r'^', 'my-app', Adapter()), | ||
] |