def get_buildings():
    search_query = request.values.get('search')
    if search_query:
        try:
            return Buildings.where(Search.buildings(search_query)) or "[]"
        except InvalidSearchException as e:
            abort(400, e)
    else:
        return Buildings.all() or "[]"
Esempio n. 2
0
 def test_building_tag(self):
     self.assertEqual(
         Search.buildings("@3 and #2"),
         " buildings.building_id = 3 AND buildings_tags.tag_id = 2")
Esempio n. 3
0
 def test_device_point(self):
     with self.assertRaises(Exception):
         Search.buildings("%310 or *78")
Esempio n. 4
0
 def test_building_room(self):
     with self.assertRaises(Exception):
         Search.buildings("@3 and $7")
Esempio n. 5
0
 def test_where_building_and_tag(self):
     self.assertEqual(
         Buildings.where(Search.buildings("@1 and #5")),
         """[{"building_id":1,"building_name":"CMC","tags":["academic","math_stats","computer_science"]}]"""
     )
Esempio n. 6
0
 def test_where_building(self):
     self.assertEqual(
         Buildings.where(Search.buildings("@2")),
         """[{"building_id":2,"building_name":"Evans","tags":["residential"]}]"""
     )
Esempio n. 7
0
 def test_ids_where_building_and_tag(self):
     self.assertEqual(
         set(Buildings.ids_where(Search.buildings("@1 and #5"))), {1})
Esempio n. 8
0
 def test_ids_where_building_or_device(self):
     with self.assertRaises(Exception):
         Buildings.ids_where(Search.buildings("@2 or %4"))
Esempio n. 9
0
 def test_simple_not(self):
     self.assertEqual(Search.buildings("not"), " NOT")
Esempio n. 10
0
 def test_simple_or(self):
     self.assertEqual(Search.buildings("or"), " OR")
Esempio n. 11
0
 def test_simple_and(self):
     self.assertEqual(Search.buildings("and"), " AND")
Esempio n. 12
0
 def test_simple_point(self):
     with self.assertRaises(Exception):
         Search.buildings("*12")
Esempio n. 13
0
 def test_simple_device(self):
     with self.assertRaises(Exception):
         Search.buildings("%12")
Esempio n. 14
0
 def test_simple_room(self):
     with self.assertRaises(Exception):
         Search.buildings("$12")
Esempio n. 15
0
 def test_simple_building(self):
     self.assertEqual(Search.buildings("@12"),
                      " buildings.building_id = 12")
Esempio n. 16
0
 def test_ids_where_building(self):
     self.assertEqual(set(Buildings.ids_where(Search.buildings("@2"))), {2})
Esempio n. 17
0
 def test_simple_floor(self):
     with self.assertRaises(Exception):
         Search.buildings(":floor = 3")
Esempio n. 18
0
 def test_ids_where_tag(self):
     self.assertEqual(set(Buildings.ids_where(Search.buildings("#11"))),
                      {1})
Esempio n. 19
0
 def test_simple_type(self):
     with self.assertRaises(Exception):
         Search.buildings(":type 4")
Esempio n. 20
0
 def test_ids_where_tag_not_building(self):
     self.assertEqual(
         set(Buildings.ids_where(Search.buildings("#4 and not @1"))), {2})
Esempio n. 21
0
 def test_simple_unit(self):
     with self.assertRaises(Exception):
         Search.buildings(":unit 5")
Esempio n. 22
0
 def test_simple_measurement(self):
     with self.assertRaises(Exception):
         Search.buildings(":measurement 'temperature'")
Esempio n. 23
0
 def test_simple_tag(self):
     self.assertEqual(Search.buildings("#1"), " buildings_tags.tag_id = 1")