Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions _chapters/chp03/django_ecommerce/main/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,40 @@ def test_index_handles_logged_in_user(self):
'user.html', {'user': user_mock.get_by_id(1)}
)
self.assertEquals(resp.content, expected_html.content)



class User(models.Model):

name = model.CharField()
pwd = model.CharField()
birthdate = model.DateField()

def get_sign():
if birthdate.month == "Jan":
return "Capricorn"
elif birthdate.monty == "Feb"
return "Sagitarius"

def is_active_twitter_user():
# call twitter with
# is user.name a user on twitter
is_active = twitter.check_user(user.name)
return is_active


def test_get_sign()
myuser = User("jj", "pwd", "Jan")
self.assertEquals(myuser.get_sign(), "Capricorn")

myuser = User("jj", "pwd", "Feb")
self.assertEquals(myuser.get_sign(), "Sagitarius")

myuser = User("jj", "pwd", "32")
self.assertEquals(myuser.get_sign(), "Sagitarius")




--- test.py

Binary file modified _chapters/chp03/django_ecommerce/test.db
Binary file not shown.
7 changes: 2 additions & 5 deletions _chapters/chp06/django_ecommerce/contact/models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from django.db import models
import datetime


class ContactForm(models.Model):
name = models.CharField(max_length=150)
email = models.EmailField(max_length=250)
topic = models.CharField(max_length=200)
message = models.CharField(max_length=1000)
timestamp = models.DateTimeField(
auto_now_add=True, default=datetime.datetime.now
)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
def __unicode__(self):
return self.email

class Meta:
Expand Down
37 changes: 19 additions & 18 deletions _chapters/chp06/django_ecommerce/django_ecommerce/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
SITE_ROOT = os.path.dirname(PROJECT_ROOT)
STRIPE_SECRET = 'sk_test_4QBquf6d5EzsnJC1fTI2GBGm'
STRIPE_PUBLISHABLE = 'pk_test_4QBqqGvCk9gaNn3pl1cwxcAS'

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
Expand All @@ -19,12 +16,8 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db',
'USER': 'djangousr',
'PASSWORD': 'your_password_here',
'HOST': 'localhost',
'PORT': '5432',
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db'
}
}

Expand Down Expand Up @@ -88,13 +81,6 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = '!(1ty%c5a)0l0(p)kxl2igmbobx_64hqh&tv1=+s9@!@zez4o^'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -111,8 +97,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'django_ecommerce.wsgi.application'

TEMPLATE_DIRS = (os.path.join(SITE_ROOT, 'templates'),)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -157,3 +141,20 @@
},
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(SITE_ROOT, 'templates'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'debug': True,
},
},
]
13 changes: 8 additions & 5 deletions _chapters/chp06/django_ecommerce/django_ecommerce/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from payments import views
from django.contrib import admin
from main.views import index as main_index
from contact.views import contact

admin.autodiscover()

urlpatterns = patterns('',
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'main.views.index', name='home'),
url(r'^$', main_index, name='home'),
url(r'^pages/', include('django.contrib.flatpages.urls')),
url(r'^contact/', 'contact.views.contact', name='contact'),
url(r'^contact/', contact, name='contact'),

# user registration/authentication
url(r'^sign_in$', views.sign_in, name='sign_in'),
url(r'^sign_out$', views.sign_out, name='sign_out'),
url(r'^register$', views.register, name='register'),
url(r'^edit$', views.edit, name='edit'),
)
]
Empty file modified _chapters/chp06/django_ecommerce/manage.py
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions _chapters/chp06/django_ecommerce/payments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class CardForm(PaymentForm):


class UserForm(CardForm):

name = forms.CharField(required=True)
email = forms.EmailField(required=True)
password = forms.CharField(
required=True,
label=('Password'),
label=(u'Password'),
widget=forms.PasswordInput(render_value=False)
)
ver_password = forms.CharField(
required=True,
label=(' Verify Password'),
label=(u' Verify Password'),
widget=forms.PasswordInput(render_value=False)
)

Expand Down
25 changes: 12 additions & 13 deletions _chapters/chp06/django_ecommerce/payments/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.db import IntegrityError
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from payments.forms import SigninForm, CardForm, UserForm
from payments.models import User
import django_ecommerce.settings as settings
Expand Down Expand Up @@ -33,15 +32,15 @@ def sign_in(request):
else:
form = SigninForm()

print(form.non_field_errors())
print form.non_field_errors()

return render_to_response(
return render(
request,
'sign_in.html',
{
'form': form,
'user': user
},
context_instance=RequestContext(request)
)


Expand Down Expand Up @@ -92,17 +91,17 @@ def register(request):
else:
form = UserForm()

return render_to_response(
return render(
request,
'register.html',
{
'form': form,
'months': list(range(1, 12)),
'months': range(1, 12),
'publishable': settings.STRIPE_PUBLISHABLE,
'soon': soon(),
'user': user,
'years': list(range(2011, 2036)),
'years': range(2011, 2036),
},
context_instance=RequestContext(request)
)


Expand Down Expand Up @@ -131,16 +130,16 @@ def edit(request):
else:
form = CardForm()

return render_to_response(
return render(
request,
'edit.html',
{
'form': form,
'publishable': settings.STRIPE_PUBLISHABLE,
'soon': soon(),
'months': list(range(1, 12)),
'years': list(range(2011, 2036))
'months': range(1, 12),
'years': range(2011, 2036)
},
context_instance=RequestContext(request)
)


Expand Down
Binary file modified _chapters/chp06/django_ecommerce/test.db
Binary file not shown.
4 changes: 2 additions & 2 deletions _chapters/chp06/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django==1.7
Django==1.9.9
mock==1.0.1
psycopg2==2.5.4
requests==2.3.0
stripe==1.9.2
wheel==0.24.0
14 changes: 8 additions & 6 deletions _chapters/chp06/tests/contact/testContactModels.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django.test import TestCase, SimpleTestCase
from contact.forms import ContactView
from contact.models import ContactForm
from contact.forms import ContactView
from datetime import datetime, timedelta


class UserModelTest(TestCase):

@classmethod
def setUpTestData(cls):
def setUpClass(cls):
super(UserModelTest, cls).setUpClass()
ContactForm(email="test@dummy.com", name="test").save()
ContactForm(email="j@j.com", name="jj").save()
cls.firstUser = ContactForm(
Expand All @@ -20,15 +21,16 @@ def setUpTestData(cls):
#cls.test_user.save()

def test_contactform_str_returns_email(self):
self.assertEqual("first@first.com", str(self.firstUser))
self.assertEquals("first@first.com", str(self.firstUser))

def test_ordering(self):
contacts = ContactForm.objects.all()
self.assertEqual(self.firstUser, contacts[0])

self.assertEquals(self.firstUser, contacts[0])

class ContactViewTests(SimpleTestCase):

def test_displayed_fields(self):
expected_fields = ['name', 'email', 'topic', 'message']
self.assertEqual(ContactView.Meta.fields, expected_fields)
self.assertEquals(ContactView.Meta.fields, expected_fields)


7 changes: 4 additions & 3 deletions _chapters/chp06/tests/main/testMainPageView.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.core.urlresolvers import resolve
from main.views import index
from django.shortcuts import render_to_response
from payments.models import User
from django.test import RequestFactory
import mock

Expand Down Expand Up @@ -29,15 +30,15 @@ def test_root_resolves_to_main_view(self):

def test_returns_appropriate_html_response_code(self):
resp = index(self.request)
self.assertEqual(resp.status_code, 200)
self.assertEquals(resp.status_code, 200)

#####################################
#### Testing templates and views ####
#####################################

def test_returns_exact_html(self):
resp = index(self.request)
self.assertEqual(
self.assertEquals(
resp.content,
render_to_response("index.html").content
)
Expand All @@ -61,4 +62,4 @@ def test_index_handles_logged_in_user(self):
expected_html = render_to_response(
'user.html', {'user': user_mock.get_by_id(1)}
)
self.assertEqual(resp.content, expected_html.content)
self.assertEquals(resp.content, expected_html.content)
1 change: 0 additions & 1 deletion _chapters/chp06/tests/payments/testCustomer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.test import TestCase
import mock


class CustomerTests(TestCase):

def test_create_subscription(self):
Expand Down
Loading