def test_format_bbcode_code(self): aou_controller = AOUController() aou_controller.text = Text() self.assertEqual("<i><highlight>test</highlight></i>", aou_controller.format_bbcode_code("[center][i][b]test[/b][/i][/center]")) self.assertEqual("\n", aou_controller.format_bbcode_code("\n")) self.assertEqual("testtest", aou_controller.format_bbcode_code("[color=#FFCC77]test[/color][color=red]test[/color]")) self.assertEqual("<a href='chatcmd:///start https://www.ao-universe.com/something1.png'>Image</a><a href='chatcmd:///start https://www.ao-universe.com/something2.png'>Image</a>", aou_controller.format_bbcode_code("[center][img]something1.png[/img][img]something2.png[/img][/center]")) self.assertEqual("<a href='chatcmd:///start test.com'>testing</a>", aou_controller.format_bbcode_code("[url=test.com]testing[/url]")) self.assertEqual("<a href='chatcmd:///tell <myname> aou 10'>testing</a>", aou_controller.format_bbcode_code("[url=index.php?pid=10]testing[/url]")) self.assertEqual("<a href='chatcmd:///waypoint 456 254 100'>Cool spot (456x254)</a>", aou_controller.format_bbcode_code("[waypoint pf=100 y=254 x=456]Cool spot[/waypoint]"))
def test_get_next_line(self): msg = "hello this is a test\nthis is another test as well\nand a third\ntest also\nwhich is\nshort" text = Text() self.assertEqual( 'hello this is a test\n', text.get_next_line(msg, { "symbol": "\n", "include": True })[0]) self.assertEqual( 'hello', text.get_next_line(msg, { "symbol": " ", "include": False })[0])
def test_paginate(self): setting = Mock() setting.get_value = MagicMock(return_value="test") setting.get_font_color = MagicMock(return_value="<font>") setting_service = Mock() setting_service.get = MagicMock(return_value=setting) bot = Mock() bot.get_char_name = MagicMock(return_value="char_name") bot.org_name = "org_name" public_channel_service = Mock() public_channel_service.get_org_name = MagicMock(return_value="org") text = Text() text.setting_service = setting_service text.bot = bot text.public_channel_service = public_channel_service msg = "hello this is a test\nthis is another test as well\nand a third\ntest also\nwhich is very\nshort" chatblob = ChatBlob("label", msg) page_prefix = "test_page_prefix" page_postfix = "test_page_postfix" chatblob.page_prefix = page_prefix chatblob.page_postfix = page_postfix pages = text.paginate(chatblob, 115) self.assertEqual(2, len(pages)) self.assertTrue("text://short" in pages[1]) # page prefix self.assertTrue(pages[0].startswith(page_prefix)) self.assertTrue(pages[1].startswith(page_prefix)) # page postfix self.assertTrue(pages[0].endswith(page_postfix)) self.assertTrue(pages[1].endswith(page_postfix)) # no max_page_length pages2 = text.paginate(chatblob) self.assertEqual(1, len(pages2))
def test_get_formatted_faction(self): text = Text() self.assertEqual("<omni>Omni</omni>", text.get_formatted_faction("omni")) self.assertEqual("<clan>Clan</clan>", text.get_formatted_faction("clan")) self.assertEqual("<neutral>Neutral</neutral>", text.get_formatted_faction("neutral")) self.assertEqual("<unknown>Unknown</unknown>", text.get_formatted_faction("unknown")) self.assertEqual("<unknown>Test</unknown>", text.get_formatted_faction("test")) self.assertEqual("<omni>Test2</omni>", text.get_formatted_faction("omni", "Test2")) self.assertEqual("<clan>Test2</clan>", text.get_formatted_faction("clan", "Test2")) self.assertEqual("<neutral>Test2</neutral>", text.get_formatted_faction("neutral", "Test2")) self.assertEqual("<unknown>Test2</unknown>", text.get_formatted_faction("unknown", "Test2"))
def test_paginate(self): setting = Mock() setting.get_value = MagicMock(return_value="test") setting.get_font_color = MagicMock(return_value="color") setting_service = Mock() setting_service.get = MagicMock(return_value=setting) bot = Mock() bot.char_name = "char_name" bot.org_name = "org_name" public_channel_service = Mock() public_channel_service.get_org_name = MagicMock(return_value="org") text = Text() text.setting_service = setting_service text.bot = bot text.public_channel_service = public_channel_service msg = "hello this is a test\nthis is another test as well\nand a third\ntest also\nwhich is very\nshort" pages = text.paginate("label", msg, 110) self.assertEqual(2, len(pages)) self.assertTrue("text://short" in pages[1])