moved to user' object & fixes
This commit is contained in:
@ -5,6 +5,13 @@ from msgprocessor import (
|
||||
TrackerRemovalProcessorMessage,
|
||||
TrackerRemovalResult,
|
||||
)
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(init=True, eq=True)
|
||||
class TestUser:
|
||||
id: int
|
||||
first_name: str
|
||||
|
||||
|
||||
class TestRemoverFactory(unittest.TestCase):
|
||||
@ -12,13 +19,10 @@ class TestRemoverFactory(unittest.TestCase):
|
||||
|
||||
def test_remove_strategy_constructor(self):
|
||||
test_case_data = [
|
||||
{
|
||||
"domain": "youtube.com",
|
||||
"remover": self.factory.remove_yt_trackers
|
||||
},
|
||||
{"domain": "youtube.com", "remover": self.factory.remove_yt_trackers},
|
||||
{
|
||||
"domain": "lowerlevel.youtube.com",
|
||||
"remover": self.factory.remove_yt_trackers
|
||||
"remover": self.factory.remove_yt_trackers,
|
||||
},
|
||||
{
|
||||
"domain": "youtu.be",
|
||||
@ -27,7 +31,7 @@ class TestRemoverFactory(unittest.TestCase):
|
||||
{
|
||||
"domain": "something.youtu.be",
|
||||
"remover": self.factory.remove_yt_trackers,
|
||||
}
|
||||
},
|
||||
]
|
||||
for test_case in test_case_data:
|
||||
self.assertIs(
|
||||
@ -39,23 +43,26 @@ class TestRemoverFactory(unittest.TestCase):
|
||||
test_case_data = [
|
||||
{
|
||||
"url": "https://youtu.be/jNQXAC9IVRw?si=qLIZT1rvs99_jbgy",
|
||||
"expected_url": "https://youtu.be/jNQXAC9IVRw"
|
||||
"expected_url": "https://youtu.be/jNQXAC9IVRw",
|
||||
},
|
||||
{
|
||||
"url": "https://youtu.be/jNQXAC9IVRw?si=qLIZT1rvs99_jbgy&t=16",
|
||||
"expected_url": "https://youtu.be/jNQXAC9IVRw?t=16"
|
||||
"expected_url": "https://youtu.be/jNQXAC9IVRw?t=16",
|
||||
},
|
||||
{
|
||||
"url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
|
||||
"expected_url": "https://www.youtube.com/watch?v=jNQXAC9IVRw"
|
||||
"expected_url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
|
||||
},
|
||||
{
|
||||
"url": "http://www.youtube.com/watch?v=jNQXAC9IVRw&si=qLIZT1rvs99_jbgy&t=16",
|
||||
"expected_url": "http://www.youtube.com/watch?v=jNQXAC9IVRw&t=16"
|
||||
}
|
||||
"expected_url": "http://www.youtube.com/watch?v=jNQXAC9IVRw&t=16",
|
||||
},
|
||||
]
|
||||
for test_case in test_case_data:
|
||||
self.assertEqual(self.factory.remove_yt_trackers(test_case["url"]), test_case["expected_url"])
|
||||
self.assertEqual(
|
||||
self.factory.remove_yt_trackers(test_case["url"]),
|
||||
test_case["expected_url"],
|
||||
)
|
||||
|
||||
|
||||
class TestRemovalMsgProcessor(unittest.TestCase):
|
||||
@ -63,44 +70,44 @@ class TestRemovalMsgProcessor(unittest.TestCase):
|
||||
test_case_data = [
|
||||
{
|
||||
"msg_text": "https://youtu.be/jNQXAC9IVRw?si=qLIZT1rvs99_jbgy",
|
||||
"sender_username": "Ghytro",
|
||||
"sender": TestUser(id=123, first_name="Ghytro"),
|
||||
"bot_responded": True,
|
||||
"bot_response": "Message from @Ghytro:\n\nhttps://youtu.be/jNQXAC9IVRw"
|
||||
"bot_response": 'Message from <a href="tg://user?id=123">Ghytro</a>:\n\nhttps://youtu.be/jNQXAC9IVRw',
|
||||
},
|
||||
{
|
||||
"msg_text": "чекай https://youtu.be/jNQXAC9IVRw?si=qLIZT1rvs99_jbgy\nнаш слон хд",
|
||||
"sender_username": "OllyHearn",
|
||||
"sender": TestUser(id=321, first_name="OllyHearn"),
|
||||
"bot_responded": True,
|
||||
"bot_response": "Message from @OllyHearn:\n\nчекай https://youtu.be/jNQXAC9IVRw\nнаш слон хд"
|
||||
"bot_response": 'Message from <a href="tg://user?id=321">OllyHearn</a>:\n\nчекай https://youtu.be/jNQXAC9IVRw\nнаш слон хд',
|
||||
},
|
||||
{
|
||||
"msg_text": "а я такая нитакуся без si ссылки шлю сразу https://youtu.be/jNQXAC9IVRw и по нескольку штук\nhttp://www.youtube.com/watch?v=jNQXAC9IVRw&si=qLIZT1rvs99_jbgy&t=16 дада",
|
||||
"sender_username": "OllyHearn",
|
||||
"sender": TestUser(id=321, first_name="OllyHearn"),
|
||||
"bot_responded": True,
|
||||
"bot_response": "Message from @OllyHearn:\n\nа я такая нитакуся без si ссылки шлю сразу https://youtu.be/jNQXAC9IVRw и по нескольку штук\nhttp://www.youtube.com/watch?v=jNQXAC9IVRw&t=16 дада"
|
||||
"bot_response": 'Message from <a href="tg://user?id=321">OllyHearn</a>:\n\nа я такая нитакуся без si ссылки шлю сразу https://youtu.be/jNQXAC9IVRw и по нескольку штук\nhttp://www.youtube.com/watch?v=jNQXAC9IVRw&t=16 дада',
|
||||
},
|
||||
{
|
||||
"msg_text": "asdasdasdasdasdasdasd asdasd asdasd asdad sasa dadsas",
|
||||
"sender_username": "Ghytro",
|
||||
"sender": TestUser(id=123, first_name="Ghytro"),
|
||||
"bot_responded": False,
|
||||
"bot_response": ""
|
||||
}
|
||||
"bot_response": "",
|
||||
},
|
||||
]
|
||||
for test_case in test_case_data:
|
||||
result = TrackerRemovalMsgProcessor(
|
||||
TrackerRemovalProcessorMessage(
|
||||
fromUsername=test_case["sender_username"],
|
||||
text=test_case["msg_text"]
|
||||
fromUser=test_case["sender"], text=test_case["msg_text"]
|
||||
)
|
||||
).process()
|
||||
self.assertEqual(
|
||||
result,
|
||||
TrackerRemovalResult(
|
||||
needsToReply=test_case["bot_responded"],
|
||||
text=test_case["bot_response"]
|
||||
)
|
||||
text=test_case["bot_response"],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_classes_to_run = [TestRemoverFactory, TestRemovalMsgProcessor]
|
||||
|
||||
@ -110,7 +117,7 @@ if __name__ == "__main__":
|
||||
for test_class in test_classes_to_run:
|
||||
suite = loader.loadTestsFromTestCase(test_class)
|
||||
suites_list.append(suite)
|
||||
|
||||
|
||||
big_suite = unittest.TestSuite(suites_list)
|
||||
|
||||
runner = unittest.TextTestRunner()
|
||||
|
||||
Reference in New Issue
Block a user