Permalink
Browse files

Merge branch 'master' of github.com:andrewsmedina/djangodash2011

  • Loading branch information...
2 parents eb4b6b3 + 734d0d5 commit 2645a7b321a9cd9acc62314c8221dc95593fd90d @siminino siminino committed Jul 31, 2011
Showing with 32 additions and 1 deletion.
  1. +4 −1 startdust_website/api/handlers.py
  2. +25 −0 startdust_website/api/tests.py
  3. +3 −0 startdust_website/responses/forms.py
@@ -4,6 +4,7 @@
from errors.forms import ErrorForm
from responses.models import Response
from responses.forms import ResponseForm
+from projects.models import Project
class ResponseHandler(BaseHandler):
@@ -16,7 +17,9 @@ def create(self, request):
form = ResponseForm(request.POST)
if form.is_valid():
- form.save()
+ instance = form.save()
+ instance.project = Project.objects.get(token=form.cleaned_data['token'])
+ instance.save()
return HttpResponse('response added with success!')
else:
return HttpResponse('', status=500)
@@ -2,6 +2,7 @@
from django.contrib.auth.models import User
from errors.models import Error
from responses.models import Response
+from projects.models import Project
import base64
@@ -159,7 +160,14 @@ def setUp(self):
'HTTP_AUTHORIZATION': auth,
}
+ self.project = Project.objects.create(
+ name='project name',
+ url='http://projecturl.com',
+ token='123'
+ )
+
def tearDown(self):
+ self.project.delete()
self.user.delete()
def test_api_response_view_should_add_a_response(self):
@@ -169,6 +177,7 @@ def test_api_response_view_should_add_a_response(self):
post_data = {
'time': 0.1123,
'url': 'http://someurl.com',
+ 'token': '123',
}
response = self.client.post('/api/response/', post_data, **self.extra)
@@ -185,11 +194,27 @@ def test_request_api_view_should_returns_200(self):
post_data = {
'time': 0.1123,
'url': 'http://someurl.com',
+ 'token': '123',
}
response = self.client.post('/api/response/', post_data, **self.extra)
self.assertEqual(200, response.status_code)
+ def test_api_response_view_should_create_a_relation_between_response_and_project(self):
+ '''
+ api response should create a realtionship between response and project
+ '''
+ post_data = {
+ 'time': 0.11233,
+ 'url': 'http://someurl.com',
+ 'token': '123',
+ }
+
+ response = self.client.post('/api/response/', post_data, **self.extra)
+
+ project = Response.objects.get(time=post_data['time']).project
+ self.assertTrue(project)
+
def test_should_returns_405_when_the_method_isnt_post(self):
'''
request api should returns 405 status code when method isnt a post
@@ -1,8 +1,11 @@
from django.forms import ModelForm
+from django import forms
from responses.models import Response
class ResponseForm(ModelForm):
+ token = forms.CharField()
+
class Meta:
model = Response

0 comments on commit 2645a7b

Please sign in to comment.