2011-08-18 20:18:45 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# django-pyvows extensions
|
|
|
|
# https://github.com/rafaelcaricio/django-pyvows
|
|
|
|
|
|
|
|
# Licensed under the MIT license:
|
|
|
|
# http://www.opensource.org/licenses/mit-license
|
|
|
|
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
|
|
|
|
2011-08-25 21:19:24 +00:00
|
|
|
from os.path import abspath, join, dirname
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
import httplib2
|
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
from django_pyvows.context import DjangoContext, DjangoHTTPContext
|
2011-08-18 20:18:45 +00:00
|
|
|
from django_pyvows.assertions import *
|
|
|
|
|
2011-08-25 21:19:24 +00:00
|
|
|
TEST_FILE_PATH = abspath(join(dirname(__file__), 'fixtures/the_file.txt'))
|
|
|
|
|
2011-08-29 22:11:44 +00:00
|
|
|
DjangoContext.start_environment("sandbox.settings")
|
|
|
|
|
2011-08-18 20:18:45 +00:00
|
|
|
@Vows.batch
|
2011-08-18 21:44:43 +00:00
|
|
|
class HttpContextVows(DjangoHTTPContext):
|
2011-08-18 20:18:45 +00:00
|
|
|
|
|
|
|
def topic(self):
|
2011-08-18 21:44:43 +00:00
|
|
|
self.start_server()
|
2011-08-18 21:48:09 +00:00
|
|
|
return self.get("/")
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def the_return_code_should_be_200(self, (topic, content)):
|
|
|
|
expect(topic.status).to_equal(200)
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_return_the_success_response(self, (topic, content)):
|
|
|
|
expect(content).to_equal("hello world")
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
class Methods(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
2011-08-18 21:48:09 +00:00
|
|
|
return self.get('/?name=rafael')
|
2011-08-18 21:44:43 +00:00
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_be_possible_to_pass_get_parameters(self, (topic, content)):
|
|
|
|
expect(topic.status).to_equal(200)
|
2011-08-18 21:44:43 +00:00
|
|
|
|
2011-08-18 22:39:52 +00:00
|
|
|
class AskMyName(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
|
|
|
return self.get('/say/')
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_ask_for_my_name(self, (topic, content)):
|
|
|
|
expect(content).to_equal('What\'s your name?')
|
2011-08-18 22:39:52 +00:00
|
|
|
|
|
|
|
class SayHelloToMe(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
|
|
|
return self.get('/say/?name=Rafael')
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_say_hello_to_me(self, (topic, content)):
|
|
|
|
expect(content).to_equal('Hello, Rafael!')
|
2011-08-18 22:39:52 +00:00
|
|
|
|
2011-08-22 18:08:00 +00:00
|
|
|
class PostIt(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
|
|
|
return self.post('/post_it/', {'value': 'posted!'})
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_be_posted(self, (topic, content)):
|
|
|
|
expect(content).to_equal('posted!')
|
2011-08-22 18:08:00 +00:00
|
|
|
|
2011-08-25 21:19:24 +00:00
|
|
|
class PostFile(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
|
|
|
return self.post('/post_file/', {'the_file': open(TEST_FILE_PATH) })
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_be_posted_to_the_server(self, (topic, content)):
|
|
|
|
expect(content).to_equal("the contents")
|
2011-08-25 21:19:24 +00:00
|
|
|
|
|
|
|
class PostToNotFound(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
|
|
|
return self.post('/post_/', {'the_file': open(TEST_FILE_PATH) })
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_be_404(self, (topic, content)):
|
|
|
|
expect(topic.status).to_equal(404)
|
2011-08-25 21:19:24 +00:00
|
|
|
|