Example #1
0
    def testPreprocessExactUsers_UserNotFound(self):
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [OWNER_FIELD],
                                ['*****@*****.**'], [])
        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], True)
        self.assertEqual(cond, new_cond)

        with self.assertRaises(ast2ast.MalformedQuery):
            ast2ast._PreprocessExactUsers(self.cnxn, cond, self.services.user,
                                          [OWNER_ID_FIELD], False)
Example #2
0
    def testPreprocessExactUsers_KeywordMe(self):
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [OWNER_FIELD],
                                ['me'], [])
        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], True)
        self.assertEqual(cond, new_cond)

        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], False)
        self.assertEqual(cond, new_cond)
Example #3
0
    def testPreprocessExactUsers_NonEquality(self):
        """Project members may search for [owner_id>111]."""
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.GE, [OWNER_ID_FIELD], ['111'],
                                [])
        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], True)
        self.assertEqual(cond, new_cond)

        with self.assertRaises(ast2ast.MalformedQuery):
            ast2ast._PreprocessExactUsers(self.cnxn, cond, self.services.user,
                                          [OWNER_ID_FIELD], False)
Example #4
0
    def testPreprocessExactUsers_UserSpecifiedByID(self):
        """Anyone may search for users by ID, [owner:1234]."""
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [OWNER_FIELD],
                                ['123'], [])
        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], True)
        self.assertEqual(ast_pb2.QueryOp.EQ, new_cond.op)
        self.assertEqual([OWNER_ID_FIELD], new_cond.field_defs)
        self.assertEqual([123], new_cond.int_values)
        self.assertEqual([], new_cond.str_values)

        # Non-members do not raise an exception.
        ast2ast._PreprocessExactUsers(self.cnxn, cond, self.services.user,
                                      [OWNER_ID_FIELD], False)
Example #5
0
    def testPreprocessExactUsers_UserFound(self):
        """Anyone can search for a know user, [owner:[email protected]]."""
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [OWNER_FIELD],
                                ['*****@*****.**'], [])
        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], True)
        self.assertEqual(ast_pb2.QueryOp.EQ, new_cond.op)
        self.assertEqual([OWNER_ID_FIELD], new_cond.field_defs)
        self.assertEqual([111], new_cond.int_values)
        self.assertEqual([], new_cond.str_values)

        # Non-members do not raise an exception.
        ast2ast._PreprocessExactUsers(self.cnxn, cond, self.services.user,
                                      [OWNER_ID_FIELD], False)
Example #6
0
    def testPreprocessExactUsers_IsDefined(self):
        """Anyone can search for [has:owner]."""
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.IS_DEFINED, [OWNER_FIELD],
                                ['*****@*****.**'], [])
        new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                                 self.services.user,
                                                 [OWNER_ID_FIELD], True)
        self.assertEqual(ast_pb2.QueryOp.IS_DEFINED, new_cond.op)
        self.assertEqual([OWNER_ID_FIELD], new_cond.field_defs)
        self.assertEqual([], new_cond.int_values)
        self.assertEqual([], new_cond.str_values)

        # Non-members do not raise an exception.
        ast2ast._PreprocessExactUsers(self.cnxn, cond, self.services.user,
                                      [OWNER_ID_FIELD], False)
Example #7
0
 def testPreprocessExactUsers_NonEquality(self):
     cond = ast_pb2.MakeCond(ast_pb2.QueryOp.GE, [OWNER_ID_FIELD], ['111'],
                             [])
     new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                              self.services.user,
                                              [OWNER_ID_FIELD])
     self.assertEqual(cond, new_cond)
Example #8
0
 def testPreprocessExactUsers_UserSpecifiedByID(self):
     cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [OWNER_FIELD],
                             ['123'], [])
     new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                              self.services.user,
                                              [OWNER_ID_FIELD])
     self.assertEqual(ast_pb2.QueryOp.EQ, new_cond.op)
     self.assertEqual([OWNER_ID_FIELD], new_cond.field_defs)
     self.assertEqual([123L], new_cond.int_values)
     self.assertEqual([], new_cond.str_values)
Example #9
0
 def testPreprocessExactUsers_IsDefined(self):
     cond = ast_pb2.MakeCond(ast_pb2.QueryOp.IS_DEFINED, [OWNER_FIELD],
                             ['*****@*****.**'], [])
     new_cond = ast2ast._PreprocessExactUsers(self.cnxn, cond,
                                              self.services.user,
                                              [OWNER_ID_FIELD])
     self.assertEqual(ast_pb2.QueryOp.IS_DEFINED, new_cond.op)
     self.assertEqual([OWNER_ID_FIELD], new_cond.field_defs)
     self.assertEqual([], new_cond.int_values)
     self.assertEqual([], new_cond.str_values)