Skip to content

Commit 0c47166

Browse files
author
aronysidoro
committed
update example project
1 parent 6faf0d7 commit 0c47166

File tree

10 files changed

+131
-21
lines changed

10 files changed

+131
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.egg-info
33
*.coverage
44
sqlite.db
5+
db.sqlite3
56
*~
67
.tmp*
78
build

CHANGELOG.rst

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=========
2+
CHANGELOG
3+
=========
4+
5+
**2015-06-11**
6+
7+
- requirements
8+
- created 1 requirements file under ``examples/chatserver/requirements.txt``
9+
10+
- tests
11+
- renamed chatclient.py to test_chatclient.py - for django-nose testrunner
12+
13+
- django 1.7
14+
- migrated example project to django 1.7
15+
16+
- docs
17+
- edited ``docs/testing.rst`` to show new changes for using example project

TODO.txt

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
* Use >100 greenlets when running the unit test. This shall take no longer than 1 second.
77

88
* Add prototype methods such as select() to base class, which raise a NotImplementedError.
9+
10+
* Fix broken tests with examples/chatserver
11+
- 7/12 tests passing

docs/testing.rst

+19-7
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,35 @@ the SQLite database
1111

1212
.. code-block:: bash
1313
14-
./manage.py syncdb
15-
Creating tables ...
16-
...
17-
Would you like to create one now? (yes/no): yes
18-
Username (leave blank to use 'johndoe'):
19-
...
14+
# create python2 virtualenv
15+
virtualenv - p /path/to/python2 /path/to/virtualenv
16+
17+
# activate virtualenv
18+
source /path/to/virtualenv/bin/activate
19+
20+
# pip
21+
pip install /django-websocket/redis/examples/chatserver/requirements.txt
22+
23+
# Django 1.7+
24+
# Load test data
25+
./manage.py loaddata chatserver/fixtures/data.json # if needed
26+
./manage.py makemigrations
27+
./manage.py migrate
2028
2129
and then start the server
2230

2331
.. code-block:: bash
2432
33+
# start Redis Server
34+
# (or follow quickstart instructions http://redis.io/topics/quickstart)
35+
36+
# start Django
2537
./manage.py runserver
2638
2739
Point a browser onto http://localhost:8000/admin/, login and add additional users. Enable their
2840
staff status, so that they can use the admin interface to log into the testing application.
2941

30-
With http://localhost:8000/userchat/ you can send messages to specific users, provided they are
42+
With http://localhost:8000/chat/ you can send messages to specific users, provided they are
3143
logged in. To log in as another user, use Django's admin interface.
3244

3345
Simple Broadcasting

examples/chatserver/settings.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Django settings for unit test project.
22
import os
33

4+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
5+
46
DEBUG = True
57

8+
TEMPLATE_DEBUG = True
9+
10+
ALLOWED_HOSTS = []
11+
612
DATABASES = {
713
'default': {
814
'ENGINE': 'django.db.backends.sqlite3',
9-
'NAME': 'sqlite.db',
10-
},
15+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
16+
}
1117
}
1218

1319
SITE_ID = 1
@@ -49,13 +55,26 @@
4955
'django.template.loaders.app_directories.Loader',
5056
)
5157

52-
TIME_ZONE = 'Europe/Berlin'
58+
# Internationalization
59+
# https://docs.djangoproject.com/en/1.7/topics/i18n/
60+
61+
LANGUAGE_CODE = 'en-us'
62+
63+
TIME_ZONE = 'UTC'
64+
65+
USE_I18N = True
66+
67+
USE_L10N = True
68+
69+
USE_TZ = True
70+
5371

5472
INSTALLED_APPS = (
73+
'django.contrib.admin',
5574
'django.contrib.auth',
5675
'django.contrib.contenttypes',
5776
'django.contrib.sessions',
58-
'django.contrib.admin',
77+
'django.contrib.messages',
5978
'django.contrib.staticfiles',
6079
'ws4redis',
6180
'chatserver',
@@ -64,10 +83,13 @@
6483
# These two middleware classes must be present, if messages sent or received through a websocket
6584
# connection shall be delivered to an authenticated Django user.
6685
MIDDLEWARE_CLASSES = (
67-
'django.middleware.csrf.CsrfViewMiddleware',
6886
'django.contrib.sessions.middleware.SessionMiddleware',
87+
'django.middleware.common.CommonMiddleware',
88+
'django.middleware.csrf.CsrfViewMiddleware',
6989
'django.contrib.auth.middleware.AuthenticationMiddleware',
90+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
7091
'django.contrib.messages.middleware.MessageMiddleware',
92+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
7193
)
7294

7395
# This setting is required to override the Django's main loop, when running in

examples/chatserver/tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
from .chatclient import *
2+
from .test_chatclient import *

examples/chatserver/tests/requirements.txt

-5
This file was deleted.

examples/chatserver/tests/settings.py

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# Django settings for unit test project.
2+
import os
3+
4+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
25

36
DEBUG = True
47

8+
TEMPLATE_DEBUG = True
9+
10+
ALLOWED_HOSTS = []
11+
512
DATABASES = {
613
'default': {
714
'ENGINE': 'django.db.backends.sqlite3',
8-
'NAME': 'database.sqlite',
9-
},
15+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
16+
}
1017
}
1118

1219
SITE_ID = 1
@@ -32,18 +39,44 @@
3239
# Example: "http://media.lawrence.com/static/"
3340
STATIC_URL = '/static/'
3441

42+
SESSION_ENGINE = 'redis_sessions.session'
43+
44+
SESSION_REDIS_PREFIX = 'session'
45+
46+
TEMPLATE_CONTEXT_PROCESSORS = (
47+
'django.contrib.auth.context_processors.auth',
48+
'django.core.context_processors.static',
49+
'django.core.context_processors.request',
50+
'ws4redis.context_processors.default',
51+
)
52+
3553
# List of callables that know how to import templates from various sources.
3654
TEMPLATE_LOADERS = (
3755
'django.template.loaders.app_directories.Loader',
3856
)
3957

58+
# Internationalization
59+
# https://docs.djangoproject.com/en/1.7/topics/i18n/
60+
61+
LANGUAGE_CODE = 'en-us'
62+
63+
TIME_ZONE = 'UTC'
64+
65+
USE_I18N = True
66+
67+
USE_L10N = True
68+
69+
USE_TZ = True
70+
71+
4072
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
4173

4274
INSTALLED_APPS = (
75+
'django.contrib.admin',
4376
'django.contrib.auth',
4477
'django.contrib.contenttypes',
4578
'django.contrib.sessions',
46-
'django.contrib.admin',
79+
'django.contrib.messages',
4780
'django.contrib.staticfiles',
4881
'django_nose',
4982
'ws4redis',
@@ -54,8 +87,12 @@
5487
# connection shall be delivered to an authenticated Django user.
5588
MIDDLEWARE_CLASSES = (
5689
'django.contrib.sessions.middleware.SessionMiddleware',
90+
'django.middleware.common.CommonMiddleware',
91+
'django.middleware.csrf.CsrfViewMiddleware',
5792
'django.contrib.auth.middleware.AuthenticationMiddleware',
93+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
5894
'django.contrib.messages.middleware.MessageMiddleware',
95+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
5996
)
6097

6198
# This setting is required to override the Django's main loop, when running in

examples/chatserver/tests/chatclient.py renamed to examples/chatserver/tests/test_chatclient.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# -*- coding: utf-8 -*-
22
import time
33
import requests
4+
from django.conf import settings
45
from django.contrib.auth.models import User
56
from django.contrib.sessions.backends.db import SessionStore
67
from django.test import LiveServerTestCase
78
from django.test.client import RequestFactory
9+
from django.utils.importlib import import_module
810
from websocket import create_connection, WebSocketException
911
from ws4redis.django_runserver import application
1012
from ws4redis.publisher import RedisPublisher
@@ -24,6 +26,14 @@ def setUp(self):
2426
self.websocket_base_url = self.live_server_url.replace('http:', 'ws:', 1) + u'/ws/' + self.facility
2527
self.message = RedisMessage(''.join(unichr(c) for c in range(33, 128)))
2628
self.factory = RequestFactory()
29+
# SessionStore
30+
# as used here: http://stackoverflow.com/a/7722483/1913888
31+
settings.SESSION_ENGINE = 'redis_sessions.session'
32+
engine = import_module(settings.SESSION_ENGINE)
33+
store = engine.SessionStore()
34+
store.save()
35+
self.session = store
36+
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
2737

2838
@classmethod
2939
def tearDownClass(cls):

examples/requirements.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Django==1.7.8
2+
backports.ssl-match-hostname==3.4.0.2
3+
django-nose==1.4
4+
django-redis-sessions==0.4.0
5+
django-websocket-redis==0.4.4
6+
gevent==1.0.2
7+
greenlet==0.4.7
8+
nose==1.3.7
9+
redis==2.10.3
10+
requests==2.7.0
11+
six==1.9.0
12+
websocket-client==0.13.0
13+
wsgiref==0.1.2

0 commit comments

Comments
 (0)