def testProcessCustomFieldCond_DateType(self): fd = tracker_pb2.FieldDef(field_id=1, project_id=789, field_name='Deadline', field_type=tracker_pb2.FieldTypes.DATE_TYPE) val = int(time.mktime(datetime.datetime(2016, 10, 5).timetuple())) cond = ast_pb2.MakeCond(ast_pb2.QueryOp.EQ, [fd], [], [val]) left_joins, where = ast2select._ProcessCustomFieldCond( cond, 'Cond1', 'User1') self.assertEqual( [('Issue2FieldValue AS Cond1 ON Issue.id = Cond1.issue_id AND ' 'Issue.shard = Cond1.issue_shard AND ' 'Cond1.field_id = %s AND ' 'Cond1.date_value = %s', [1, val])], left_joins) self.assertTrue(sql._IsValidJoin(left_joins[0][0])) self.assertEqual([('Cond1.field_id IS NOT NULL', [])], where) self.assertTrue(sql._IsValidWhereCond(where[0][0]))
def testProcessCustomFieldCond_UserType_ByID(self): fd = tracker_pb2.FieldDef(field_id=1, project_id=789, field_name='ExecutiveProducer', field_type=tracker_pb2.FieldTypes.USER_TYPE) val = 111L cond = ast_pb2.MakeCond(ast_pb2.QueryOp.EQ, [fd], [], [val]) left_joins, where = ast2select._ProcessCustomFieldCond( cond, 'Cond1', 'User1') self.assertEqual( [('Issue2FieldValue AS Cond1 ON Issue.id = Cond1.issue_id AND ' 'Issue.shard = Cond1.issue_shard AND ' 'Cond1.field_id = %s AND ' 'Cond1.user_id = %s', [1, val])], left_joins) self.assertTrue(sql._IsValidJoin(left_joins[0][0])) self.assertEqual([('Cond1.field_id IS NOT NULL', [])], where) self.assertTrue(sql._IsValidWhereCond(where[0][0]))