def test_filter_query5(self): args = ImmutableMultiDict([('test', 'hello')]) type_ = 0 where_clause = '' data = [] error_str = '' try: where_clause, data = main.filter_query(args, type_) except Exception as e: error_str = str(e) self.assertTrue(error_str == 'test_invalid_filter') args = ImmutableMultiDict([('test', 'hello')]) type_ = 1 where_clause = '' data = [] error_str = '' try: where_clause, data = main.filter_query(args, type_) except Exception as e: error_str = str(e) self.assertTrue(error_str == 'test_invalid_filter') args = ImmutableMultiDict([('test', 'hello')]) type_ = 2 where_clause = '' data = [] error_str = '' try: where_clause, data = main.filter_query(args, type_) except Exception as e: error_str = str(e) self.assertTrue(error_str == 'test_invalid_filter')
def test_filter_query2(self): args = ImmutableMultiDict([('num-courses', '0..10')]) type_ = 0 where_clause, data = main.filter_query(args, type_) print(where_clause) self.assertTrue( where_clause == ' and ( (Subject.num_courses BETWEEN %s AND %s))') self.assertTrue(len(data) == 2) args = ImmutableMultiDict([('price', '100..200')]) type_ = 1 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (Course.price BETWEEN %s AND %s))') self.assertTrue(len(data) == 2) args = ImmutableMultiDict([('num-related-courses', '5..100')]) type_ = 2 where_clause, data = main.filter_query(args, type_) self.assertTrue(where_clause == ' and ( (Job.num_related_courses BETWEEN %s AND %s))') self.assertTrue(len(data) == 2)
def test_filter_query3(self): args = ImmutableMultiDict([('provider', 'test')]) type_ = 0 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Subject.provider) = %s))') self.assertTrue(len(data) == 1) self.assertTrue(data[0] == 'TEST') args = ImmutableMultiDict([('provider', 'test')]) type_ = 1 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Course.provider) = %s))') self.assertTrue(len(data) == 1) self.assertTrue(data[0] == 'TEST') args = ImmutableMultiDict([('provider', 'test')]) type_ = 2 where_clause, data = main.filter_query(args, type_) self.assertTrue(where_clause == ' and ( (UPPER(Job.provider) = %s))') self.assertTrue(len(data) == 1) self.assertTrue(data[0] == 'TEST')
def test_filter_query1(self): args = ImmutableMultiDict([('provider', 'Udemy')]) type_ = 0 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Subject.provider) = %s))') self.assertTrue(len(data) == 1) self.assertTrue(data[0] == 'UDEMY') args = ImmutableMultiDict([('provider', 'Udemy')]) type_ = 1 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Course.provider) = %s))') self.assertTrue(len(data) == 1) self.assertTrue(data[0] == 'UDEMY') args = ImmutableMultiDict([('provider', 'Github Jobs')]) type_ = 2 where_clause, data = main.filter_query(args, type_) self.assertTrue(where_clause == ' and ( (UPPER(Job.provider) = %s))') self.assertTrue(len(data) == 1) self.assertTrue(data[0] == 'GITHUB JOBS')
def test_filter_query4(self): args = ImmutableMultiDict([('provider', 'Udemy'), ('num-courses', '0..10')]) type_ = 0 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Subject.provider) = %s)) and ( (Subject.num_courses BETWEEN %s AND %s))' ) self.assertTrue(len(data) == 3) self.assertTrue(data[0] == 'UDEMY') self.assertTrue(data[1] == 0 and data[2] == 10) args = ImmutableMultiDict([('provider', 'Khan Academy'), ('price', '0..0')]) type_ = 1 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Course.provider) = %s)) and ( (Course.price BETWEEN %s AND %s))' ) self.assertTrue(len(data) == 3) self.assertTrue(data[0] == 'KHAN ACADEMY') self.assertTrue(data[1] == 0 and data[2] == 0) args = ImmutableMultiDict([('provider', 'Github Jobs'), ('num-related-courses', '0..100')]) type_ = 2 where_clause, data = main.filter_query(args, type_) self.assertTrue( where_clause == ' and ( (UPPER(Job.provider) = %s)) and ( (Job.num_related_courses BETWEEN %s AND %s))' ) self.assertTrue(len(data) == 3) self.assertTrue(data[0] == 'GITHUB JOBS') self.assertTrue(data[1] == 0 and data[2] == 100)