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