Fixed #20918 -- Tidied up implementation of custom assertions

1. Moved common logic between assertContains and assertNotContains
   into a separate function _assert_contains()

2. Moved common logic between assertTemplateUsed and
   assertTemplateNotUsed into a separate function
   _assert_templateused()

Thanks Marc Tamlyn for the report and review.