Reverting my changes
This commit is contained in:
parent
ca0286ea0a
commit
2663441db9
6 changed files with 41 additions and 46 deletions
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
pyvows: db
|
pyvows:
|
||||||
@env PYTHONPATH=$$PYTHONPATH:vows/sandbox/:. pyvows --cover --cover_package=django_pyvows --cover_threshold=95 vows/
|
@env PYTHONPATH=$$PYTHONPATH:vows/sandbox/:. pyvows --cover --cover_package=django_pyvows --cover_threshold=95 vows/
|
||||||
|
|
||||||
ci_test:
|
ci_test:
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
# http://www.opensource.org/licenses/mit-license
|
# http://www.opensource.org/licenses/mit-license
|
||||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||||
|
|
||||||
from pyvows import Vows
|
from pyvows import Vows, expect
|
||||||
|
|
||||||
|
|
||||||
class Model(object):
|
class Model(object):
|
||||||
def __init__(self, context, model):
|
def __init__(self, context, model):
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#!/usr/bin/python
|
import urllib2
|
||||||
# -*- coding: utf-8 -*-
|
from urllib import urlencode
|
||||||
|
|
||||||
import httplib2
|
|
||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import mimetools
|
import mimetools
|
||||||
|
@ -72,12 +70,10 @@ class MultiPartForm(object):
|
||||||
|
|
||||||
|
|
||||||
def get(url):
|
def get(url):
|
||||||
h = httplib2.Http()
|
response = urllib2.urlopen(url)
|
||||||
resp, content = h.request(url)
|
return response
|
||||||
return resp, content
|
|
||||||
|
|
||||||
def post(url, data):
|
def post(url, data):
|
||||||
h = httplib2.Http()
|
|
||||||
form = MultiPartForm()
|
form = MultiPartForm()
|
||||||
|
|
||||||
for field, value in data.iteritems():
|
for field, value in data.iteritems():
|
||||||
|
@ -86,15 +82,15 @@ def post(url, data):
|
||||||
else:
|
else:
|
||||||
form.add_field(field, str(value))
|
form.add_field(field, str(value))
|
||||||
|
|
||||||
|
request = urllib2.Request(url)
|
||||||
body = str(form)
|
body = str(form)
|
||||||
headers = {
|
request.add_header('Content-type', form.get_content_type())
|
||||||
'Content-type': form.get_content_type(),
|
request.add_header('Content-length', len(body))
|
||||||
'Content-length': str(len(body))
|
request.add_data(body)
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = h.request(url, 'POST', headers=headers, body=body)
|
response = urllib2.urlopen(request)
|
||||||
except httplib2.HttpLib2Error, err:
|
except urllib2.HTTPError, err:
|
||||||
response = err
|
response = err
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -43,8 +43,7 @@ django-pyvows are pyvows extensions to django web framework.
|
||||||
|
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"pyvows",
|
"pyvows",
|
||||||
"django",
|
"django"
|
||||||
"httplib2"
|
|
||||||
],
|
],
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,10 +8,9 @@
|
||||||
# http://www.opensource.org/licenses/mit-license
|
# http://www.opensource.org/licenses/mit-license
|
||||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||||
|
|
||||||
|
import urllib2
|
||||||
from os.path import abspath, join, dirname
|
from os.path import abspath, join, dirname
|
||||||
|
|
||||||
import httplib2
|
|
||||||
|
|
||||||
from django_pyvows.context import DjangoContext, DjangoHTTPContext
|
from django_pyvows.context import DjangoContext, DjangoHTTPContext
|
||||||
from django_pyvows.assertions import *
|
from django_pyvows.assertions import *
|
||||||
|
|
||||||
|
@ -26,57 +25,57 @@ class HttpContextVows(DjangoHTTPContext):
|
||||||
self.start_server()
|
self.start_server()
|
||||||
return self.get("/")
|
return self.get("/")
|
||||||
|
|
||||||
def the_return_code_should_be_200(self, (topic, content)):
|
def the_return_code_should_be_200(self, topic):
|
||||||
expect(topic.status).to_equal(200)
|
expect(topic.getcode()).to_equal(200)
|
||||||
|
|
||||||
def should_return_the_success_response(self, (topic, content)):
|
def should_return_the_success_response(self, topic):
|
||||||
expect(content).to_equal("hello world")
|
expect(topic.read()).to_equal("hello world")
|
||||||
|
|
||||||
class Methods(DjangoContext):
|
class Methods(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
return self.get('/?name=rafael')
|
return self.get('/?name=rafael')
|
||||||
|
|
||||||
def should_be_possible_to_pass_get_parameters(self, (topic, content)):
|
def should_be_possible_to_pass_get_parameters(self, topic):
|
||||||
expect(topic.status).to_equal(200)
|
expect(topic.getcode()).to_equal(200)
|
||||||
|
|
||||||
class AskMyName(DjangoContext):
|
class AskMyName(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
return self.get('/say/')
|
return self.get('/say/')
|
||||||
|
|
||||||
def should_ask_for_my_name(self, (topic, content)):
|
def should_ask_for_my_name(self, topic):
|
||||||
expect(content).to_equal('What\'s your name?')
|
expect(topic.read()).to_equal('What\'s your name?')
|
||||||
|
|
||||||
class SayHelloToMe(DjangoContext):
|
class SayHelloToMe(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
return self.get('/say/?name=Rafael')
|
return self.get('/say/?name=Rafael')
|
||||||
|
|
||||||
def should_say_hello_to_me(self, (topic, content)):
|
def should_say_hello_to_me(self, topic):
|
||||||
expect(content).to_equal('Hello, Rafael!')
|
expect(topic.read()).to_equal('Hello, Rafael!')
|
||||||
|
|
||||||
class PostIt(DjangoContext):
|
class PostIt(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
return self.post('/post_it/', {'value': 'posted!'})
|
return self.post('/post_it/', {'value': 'posted!'})
|
||||||
|
|
||||||
def should_be_posted(self, (topic, content)):
|
def should_be_posted(self, topic):
|
||||||
expect(content).to_equal('posted!')
|
expect(topic.read()).to_equal('posted!')
|
||||||
|
|
||||||
class PostFile(DjangoContext):
|
class PostFile(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
return self.post('/post_file/', {'the_file': open(TEST_FILE_PATH) })
|
return self.post('/post_file/', {'the_file': open(TEST_FILE_PATH) })
|
||||||
|
|
||||||
def should_be_posted_to_the_server(self, (topic, content)):
|
def should_be_posted_to_the_server(self, topic):
|
||||||
expect(content).to_equal("the contents")
|
expect(topic.read()).to_equal("the contents")
|
||||||
|
|
||||||
class PostToNotFound(DjangoContext):
|
class PostToNotFound(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
return self.post('/post_/', {'the_file': open(TEST_FILE_PATH) })
|
return self.post('/post_/', {'the_file': open(TEST_FILE_PATH) })
|
||||||
|
|
||||||
def should_be_404(self, (topic, content)):
|
def should_be_thrown_an_error(self, topic):
|
||||||
expect(topic.status).to_equal(404)
|
expect(topic).to_be_an_error_like(urllib2.HTTPError)
|
||||||
|
|
||||||
|
|
|
@ -54,25 +54,25 @@ class SettingsVows(DjangoContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
self.settings.SAY_HELLO_WITHOUT_NAME = False
|
self.settings.SAY_HELLO_WITHOUT_NAME = False
|
||||||
self.start_server(port=9000)
|
self.start_server(port=8002)
|
||||||
return self.get('/say/')
|
return self.get('/say/')
|
||||||
|
|
||||||
def should_be_ok(self, (topic, content)):
|
def should_be_ok(self, topic):
|
||||||
expect(topic.status).to_equal(200)
|
expect(topic.code).to_equal(200)
|
||||||
|
|
||||||
def should_ask_for_my_name(self, (topic, content)):
|
def should_ask_for_my_name(self, topic):
|
||||||
expect(content).to_equal("What's your name?")
|
expect(topic.read()).to_equal("What's your name?")
|
||||||
|
|
||||||
class SayHelloWithoutName(DjangoHTTPContext):
|
class SayHelloWithoutName(DjangoHTTPContext):
|
||||||
|
|
||||||
def topic(self):
|
def topic(self):
|
||||||
self.settings.SAY_HELLO_WITHOUT_NAME = True
|
self.settings.SAY_HELLO_WITHOUT_NAME = True
|
||||||
self.start_server(port=9001)
|
self.start_server(port=8003)
|
||||||
return self.get('/say/')
|
return self.get('/say/')
|
||||||
|
|
||||||
def should_be_ok(self, (topic, content)):
|
def should_be_ok(self, topic):
|
||||||
expect(topic.status).to_equal(200)
|
expect(topic.code).to_equal(200)
|
||||||
|
|
||||||
def should_(self, (topic, content)):
|
def should_(self, topic):
|
||||||
expect(content).to_equal("Hello, guess!")
|
expect(topic.read()).to_equal("Hello, guess!")
|
||||||
|
|
||||||
|
|
Reference in a new issue