          # Ensure we don't allow directory-traversal.
          # This is tested directly on _key_to_file, as load() will swallow
          # a SuspiciousOperation in the same way as an IOError - by creating
          # a new session, making it unclear whether the slashes were detected.
          self.assertRaises(InvalidSessionKey,
                            self.backend()._key_to_file, "a\\b\\c")
  
      def test_invalid_key_forwardslash(self):
          # Ensure we don't allow directory-traversal
          self.assertRaises(InvalidSessionKey,
                            self.backend()._key_to_file, "a/b/c")
 
</s> remove         self.assertRaises(ImproperlyConfigured, self.backend)
 </s> add         with self.assertRaises(ImproperlyConfigured):
            self.backend() </s> remove         self.assertRaises(InvalidSessionKey,
                          self.backend()._key_to_file, "a/b/c")
 </s> add         with self.assertRaises(InvalidSessionKey):
            self.backend()._key_to_file("a/b/c") </s> remove         self.assertRaises(
            DatabaseError,
            self.column_classes, LocalBookWithM2M._meta.get_field("tags").remote_field.through
        )
 </s> add         with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through) </s> remove         self.assertRaises(ValueError, Author.objects.annotate, friends=Count('friends'))
 </s> add         with self.assertRaises(ValueError):
            Author.objects.annotate(friends=Count('friends')) </s> remove         self.assertRaises(DatabaseError, self.column_classes, new_field.remote_field.through)
 </s> add         with self.assertRaises(DatabaseError):
            self.column_classes(new_field.remote_field.through)
        with self.assertRaises(InvalidSessionKey):
            self.backend()._key_to_file("a\\b\\c")
          # Ensure we don't allow directory-traversal.
          # This is tested directly on _key_to_file, as load() will swallow
          # a SuspiciousOperation in the same way as an IOError - by creating
          # a new session, making it unclear whether the slashes were detected.
        with self.assertRaises(InvalidSessionKey):
            self.backend()._key_to_file("a\\b\\c")
        with self.assertRaises(InvalidSessionKey):
            self.backend()._key_to_file("a\\b\\c")
  
      def test_invalid_key_forwardslash(self):
          # Ensure we don't allow directory-traversal
          self.assertRaises(InvalidSessionKey,
                            self.backend()._key_to_file, "a/b/c")
keep keep keep keep replace replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/sessions_tests/tests.py