def testGetAccount(self): # mimic a GET of an account addr = "*****@*****.**" pwd = "dummypwd" account.createAccount(addr, pwd).put() result = account.getAccount(addr, pwd) # test the account values self.assertIsNotNone(result) self.assertEqual( result.address, addr) self.assertEqual( result.password, pwd) # test the json encoder resultStr = result.toJSON() self.assertIsNotNone(resultStr) # fetch again via the JSON string result = json.JSONDecoder(object_hook=account.fromJSON).decode(resultStr) self.assertIsNotNone(result) self.assertEqual( result.address, addr) self.assertEqual( result.password, pwd)
def post(self): address = self.request.get("create_addr") pwd = self.request.get("create_password") try: if account.getAccount(address): raise loginerror.LoginError('account already exists') acct = account.createAccount(address, pwd) if acct: acct.put() # write to the datastore outString = acct.toJSON() self.response.out.write(outString) else: self.response.out.write('{"errorMsg":"account does not exist or incorrect password."}') except loginerror.LoginError as e: self.response.out.write('{"errorMsg":"' + e.args[0] + '"}') except: self.response.out.write('{"errorMsg":"unexpected error in AccountPage POST."}') self.response.headers['Content-Type'] = "text/json";