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