Exemplo n.º 1
0
 def register(self, jrequest, jresponse):
     assert isinstance(jrequest, JsonRpcRequest)
     assert isinstance(jresponse, JsonRpcResponse)
     jresponse.setId()
     request = jrequest.request
     assert isinstance(request, Request)
     if len(request.params) < 3:
         raise InvalidParams(
             "method=register&x=y&z=w&moduleId=mid&sensorId=sid&sensorName=mysensor where x is product field, y is product string, z is serial field, is serial string"
         )
     assert request.params.items()[0][0] == "method"
     assert request.params.items()[0][1] == "register"
     (product_name_field, product_name_string) = request.params.items()[1]
     (serial_number_field, serial_number_string) = request.params.items()[2]
     assert isinstance(product_name_field, str)
     product_name_field = unicode(product_name_field)
     assert isinstance(product_name_field, unicode)
     assert isinstance(serial_number_field, str)
     serial_number_field = unicode(serial_number_field)
     assert isinstance(serial_number_string, unicode)
     try:
         product_name_data = Data.prepare(product_name_field,
                                          product_name_string)
         serial_number_data = Data.prepare(serial_number_field,
                                           serial_number_string)
         module_id_string = request.get("moduleId")
         assert len(module_id_string) > 0
         sensor_id_string = request.get("sensorId")
         assert len(sensor_id_string) > 0
         module_id_data = Data.prepare("moduleId", request.get("moduleId"))
         sensor_id_data = Data.prepare("sensorId", request.get("sensorId"))
         existing_sensor = Sensor.getByProductNameSerialNumberModuleIdSensorId(
             product_name_data, serial_number_data, module_id_data,
             sensor_id_data)
         raise EntityExists(
             "Equipment", {
                 product_name_field: product_name_string,
                 serial_number_field: serial_number_string,
                 "moduleId": module_id_string,
                 "sensorId": sensor_id_string
             })
     except EntityNotFound:
         pass
     odenki_user = OdenkiUser.loadFromSession()
     assert isinstance(odenki_user, OdenkiUser)
     sensor_name = request.get("sensorName")
     if len(sensor_name) == 0: sensor_name = unicode(sensor_name)
     sensor_name_data = Data.prepare("sensorName", sensor_name)
     sensor = Sensor.create(product_name_data, serial_number_data,
                            module_id_data, sensor_id_data,
                            sensor_name_data, odenki_user)
     jresponse.addResult(sensor)
Exemplo n.º 2
0
 def testSucceeded(self):
     d = Data.prepare("f1", "s1")
     data_id = d.dataId
     self.assertEqual(data_id, 1)
     response = self.testapp.get("/api/Data/dataId/%s" % data_id)
     j = simplejson.loads(response.body)
     #print(j)
     self.assertEqual(j["result"][0]["field"], "f1")
     self.assertEqual(j["result"][0]["string"], "s1")
     self.assertEqual(j["result"][0]["dataId"], 1)
Exemplo n.º 3
0
    def setUp(self):
        import webtest
        from google.appengine.ext import webapp
        #app = webapp2.WSGIApplication([map])
        #from lib.gae import run_wsgi_app
        #app = run_wsgi_app(UrlMap.UrlMap)
        wsgi_application = webapp.WSGIApplication(post.paths, debug=True)
        self.testapp = webtest.TestApp(wsgi_application)

        from google.appengine.ext import testbed

        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        self.data1 = Data.prepare("f1", "s1")
        self.data1 = Data.prepare("f1", "s11")
        self.data2 = Data.prepare("f2", "s2")
Exemplo n.º 4
0
 def testFailed(self):
     d = Data.prepare("f1", "s1")
     data_id = d.dataId
     self.assertEqual(data_id, 1)
     response = self.testapp.get("/api/Data/dataId/%s" % (data_id + 1), status=500)
     # print(response.body)
     json_object = simplejson.loads(response.body)
     self.assertEqual(json_object["error"]["code"], -32099)
     self.assertIsNone(json_object["error"]["data"])
     self.assertIsNone(json_object["error"]["name"])
Exemplo n.º 5
0
 def testSucceeded(self):
     d = Data.prepare("f1", "s1")
     data_id = d.dataId
     self.assertEqual(data_id, 1)
     response = self.testapp.get("/api/Data/dataId/%s" % data_id)
     j = simplejson.loads(response.body)
     # print(j)
     self.assertEqual(j["result"][0]["field"], "f1")
     self.assertEqual(j["result"][0]["string"], "s1")
     self.assertEqual(j["result"][0]["dataId"], 1)
Exemplo n.º 6
0
    def setUp(self):
        import webtest
        from google.appengine.ext import webapp
        #app = webapp2.WSGIApplication([map])
        #from lib.gae import run_wsgi_app
        #app = run_wsgi_app(UrlMap.UrlMap)
        wsgi_application = webapp.WSGIApplication(post.paths, debug=True)
        self.testapp = webtest.TestApp(wsgi_application)

        from google.appengine.ext import testbed

        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        self.data1 = Data.prepare("f1", "s1")
        self.data1 = Data.prepare("f1", "s11")
        self.data2 = Data.prepare("f2", "s2")
Exemplo n.º 7
0
 def testFailed(self):
     d = Data.prepare("f1", "s1")
     data_id = d.dataId
     self.assertEqual(data_id, 1)
     response = self.testapp.get("/api/Data/dataId/%s" % (data_id + 1),
                                 status=500)
     #print(response.body)
     json_object = simplejson.loads(response.body)
     self.assertEqual(json_object["error"]["code"], -32099)
     self.assertIsNone(json_object["error"]["data"])
     self.assertIsNone(json_object["error"]["name"])
Exemplo n.º 8
0
 def register(self, jrequest, jresponse):
     assert isinstance(jrequest, JsonRpcRequest)
     assert isinstance(jresponse, JsonRpcResponse)
     jresponse.setId()
     request = jrequest.request
     assert isinstance(request, Request)
     if len(request.params) < 3:
         raise InvalidParams("method=register&x=y&z=w&moduleId=mid&sensorId=sid&sensorName=mysensor where x is product field, y is product string, z is serial field, is serial string")
     assert request.params.items()[0][0] == "method"
     assert request.params.items()[0][1] == "register"
     (product_name_field, product_name_string) = request.params.items()[1]
     (serial_number_field, serial_number_string) = request.params.items()[2]
     assert isinstance(product_name_field, str)
     product_name_field = unicode(product_name_field) 
     assert isinstance(product_name_field, unicode)
     assert isinstance(serial_number_field, str)
     serial_number_field = unicode(serial_number_field)
     assert isinstance(serial_number_string, unicode)
     try:
         product_name_data = Data.prepare(product_name_field, product_name_string)
         serial_number_data = Data.prepare(serial_number_field, serial_number_string)
         module_id_string = request.get("moduleId")
         assert len(module_id_string) > 0
         sensor_id_string = request.get("sensorId")
         assert len(sensor_id_string) > 0
         module_id_data = Data.prepare("moduleId", request.get("moduleId"))
         sensor_id_data = Data.prepare("sensorId", request.get("sensorId"))
         existing_sensor = Sensor.getByProductNameSerialNumberModuleIdSensorId(product_name_data, serial_number_data, module_id_data, sensor_id_data)
         raise EntityExists("Equipment", {product_name_field:product_name_string, serial_number_field: serial_number_string, "moduleId":module_id_string, "sensorId":sensor_id_string})
     except EntityNotFound: pass
     odenki_user = OdenkiUser.loadFromSession()
     assert isinstance(odenki_user, OdenkiUser)
     sensor_name = request.get("sensorName")
     if len(sensor_name) == 0: sensor_name = unicode(sensor_name)
     sensor_name_data = Data.prepare("sensorName", sensor_name)
     sensor = Sensor.create(product_name_data, serial_number_data, module_id_data, sensor_id_data, sensor_name_data, odenki_user)
     jresponse.addResult(sensor)