daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MyModel(db.Model):
  2.     name = db.StringProperty()
  3.     code = db.IntegerProperty()
  4.  
  5. class MyHandler(webapp2.RequestHandler):
  6.  
  7.     def MyMethod(self, name):
  8.         if self.request.method == 'POST':
  9.             model = MyModel.gql("WHERE name=:1", name).get()
  10.             model.code = SOME_CODE
  11.             model.put()
  12.    
  13. from google.appengine.ext import testbed
  14. import unittest
  15. import webtest
  16. import MyModel
  17. from main import api_routes '''my WSGIapplication routes '''
  18.  
  19. class MyTestClass(unittest.TestCase):
  20.  
  21.     def setUp(self):
  22.         app = webapp2.WSGIApplication(routes=api_routes)
  23.         self.testapp = webtest.TestApp(app)
  24.         self.testbed = testbed.Testbed()
  25.         self.testbed.activate()
  26.         self.testbed.init_datastore_v3_stub()
  27.         self.testmodel = MyModel(name='testname')
  28.         self.testmodel.put()
  29.  
  30.     def tearDown(self):
  31.         self.testbed.deactivate()
  32.  
  33.     def testOne(self):
  34.         url = SOME_URL # which call MyHandler MyMethod
  35.         params = {'name':'testname'}
  36.         response = self.testapp.post(url,params)
  37.         SOMEASSERTS
  38.    
  39. def testOne(self):
  40.         url = SOME_URL # which call MyHandler MyMethod
  41.         params = {'name':'testname'}
  42.         response = self.testapp.post(url,params)
  43.         model = MyModel.gql("WHERE name=:1",'testname').get()
  44.         self.assertTrue(model.code == SOME_CODE)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top