Ejemplo n.º 1
0
    def test_where_tag(self):
        self.assertEqual(
            Devices.where(Search.devices("#11")),
            """[{"device_id":2,"device_name":"Fishbowl vav","room_id":1,"room_name":"328","building_id":1,"building_name":"CMC","tags":["classroom","math_stats","academic","computer_science"],"description":null}, 
 {"device_id":1,"device_name":"Fishbowl thermostat","room_id":1,"room_name":"328","building_id":1,"building_name":"CMC","tags":["classroom","math_stats","academic","thermostat","computer_science"],"description":null}, 
 {"device_id":4,"device_name":"102 Lab thermostat","room_id":3,"room_name":"102","building_id":1,"building_name":"CMC","tags":["math_stats","academic","computer_science"],"description":null}]"""
        )
Ejemplo n.º 2
0
def get_devices():
    search_query = request.values.get('search')
    if search_query:
        try:
            return Devices.where(Search.devices(search_query)) or "[]"
        except InvalidSearchException as e:
            abort(400, e)
    else:
        return Devices.all() or "[]"
Ejemplo n.º 3
0
 def test_where_building(self):
     self.assertEqual(
         Devices.where(Search.devices("@2")),
         '[{"device_id":3,"device_name":"Thermostat in Evans 107","room_id":4,"room_name":"107","building_id":2,"building_name":"Evans","tags":["thermostat","residential","single","residence"],"description":null}]'
     )
Ejemplo n.º 4
0
 def test_ids_where_building_and_tag(self):
     self.assertEqual(set(Devices.ids_where(Search.devices("@1 and #2"))),
                      set())
Ejemplo n.º 5
0
 def test_simple_tag(self):
     self.assertEqual(
         Search.devices("#1"), " (devices_tags.tag_id = 1" +
         " OR rooms_tags.tag_id = 1 OR buildings_tags.tag_id = 1)")
Ejemplo n.º 6
0
 def test_ids_where_building_floor(self):
     self.assertEqual(
         set(Devices.ids_where(Search.devices("@1 and :floor > 2"))),
         {1, 2})
Ejemplo n.º 7
0
 def test_building_floor(self):
     self.assertEqual(Search.devices("@3 and :floor > 2"),
                      " buildings.building_id = 3 AND rooms.floor > 2")
Ejemplo n.º 8
0
 def test_parenthesis_building_room_device(self):
     self.assertEqual(
         Search.devices("(%6 or @3) and $2"),
         "( devices.device_id = 6 OR buildings.building_id = 3) AND rooms.room_id = 2"
     )
Ejemplo n.º 9
0
 def test_building_room_device(self):
     self.assertEqual(
         Search.devices("%6 and @3 and $2"),
         " devices.device_id = 6 AND buildings.building_id = 3 AND rooms.room_id = 2"
     )
Ejemplo n.º 10
0
 def test_simple_point(self):
     with self.assertRaises(Exception):
         Search.devices("*12")
Ejemplo n.º 11
0
 def test_simple_device(self):
     self.assertEqual(Search.devices("%12"), " devices.device_id = 12")
Ejemplo n.º 12
0
 def test_where_building_and_tag(self):
     self.assertEqual(Devices.where(Search.devices("@1 and #2")), "[]")
Ejemplo n.º 13
0
 def test_simple_room(self):
     self.assertEqual(Search.devices("$12"), " rooms.room_id = 12")
Ejemplo n.º 14
0
    def test_where_building_or_device(self):
        self.assertEqual(
            Devices.where(Search.devices("@2 or %4")),
            """[{"device_id":3,"device_name":"Thermostat in Evans 107","room_id":4,"room_name":"107","building_id":2,"building_name":"Evans","tags":["thermostat","residential","single","residence"],"description":null}, 
 {"device_id":4,"device_name":"102 Lab thermostat","room_id":3,"room_name":"102","building_id":1,"building_name":"CMC","tags":["math_stats","academic","computer_science"],"description":null}]"""
        )
Ejemplo n.º 15
0
 def test_building_room(self):
     self.assertEqual(Search.devices("@3 and $7"),
                      " buildings.building_id = 3 AND rooms.room_id = 7")
Ejemplo n.º 16
0
 def test_device_point(self):
     with self.assertRaises(Exception):
         Search.devices("%310 or *78")
Ejemplo n.º 17
0
 def test_simple_and(self):
     self.assertEqual(Search.devices("and"), " AND")
Ejemplo n.º 18
0
 def test_simple_building(self):
     self.assertEqual(Search.devices("@12"), " buildings.building_id = 12")
Ejemplo n.º 19
0
 def test_simple_or(self):
     self.assertEqual(Search.devices("or"), " OR")
Ejemplo n.º 20
0
 def test_nested_parenthesis_building_room_device(self):
     self.assertEqual(
         Search.devices("%6 or (@3 or $2)"),
         " devices.device_id = 6 OR( buildings.building_id = 3 OR rooms.room_id = 2)"
     )
Ejemplo n.º 21
0
 def test_simple_not(self):
     self.assertEqual(Search.devices("not"), " NOT")
Ejemplo n.º 22
0
 def test_ids_where_building(self):
     self.assertEqual(set(Devices.ids_where(Search.devices("@2"))), {3})
Ejemplo n.º 23
0
 def test_simple_floor(self):
     self.assertEqual(Search.devices(":floor = 3"), " rooms.floor = 3")
Ejemplo n.º 24
0
 def test_ids_where_building_or_device(self):
     self.assertEqual(set(Devices.ids_where(Search.devices("@2 or %4"))),
                      {3, 4})
Ejemplo n.º 25
0
 def test_simple_type(self):
     with self.assertRaises(Exception):
         Search.devices(":type 4")
Ejemplo n.º 26
0
 def test_ids_where_tag(self):
     self.assertEqual(set(Devices.ids_where(Search.devices("#11"))),
                      {1, 2, 4})
Ejemplo n.º 27
0
 def test_simple_unit(self):
     with self.assertRaises(Exception):
         Search.devices(":unit 5")
Ejemplo n.º 28
0
 def test_simple_measurement(self):
     with self.assertRaises(Exception):
         Search.devices(":measurement 'temperature'")
Ejemplo n.º 29
0
 def test_ids_where_tag_not_building(self):
     self.assertEqual(
         set(Devices.ids_where(Search.devices("#1 and not @2"))), {1})