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)
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)
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)
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)
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("<type> <text>", get_html_display_for_key("<type> <text>", 100))
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( "<type> <text>", get_html_display_for_key("<type> <text>", 100))
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)
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)
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)
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)
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("<comment>")) # And of course the check also implies that the text is # HTML-escaped: self.assertNotIn("<", display) self.assertNotIn(">", display)
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("<comment>")) # And of course the check also implies that the text is # HTML-escaped: self.assertNotIn("<", display) self.assertNotIn(">", display)
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("…", 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("<comment>"))
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("…", 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("<comment>"))