platform generic paths

This commit is contained in:
Dineshkarthik 2020-07-11 08:40:17 +02:00
parent 66aaedc948
commit c91507d345

View file

@ -27,6 +27,10 @@ MOCK_CONF = {
}
def platform_generic_path(path: str) -> str:
return os.path.join("/", *path.split("/"))
class MockMessage:
def __init__(self, **kwargs):
self.message_id = kwargs.get("id")
@ -130,9 +134,9 @@ class MockClient:
async def download_media(self, *args, **kwargs):
assert "AwADBQADbwAD2oTRVeHe5eXRFftfAg", args[0]
assert "/root/project/voice/voice_2019-07-25T14:53:50.ogg", kwargs[
"file_name"
]
assert platform_generic_path(
"/root/project/voice/voice_2019-07-25T14:53:50.ogg"
), kwargs["file_name"]
return kwargs["file_name"]
@ -160,7 +164,9 @@ class MediaDownloaderTestCase(unittest.TestCase):
self.assertEqual(
(
"AwADBQADbwAD2oTRVeHe5eXRFftfAg",
"/root/project/voice/voice_2019-07-25T14:53:50.ogg",
platform_generic_path(
"/root/project/voice/voice_2019-07-25T14:53:50.ogg"
),
"ogg",
),
result,
@ -178,7 +184,11 @@ class MediaDownloaderTestCase(unittest.TestCase):
async_get_media_meta(message.photo, "photo")
)
self.assertEqual(
("AgADBQAD5KkxG_FPQValJzQsJPyzhHcC", "/root/project/photo/", None),
(
"AgADBQAD5KkxG_FPQValJzQsJPyzhHcC",
platform_generic_path("/root/project/photo/"),
None,
),
result,
)
@ -198,7 +208,9 @@ class MediaDownloaderTestCase(unittest.TestCase):
self.assertEqual(
(
"AQADAgADq7LfMgAEIdy5DwAE4w4AAwI",
"/root/project/document/sample_document.pdf",
platform_generic_path(
"/root/project/document/sample_document.pdf"
),
"pdf",
),
result,
@ -220,7 +232,7 @@ class MediaDownloaderTestCase(unittest.TestCase):
self.assertEqual(
(
"AQADAgADq7LfMgAEIdy5DwAE5Q4AAgEC",
"/root/project/audio/sample_audio.mp3",
platform_generic_path("/root/project/audio/sample_audio.mp3"),
"mp3",
),
result,
@ -239,7 +251,11 @@ class MediaDownloaderTestCase(unittest.TestCase):
async_get_media_meta(message.video, "video")
)
self.assertEqual(
("CQADBQADeQIAAlL60FUCNMBdK8OjlAI", "/root/project/video/", "mp4"),
(
"CQADBQADeQIAAlL60FUCNMBdK8OjlAI",
platform_generic_path("/root/project/video/"),
"mp4",
),
result,
)