1. Vladimyr Pavlenko
  2. tdd-django

Commits

Vladimyr Pavlenko  committed 4966e46

End Part 1

  • Participants
  • Parent commits a3b142f
  • Branches master

Comments (0)

Files changed (10)

File mysite/database.sqlite

Binary file added.

File mysite/fts/fixtures/admin_user.json

View file
+[
+  {
+    "pk": 1, 
+    "model": "auth.user", 
+    "fields": {
+      "username": "masha", 
+      "first_name": "", 
+      "last_name": "", 
+      "is_active": true, 
+      "is_superuser": true, 
+      "is_staff": true, 
+      "last_login": "2012-11-05T08:08:54.561Z", 
+      "groups": [], 
+      "user_permissions": [], 
+      "password": "pbkdf2_sha256$10000$4VquJ5JtczM2$se8O95qhr1YpjPCufxtiA1k2eMUVlSNCMviKyUSrjJ4=", 
+      "email": "masha@examples.com", 
+      "date_joined": "2012-11-05T08:08:54.561Z"
+    }
+  }
+]

File mysite/fts/tests.py

View file
 from django.test import LiveServerTestCase
 from selenium import webdriver
+from selenium.webdriver.common.keys import Keys
 
 class PollsTest(LiveServerTestCase):
+    fixtures = ['admin_user.json']
+
 
     def setUp(self):
         self.browser = webdriver.Firefox()
         body = self.browser.find_element_by_tag_name('body')
         self.assertIn('Django administration', body.text)
 
+        # She types her name and password and type RETURN
+        username_field = self.browser.find_element_by_name('username')
+        username_field.send_keys('masha')
+        password_field = self.browser.find_element_by_name('password')
+        password_field.send_keys('1')
+        password_field.send_keys(Keys.RETURN)
+
+        # her username and password are accepted, and she is taken to
+        # the Site Administration page
+        body = self.browser.find_element_by_tag_name('body')
+        self.assertIn('Site administration', body.text)
+
+        # She now sees a couple of hyperlink that says "Polls"
+        polls_links = self.browser.find_elements_by_link_text('Polls')
+        self.assertEquals(len(polls_links), 2)
+
         # TODO: use the admin site to create a Poll
         self.fail('finish this test')

File mysite/mysite/settings.py

View file
     'django.contrib.messages',
     'django.contrib.staticfiles',
     # Uncomment the next line to enable the admin:
-    # 'django.contrib.admin',
+    'django.contrib.admin',
     # Uncomment the next line to enable admin documentation:
     # 'django.contrib.admindocs',
-    "fts"
+    "fts",
+    "polls"
 )
 
 # A sample logging configuration. The only tangible logging

File mysite/mysite/urls.py

View file
 from django.conf.urls import patterns, include, url
-
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
+from django.contrib import admin
+admin.autodiscover()
 
 urlpatterns = patterns('',
     # Examples:
     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
 
     # Uncomment the next line to enable the admin:
-    # url(r'^admin/', include(admin.site.urls)),
+    url(r'^admin/', include(admin.site.urls)),
 )

File mysite/polls/__init__.py

Empty file added.

File mysite/polls/admin.py

View file
+# -*- encoding: utf-8 -*-
+
+__author__ = 'ds'
+
+from django.contrib import admin
+from polls.models import Poll
+
+admin.site.register(Poll)

File mysite/polls/models.py

View file
+from django.db import models
+
+class Poll(models.Model):
+    question = models.CharField(max_length=200)
+    pub_date = models.DateTimeField()

File mysite/polls/tests.py

View file
+from django.test import TestCase
+from django.utils import timezone
+from polls.models import Poll
+
+class PollModelTest(TestCase):
+
+    def test_creating_a_new_poll_and_saving_it_into_database(self):
+        poll = Poll()
+        poll.question = "What's up?"
+        poll.pub_date = timezone.now()
+
+        poll.save()
+
+        all_polls_in_database = Poll.objects.all()
+        self.assertEquals(len(all_polls_in_database), 1)
+
+        only_poll_in_database = all_polls_in_database[0]
+        self.assertEquals(only_poll_in_database, poll)
+
+        self.assertEquals(only_poll_in_database.question, "What's up?")
+        self.assertEquals(only_poll_in_database.pub_date, poll.pub_date)

File mysite/polls/views.py

View file
+# Create your views here.