Browse Source

update example project

check_code_closing_websocket_python2
aronysidoro 6 years ago
parent
commit
0c47166fca
10 changed files with 131 additions and 21 deletions
  1. +1
    -0
      .gitignore
  2. +17
    -0
      CHANGELOG.rst
  3. +3
    -0
      TODO.txt
  4. +19
    -7
      docs/testing.rst
  5. +27
    -5
      examples/chatserver/settings.py
  6. +1
    -1
      examples/chatserver/tests/__init__.py
  7. +0
    -5
      examples/chatserver/tests/requirements.txt
  8. +40
    -3
      examples/chatserver/tests/settings.py
  9. +10
    -0
      examples/chatserver/tests/test_chatclient.py
  10. +13
    -0
      examples/requirements.txt

+ 1
- 0
.gitignore View File

@ -2,6 +2,7 @@
*.egg-info
*.coverage
sqlite.db
db.sqlite3
*~
.tmp*
build


+ 17
- 0
CHANGELOG.rst View File

@ -0,0 +1,17 @@
=========
CHANGELOG
=========
**2015-06-11**
- requirements
- created 1 requirements file under ``examples/chatserver/requirements.txt``
- tests
- renamed chatclient.py to test_chatclient.py - for django-nose testrunner
- django 1.7
- migrated example project to django 1.7
- docs
- edited ``docs/testing.rst`` to show new changes for using example project

+ 3
- 0
TODO.txt View File

@ -6,3 +6,6 @@
* Use >100 greenlets when running the unit test. This shall take no longer than 1 second.
* Add prototype methods such as select() to base class, which raise a NotImplementedError.
* Fix broken tests with examples/chatserver
- 7/12 tests passing

+ 19
- 7
docs/testing.rst View File

@ -11,23 +11,35 @@ the SQLite database
.. code-block:: bash
./manage.py syncdb
Creating tables ...
...
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'johndoe'):
...
# create python2 virtualenv
virtualenv - p /path/to/python2 /path/to/virtualenv
# activate virtualenv
source /path/to/virtualenv/bin/activate
# pip
pip install /django-websocket/redis/examples/chatserver/requirements.txt
# Django 1.7+
# Load test data
./manage.py loaddata chatserver/fixtures/data.json # if needed
./manage.py makemigrations
./manage.py migrate
and then start the server
.. code-block:: bash
# start Redis Server
# (or follow quickstart instructions http://redis.io/topics/quickstart)
# start Django
./manage.py runserver
Point a browser onto http://localhost:8000/admin/, login and add additional users. Enable their
staff status, so that they can use the admin interface to log into the testing application.
With http://localhost:8000/userchat/ you can send messages to specific users, provided they are
With http://localhost:8000/chat/ you can send messages to specific users, provided they are
logged in. To log in as another user, use Django's admin interface.
Simple Broadcasting


+ 27
- 5
examples/chatserver/settings.py View File

@ -1,13 +1,19 @@
# Django settings for unit test project.
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'sqlite.db',
},
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
SITE_ID = 1
@ -49,13 +55,26 @@ TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
)
TIME_ZONE = 'Europe/Berlin'
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
'django.contrib.staticfiles',
'ws4redis',
'chatserver',
@ -64,10 +83,13 @@ INSTALLED_APPS = (
# These two middleware classes must be present, if messages sent or received through a websocket
# connection shall be delivered to an authenticated Django user.
MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
# This setting is required to override the Django's main loop, when running in


+ 1
- 1
examples/chatserver/tests/__init__.py View File

@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from .chatclient import *
from .test_chatclient import *

+ 0
- 5
examples/chatserver/tests/requirements.txt View File

@ -1,5 +0,0 @@
six
nose
django-nose
websocket-client==0.13.0
requests

+ 40
- 3
examples/chatserver/tests/settings.py View File

@ -1,12 +1,19 @@
# Django settings for unit test project.
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'database.sqlite',
},
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
SITE_ID = 1
@ -32,18 +39,44 @@ STATIC_ROOT = '/home/static/'
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
SESSION_ENGINE = 'redis_sessions.session'
SESSION_REDIS_PREFIX = 'session'
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.static',
'django.core.context_processors.request',
'ws4redis.context_processors.default',
)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
)
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_nose',
'ws4redis',
@ -54,8 +87,12 @@ INSTALLED_APPS = (
# connection shall be delivered to an authenticated Django user.
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
# This setting is required to override the Django's main loop, when running in


examples/chatserver/tests/chatclient.py → examples/chatserver/tests/test_chatclient.py View File


+ 13
- 0
examples/requirements.txt View File

@ -0,0 +1,13 @@
Django==1.7.8
backports.ssl-match-hostname==3.4.0.2
django-nose==1.4
django-redis-sessions==0.4.0
django-websocket-redis==0.4.4
gevent==1.0.2
greenlet==0.4.7
nose==1.3.7
redis==2.10.3
requests==2.7.0
six==1.9.0
websocket-client==0.13.0
wsgiref==0.1.2

Loading…
Cancel
Save