Beispiel #1
0
 def test_display_limits_size_with_large_key_type(self):
     # If the key has a large 'key_type' part, the key is simply
     # cropped and HELLIPSIS appended to it.
     key = self.make_key(100, 10, 10)
     display = get_html_display_for_key(key, 50)
     self.assertEqual(50, len(display))
     self.assertEqual(
         '%.*s%s' % (50 - len(HELLIPSIS), key, HELLIPSIS), display)
Beispiel #2
0
 def test_display_limits_size_with_large_key_type(self):
     # If the key has a large 'key_type' part, the key is simply
     # cropped and HELLIPSIS appended to it.
     key = self.make_key(100, 10, 10)
     display = get_html_display_for_key(key, 50)
     self.assertEqual(50, len(display))
     self.assertEqual(
         '%.*s%s' % (50 - len(HELLIPSIS), key, HELLIPSIS), display)
Beispiel #3
0
 def test_display_returns_unchanged_if_unknown_and_small(self):
     # If the key does not look like a normal key (with three parts
     # separated by spaces, it's returned unchanged if its size is <=
     # size.
     size = random.randint(101, 200)
     key = factory.getRandomString(size - 100)
     display = get_html_display_for_key(key, size)
     self.assertTrue(len(display) < size)
     self.assertEqual(key, display)
Beispiel #4
0
 def test_display_returns_unchanged_if_unknown_and_small(self):
     # If the key does not look like a normal key (with three parts
     # separated by spaces, it's returned unchanged if its size is <=
     # size.
     size = random.randint(101, 200)
     key = factory.getRandomString(size - 100)
     display = get_html_display_for_key(key, size)
     self.assertTrue(len(display) < size)
     self.assertEqual(key, display)
Beispiel #5
0
 def test_display_escapes_commentless_key_for_html(self):
     # The key's comment may contain characters that are not safe for
     # including in HTML, and so get_html_display_for_key escapes the
     # text.
     # There are several code paths in get_html_display_for_key; this
     # test is for the case where the key has no comment, and is
     # brief enough to fit into the allotted space.
     self.assertEqual("&lt;type&gt; &lt;text&gt;",
                      get_html_display_for_key("<type> <text>", 100))
Beispiel #6
0
 def test_display_escapes_commentless_key_for_html(self):
     # The key's comment may contain characters that are not safe for
     # including in HTML, and so get_html_display_for_key escapes the
     # text.
     # There are several code paths in get_html_display_for_key; this
     # test is for the case where the key has no comment, and is
     # brief enough to fit into the allotted space.
     self.assertEqual(
         "&lt;type&gt; &lt;text&gt;",
         get_html_display_for_key("<type> <text>", 100))
Beispiel #7
0
 def test_display_returns_cropped_if_unknown_and_large(self):
     # If the key does not look like a normal key (with three parts
     # separated by spaces, it's returned cropped if its size is >
     # size.
     size = random.randint(20, 100)  # size cannot be < len(HELLIPSIS).
     key = factory.getRandomString(size + 1)
     display = get_html_display_for_key(key, size)
     self.assertEqual(size, len(display))
     self.assertEqual(
         '%.*s%s' % (size - len(HELLIPSIS), key, HELLIPSIS), display)
Beispiel #8
0
 def test_display_returns_cropped_if_unknown_and_large(self):
     # If the key does not look like a normal key (with three parts
     # separated by spaces, it's returned cropped if its size is >
     # size.
     size = random.randint(20, 100)  # size cannot be < len(HELLIPSIS).
     key = factory.getRandomString(size + 1)
     display = get_html_display_for_key(key, size)
     self.assertEqual(size, len(display))
     self.assertEqual(
         '%.*s%s' % (size - len(HELLIPSIS), key, HELLIPSIS), display)
Beispiel #9
0
 def test_display_cropped_key(self):
     # If the key has a small key_type, a small comment and a large
     # key_string (which is the 'normal' case), the key_string part
     # gets cropped.
     type_len = 10
     comment_len = 10
     key = self.make_key(type_len, 100, comment_len)
     key_type, key_string, comment = key.split(' ', 2)
     display = get_html_display_for_key(key, 50)
     self.assertEqual(50, len(display))
     self.assertEqual(
         '%s %.*s%s %s' %
         (key_type, 50 - (type_len + len(HELLIPSIS) + comment_len + 2),
          key_string, HELLIPSIS, comment), display)
Beispiel #10
0
 def test_display_cropped_key(self):
     # If the key has a small key_type, a small comment and a large
     # key_string (which is the 'normal' case), the key_string part
     # gets cropped.
     type_len = 10
     comment_len = 10
     key = self.make_key(type_len, 100, comment_len)
     key_type, key_string, comment = key.split(' ', 2)
     display = get_html_display_for_key(key, 50)
     self.assertEqual(50, len(display))
     self.assertEqual(
         '%s %.*s%s %s' % (
             key_type,
             50 - (type_len + len(HELLIPSIS) + comment_len + 2),
             key_string, HELLIPSIS, comment),
         display)
Beispiel #11
0
 def test_display_escapes_short_key_for_html(self):
     # The key's comment may contain characters that are not safe for
     # including in HTML, and so get_html_display_for_key escapes the
     # text.
     # There are several code paths in get_html_display_for_key; this
     # test is for the case where the whole key is short enough to
     # fit completely into the output.
     key = "<type> <text> <comment>"
     display = get_html_display_for_key(key, 100)
     # This also verifies that the entire key fits into the string.
     # Otherwise we might accidentally get one of the other cases.
     self.assertThat(display, EndsWith("&lt;comment&gt;"))
     # And of course the check also implies that the text is
     # HTML-escaped:
     self.assertNotIn("<", display)
     self.assertNotIn(">", display)
Beispiel #12
0
 def test_display_escapes_short_key_for_html(self):
     # The key's comment may contain characters that are not safe for
     # including in HTML, and so get_html_display_for_key escapes the
     # text.
     # There are several code paths in get_html_display_for_key; this
     # test is for the case where the whole key is short enough to
     # fit completely into the output.
     key = "<type> <text> <comment>"
     display = get_html_display_for_key(key, 100)
     # This also verifies that the entire key fits into the string.
     # Otherwise we might accidentally get one of the other cases.
     self.assertThat(display, EndsWith("&lt;comment&gt;"))
     # And of course the check also implies that the text is
     # HTML-escaped:
     self.assertNotIn("<", display)
     self.assertNotIn(">", display)
Beispiel #13
0
 def test_display_escapes_long_key_for_html(self):
     # The key's comment may contain characters that are not safe for
     # including in HTML, and so get_html_display_for_key escapes the
     # text.
     # There are several code paths in get_html_display_for_key; this
     # test is for the case where the comment is short enough to fit
     # completely into the output.
     key = "<type> %s <comment>" % ("<&>" * 50)
     display = get_html_display_for_key(key, 50)
     # This verifies that we are indeed getting an abbreviated
     # display.  Otherwise we might accidentally get one of the other
     # cases.
     self.assertIn("&hellip;", display)
     self.assertIn("comment", display)
     # And now, on to checking that the text is HTML-safe.
     self.assertNotIn("<", display)
     self.assertNotIn(">", display)
     self.assertThat(display, EndsWith("&lt;comment&gt;"))
Beispiel #14
0
 def test_display_escapes_long_key_for_html(self):
     # The key's comment may contain characters that are not safe for
     # including in HTML, and so get_html_display_for_key escapes the
     # text.
     # There are several code paths in get_html_display_for_key; this
     # test is for the case where the comment is short enough to fit
     # completely into the output.
     key = "<type> %s <comment>" % ("<&>" * 50)
     display = get_html_display_for_key(key, 50)
     # This verifies that we are indeed getting an abbreviated
     # display.  Otherwise we might accidentally get one of the other
     # cases.
     self.assertIn("&hellip;", display)
     self.assertIn("comment", display)
     # And now, on to checking that the text is HTML-safe.
     self.assertNotIn("<", display)
     self.assertNotIn(">", display)
     self.assertThat(display, EndsWith("&lt;comment&gt;"))