Commits

RafRaf committed f0d7f4a

Tests added + new README file

Comments (0)

Files changed (2)

 Installation
 
 1. Install the package into your ecosystem
-    >> easy_install django_poll_system 
+    >> easy_install django_poll_system
+    or
+    >> pip install django_poll_system
 
 
-2. Add it to your INSTALLED_APPS (in settings.py), like this:
+2. Add it to your INSTALLED_APPS (in settings.py). Example:
 
 INSTALLED_APPS = (
 'django.contrib.auth',
 
 3. Add the poll's url to your urls.py.
 
-from django.conf.urls.defaults import patterns, include, url
-
-from django.contrib import admin
-from django.contrib.staticfiles.urls import staticfiles_urlpatterns
-from views import TestView
-
-admin.autodiscover()
+...
 
 urlpatterns = patterns('',
-    url(r'^$', TestView.as_view(), name='home'),
-    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
-    url(r'^admin/', include(admin.site.urls)),
+    ...
 
     url(r'^poll/', include('poll.urls')),
 )
 
-urlpatterns += staticfiles_urlpatterns()
 
-
-4. Your TEMPLATE_CONTEXT_PROCESSORS (in settings.py) should looks like this:
+4. Your TEMPLATE_CONTEXT_PROCESSORS (in settings.py) should look like this:
 
 TEMPLATE_CONTEXT_PROCESSORS = (
     # Uncomment for Django 1.3
 ) 
 
 
-4. Eventually we need to do "syncdb".
+5. Run "syncdb" command:
    >> python manage.py syncdb
 
 
-5. Now installation is completed. After all you need to create a queue of polls and at least one poll for it.  
+6. Create some queues and polls through the admin panel.
 
 
-6. Insert the component into your page. Use the code snippet below to understand how to do that.  
+7. Insert the component into your page using a queue title. Use the code snippet below to understand how to do that.  
 
 {% load polls_tags %}
 <html>
 
 
 ================================
-That's all. Try it: http://polltest.pythonism.ru. (Please, leave your comments there)
+That's all. Example: http://polltest.pythonism.ru.
+from django.test import TestCase
+from poll.models import Poll, Queue, Vote
+from django.utils.datetime_safe import datetime
+from django.test.client import Client
+from django.core.urlresolvers import reverse
+
+
+class PollTest(TestCase):
+    def setUp(self):
+        self.queue = Queue(title='TestQueue',
+                           auth=False)
+        self.queue.save()
+        self.poll = Poll(title='TestPoll',
+                         queue=self.queue,
+                         polltype=0,
+                         startdate=datetime.now())
+        self.poll.save()
+        self.item = self.poll.item_set.create(userbox=False,
+                                              value='One',
+                                              index=0)
+        self.client = Client()
+    
+    def test_voting(self):
+        request = self.client.post(
+                    reverse('poll_ajax_vote',
+                            args=(self.poll.pk,)),
+                            {'chosen_items': '{"%s": "radio"}'\
+                                                    % (self.item.id,)},
+                            HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+        self.assertEqual(request.status_code, 200)
+        self.assertEqual(Vote.objects.count(), 1)