2021-01-31 10:21:40 +01:00
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2022-02-16 12:55:55 +01:00
|
|
|
from fittrackee.files import display_readable_file_size
|
2022-04-03 11:42:03 +02:00
|
|
|
from fittrackee.request import UserAgent
|
2021-02-20 21:37:31 +01:00
|
|
|
from fittrackee.utils import get_readable_duration
|
2021-01-31 10:21:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestDisplayReadableFileSize:
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'size, expected_readable_size',
|
|
|
|
[
|
|
|
|
(0, '0 bytes'),
|
|
|
|
(1, '1 byte'),
|
|
|
|
(100, '100.0 bytes'),
|
|
|
|
(1024, '1.0KB'),
|
|
|
|
(286773663, '273.5MB'),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_it_returns_readable_file_size(
|
|
|
|
self, size: Union[float, int], expected_readable_size: str
|
|
|
|
) -> None:
|
|
|
|
readable_file_size = display_readable_file_size(size)
|
|
|
|
|
|
|
|
assert readable_file_size == expected_readable_size
|
|
|
|
|
|
|
|
|
|
|
|
class TestReadableDuration:
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'locale, expected_duration',
|
|
|
|
[
|
|
|
|
('en', '30 seconds'),
|
|
|
|
('fr', '30 secondes'),
|
|
|
|
(None, '30 seconds'),
|
2022-11-19 20:17:58 +01:00
|
|
|
('invalid_locale', '30 seconds'),
|
2021-01-31 10:21:40 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_it_returns_duration_in_locale(
|
|
|
|
self, locale: str, expected_duration: str
|
|
|
|
) -> None:
|
|
|
|
readable_duration = get_readable_duration(30, locale)
|
|
|
|
|
|
|
|
assert readable_duration == expected_duration
|
2022-04-03 11:42:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestParseUserAgent:
|
|
|
|
string = (
|
|
|
|
'Mozilla/5.0 (X11; Linux x86_64; rv:98.0) '
|
|
|
|
'Gecko/20100101 Firefox/98.0'
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_it_returns_browser_name(self) -> None:
|
|
|
|
user_agent = UserAgent(self.string)
|
|
|
|
assert user_agent.browser == 'Firefox'
|
|
|
|
|
|
|
|
def test_it_returns_other_as_brother_name_when_empty_string_provided(
|
|
|
|
self,
|
|
|
|
) -> None:
|
|
|
|
user_agent = UserAgent('')
|
|
|
|
assert user_agent.browser == 'Other'
|
|
|
|
|
|
|
|
def test_it_returns_operating_system(self) -> None:
|
|
|
|
user_agent = UserAgent(self.string)
|
|
|
|
assert user_agent.platform == 'Linux'
|
|
|
|
|
|
|
|
def test_it_returns_other_as_os_when_empty_string_provided(self) -> None:
|
|
|
|
user_agent = UserAgent('')
|
|
|
|
assert user_agent.platform == 'Other'
|