Skip to content

Commit

Permalink
for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
seungjin committed Jun 3, 2011
1 parent 627be2e commit 02556f0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cloudservice/api/v1/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from atmosphere.cloudservice.models import *
from tools.request_factory import RequestFactory
from cloudservice.api.v1.cloud import Ec2_cloud



rf = RequestFactory()
post_request = rf.post('/resources/v1/launchApp/', {'image_id':'emi-D9602AB9', 'instance_size':'m1.small','instance_name':'iPlant Base Image','application_id':'app1','life_time':1})

ec2_keys = Ec2_keys.objects.get(username = 'seungjin')
ec2_cloud = Ec2_cloud(ec2_access_key=str(ec2_keys.ec2_access_key),ec2_secret_key=str(ec2_keys.ec2_secret_key),ec2_url=str(ec2_keys.ec2_url),s3_url=str(ec2_keys.s3_url))

ec2_cloud.launchApp(post_request)
Empty file added tools/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions tools/request_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


#RequestFactory: Easily create mock request objects, for use in testing
#http://djangosnippets.org/snippets/963/

from django.test import Client
from django.core.handlers.wsgi import WSGIRequest

class RequestFactory(Client):
"""
Class that lets you create mock Request objects for use in testing.
Usage:
rf = RequestFactory()
get_request = rf.get('/hello/')
post_request = rf.post('/submit/', {'foo': 'bar'})
This class re-uses the django.test.client.Client interface, docs here:
http://www.djangoproject.com/documentation/testing/#the-test-client
Once you have a request object you can pass it to any view function,
just as if that view had been hooked up using a URLconf.
"""
def request(self, **request):
"""
Similar to parent class, but returns the request object as soon as it
has created it.
"""
environ = {
'HTTP_COOKIE': self.cookies,
'PATH_INFO': '/',
'QUERY_STRING': '',
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': '',
'SERVER_NAME': 'testserver',
'SERVER_PORT': 80,
'SERVER_PROTOCOL': 'HTTP/1.1',
}
method = "POST"
environ.update(self.defaults)
environ.update(request)
return WSGIRequest(environ)

0 comments on commit 02556f0

Please sign in to comment.