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 "[]"
Exemplo 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")
Exemplo n.º 3
0
 def test_device_point(self):
     with self.assertRaises(Exception):
         Search.buildings("%310 or *78")
Exemplo n.º 4
0
 def test_building_room(self):
     with self.assertRaises(Exception):
         Search.buildings("@3 and $7")
Exemplo 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"]}]"""
     )
Exemplo n.º 6
0
 def test_where_building(self):
     self.assertEqual(
         Buildings.where(Search.buildings("@2")),
         """[{"building_id":2,"building_name":"Evans","tags":["residential"]}]"""
     )
Exemplo n.º 7
0
 def test_ids_where_building_and_tag(self):
     self.assertEqual(
         set(Buildings.ids_where(Search.buildings("@1 and #5"))), {1})
Exemplo n.º 8
0
 def test_ids_where_building_or_device(self):
     with self.assertRaises(Exception):
         Buildings.ids_where(Search.buildings("@2 or %4"))
Exemplo n.º 9
0
 def test_simple_not(self):
     self.assertEqual(Search.buildings("not"), " NOT")
Exemplo n.º 10
0
 def test_simple_or(self):
     self.assertEqual(Search.buildings("or"), " OR")
Exemplo n.º 11
0
 def test_simple_and(self):
     self.assertEqual(Search.buildings("and"), " AND")
Exemplo n.º 12
0
 def test_simple_point(self):
     with self.assertRaises(Exception):
         Search.buildings("*12")
Exemplo n.º 13
0
 def test_simple_device(self):
     with self.assertRaises(Exception):
         Search.buildings("%12")
Exemplo n.º 14
0
 def test_simple_room(self):
     with self.assertRaises(Exception):
         Search.buildings("$12")
Exemplo n.º 15
0
 def test_simple_building(self):
     self.assertEqual(Search.buildings("@12"),
                      " buildings.building_id = 12")
Exemplo n.º 16
0
 def test_ids_where_building(self):
     self.assertEqual(set(Buildings.ids_where(Search.buildings("@2"))), {2})
Exemplo n.º 17
0
 def test_simple_floor(self):
     with self.assertRaises(Exception):
         Search.buildings(":floor = 3")
Exemplo n.º 18
0
 def test_ids_where_tag(self):
     self.assertEqual(set(Buildings.ids_where(Search.buildings("#11"))),
                      {1})
Exemplo n.º 19
0
 def test_simple_type(self):
     with self.assertRaises(Exception):
         Search.buildings(":type 4")
Exemplo n.º 20
0
 def test_ids_where_tag_not_building(self):
     self.assertEqual(
         set(Buildings.ids_where(Search.buildings("#4 and not @1"))), {2})
Exemplo n.º 21
0
 def test_simple_unit(self):
     with self.assertRaises(Exception):
         Search.buildings(":unit 5")
Exemplo n.º 22
0
 def test_simple_measurement(self):
     with self.assertRaises(Exception):
         Search.buildings(":measurement 'temperature'")
Exemplo n.º 23
0
 def test_simple_tag(self):
     self.assertEqual(Search.buildings("#1"), " buildings_tags.tag_id = 1")