def createDb(): qSchools = School.query() schools = qSchools.fetch(2) if len(schools) == 0: for i in range(0,50): school = School() school.name='School '+str(i) school.put() qBoys = Boy.query() boys = qBoys.fetch(2) if len(boys) == 0: for i in range(0,50): boy = Boy() boy.name='Boy '+str(i) boy.put()
def getBoy(self, key): # first see if the user logged in: user = users.get_current_user() if user: q = Boy.query() #schools = q.fetch(10) boys, nextCursor, more = q.fetch_page(3) #return json.dumps(boys); return boys; else: return [] # return empty list
def post(self): boyName=cgi.escape(self.request.get('boyName')); schoolKey=cgi.escape(self.request.get('schoolKey')); myKey=ndb.Key('SunnyKey','myKeySunny'); schoolKey=ndb.Key(urlsafe=schoolKey); schools_query = School.query() schools = schools_query.fetch(10) schoolTarget = None for school in schools: if school.name == 'H N School': schoolTarget = school boy = Boy(parent=schoolKey) boy.name=boyName boy.put() template = JINJA_ENVIRONMENT.get_template('index-2.html') templateValues = { 'schoolKey': schoolTarget.key.urlsafe() } #print 'template is',template self.response.write(template.render(templateValues))
def testProperties(self): boy = Boy() # email test boy.email="*****@*****.**" boy.level="a" boy.put() boys = Boy.query().fetch(2) self.assertEqual(1, len(boys)) # test the email self.assertEqual('*****@*****.**', boys[0].email) #level test self.assertEqual('a', boys[0].level)
def testInsertEntity(self): Boy().put() self.assertEqual(1, len(Boy.query().fetch(2)))
def createBoys(self, num=10): for i in range(0, num): boy = Boy() boy.name = "Boy " + str(i) boy.put()
def testCreateBoys(self): # creates 10 boys by default: DbManager().createBoys() self.assertEqual(10, len(Boy.query().fetch(10)))