Skip to content

Commit

Permalink
Added view that saves a dojo on datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Apr 28, 2011
1 parent 757fbef commit 8f94395
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 13 additions & 0 deletions dojomap/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
from dojomap import app
from dojomap.forms import DojoForm
from dojomap.models import Dojo
from flask import render_template

@app.route('/dojo/new')
def new_dojo():
return render_template("new_dojo.html")

@app.route('/dojo/new', methods=['POST'])
def create_dojo():
form = DojoForm()

if form.validate_on_submit():
dojo = Dojo(name=form.name.data, description=form.description.data, address=form.address.data)
dojo.put()
return "Saved"

return render_template("new_dojo.html", form=form)
20 changes: 19 additions & 1 deletion tests/functional/test_dojo_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest
from dojomap import app
from dojomap.models import Dojo
from nose.tools import assert_equals

class TestDojoViews(unittest.TestCase):

Expand All @@ -10,4 +12,20 @@ def test_add_dojo_view(self):
"Should contain a view that responds to URL /dojo/new"
with app.test_request_context():
response = self.client.get("/dojo/new")
assert response.status_code == 200
assert_equals(response.status_code, 200)

def test_create_dojo_view(self):
"Should contain a view that creates a dojo on database on POST requests"
with app.test_request_context():

post_data = {
'name' : u'Main dojo',
'description' : u'The main dojo of the entire universe',
'address' : u'Main street, 20'
}

response = self.client.post("/dojo/new", data=post_data, follow_redirects=True)
assert_equals(response.status_code, 200)

dojo = Dojo.all().filter('name =', u'Main dojo').get()
assert_equals(dojo.address, u'Main street, 20')

0 comments on commit 8f94395

Please sign in to comment.