'Special characters (e.g. %, _ and \) stored in database are
properly escaped when using a case insensitive pattern lookup with an
expression -- refs #16731'

def test_insensitive_patterns_escape(self):

    Employee.objects.bulk_create([Employee(firstname='%Joh\\nny', lastname='%joh\\n'), Employee(firstname='Johnny', lastname='%john'), Employee(firstname='Jean-Claude', lastname='claud_'), Employee(firstname='Jean-Claude', lastname='claude'), Employee(firstname='Jean-Claude', lastname='claude%'), Employee(firstname='Johnny', lastname='joh\\n'), Employee(firstname='Johnny', lastname='john'), Employee(firstname='Johnny', lastname='_ohn')])
    self.assertQuerysetEqual(Employee.objects.filter(firstname__icontains=F('lastname')), ['<Employee:    %Joh\\nny    %joh\\n>', '<Employee:    Jean-Claude    claude>', '<Employee:    Johnny    john>'], ordered=False)
    self.assertQuerysetEqual(Employee.objects.filter(firstname__istartswith=F('lastname')), ['<Employee:    %Joh\\nny    %joh\\n>', '<Employee:    Johnny    john>'], ordered=False)
    self.assertQuerysetEqual(Employee.objects.filter(firstname__iendswith=F('lastname')), ['<Employee:    Jean-Claude    claude>'], ordered=False)
