API - fix user agent infos in emails after dependencies update

(user-agent parsing has been removed in Werkzeug 2.1)
This commit is contained in:
Sam
2022-04-03 11:42:03 +02:00
parent a9064d5bef
commit db8c9df33c
6 changed files with 89 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ from uuid import uuid4
import pytest
from fittrackee.files import display_readable_file_size
from fittrackee.request import UserAgent
from fittrackee.utils import get_readable_duration
@@ -42,3 +43,28 @@ class TestReadableDuration:
readable_duration = get_readable_duration(30, locale)
assert readable_duration == expected_duration
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'

View File

@@ -285,8 +285,8 @@ class TestUserRegistration(ApiTestCaseMixin):
{
'username': username,
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
'account_confirmation_url': (
'http://0.0.0.0:5000/account-confirmation'
f'?token={expected_token}'
@@ -807,8 +807,8 @@ class TestUserAccountUpdate(ApiTestCaseMixin):
{
'username': user_1.username,
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
'new_email_address': new_email,
},
)
@@ -849,8 +849,8 @@ class TestUserAccountUpdate(ApiTestCaseMixin):
{
'username': user_1.username,
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
'email_confirmation_url': (
f'http://0.0.0.0:5000/email-update?token={expected_token}'
),
@@ -1009,8 +1009,8 @@ class TestUserAccountUpdate(ApiTestCaseMixin):
{
'username': user_1.username,
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
},
)
@@ -1690,8 +1690,8 @@ class TestPasswordResetRequest(ApiTestCaseMixin):
f'http://0.0.0.0:5000/password-reset?token={token}'
),
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
},
)
@@ -1903,8 +1903,8 @@ class TestPasswordUpdate(ApiTestCaseMixin):
{
'username': user_1.username,
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
},
)
@@ -2130,8 +2130,8 @@ class TestResendAccountConfirmationEmail(ApiTestCaseMixin):
{
'username': inactive_user.username,
'fittrackee_url': 'http://0.0.0.0:5000',
'operating_system': 'linux',
'browser_name': 'firefox',
'operating_system': 'Linux',
'browser_name': 'Firefox',
'account_confirmation_url': (
'http://0.0.0.0:5000/account-confirmation'
f'?token={expected_token}'