API - init privacy policy
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
@ -296,7 +298,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
|
||||
@pytest.mark.parametrize(
|
||||
'input_description,input_email', [('input string', ''), ('None', None)]
|
||||
)
|
||||
def test_it_empties_error_if_admin_contact_is_an_empty(
|
||||
def test_it_empties_contact_if_provided_admin_contact_is_an_empty(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_admin: User,
|
||||
@ -325,6 +327,66 @@ class TestUpdateConfig(ApiTestCaseMixin):
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['admin_contact'] is None
|
||||
|
||||
def test_it_updates_about(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_admin: User,
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1_admin.email
|
||||
)
|
||||
about = self.random_string()
|
||||
|
||||
response = client.patch(
|
||||
'/api/config',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
about=about,
|
||||
)
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.data.decode())
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['about'] == about
|
||||
|
||||
def test_it_updates_privacy_policy(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_admin: User,
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1_admin.email
|
||||
)
|
||||
privacy_policy = self.random_string()
|
||||
privacy_policy_date = datetime.utcnow()
|
||||
|
||||
with patch(
|
||||
'fittrackee.application.app_config.datetime'
|
||||
) as datetime_mock:
|
||||
datetime_mock.utcnow = Mock(return_value=privacy_policy_date)
|
||||
response = client.patch(
|
||||
'/api/config',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
privacy_policy=privacy_policy,
|
||||
)
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.data.decode())
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['privacy_policy'] == privacy_policy
|
||||
assert data['data'][
|
||||
'privacy_policy_date'
|
||||
] == privacy_policy_date.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
|
@ -1,3 +1,5 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
|
||||
@ -5,6 +7,8 @@ from fittrackee import VERSION
|
||||
from fittrackee.application.models import AppConfig
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from ..utils import random_string
|
||||
|
||||
|
||||
class TestConfigModel:
|
||||
def test_application_config(
|
||||
@ -88,3 +92,26 @@ class TestConfigModel:
|
||||
serialized_app_config['weather_provider']
|
||||
== expected_weather_provider
|
||||
)
|
||||
|
||||
def test_it_returns_privacy_policy(self, app: Flask) -> None:
|
||||
app_config = AppConfig.query.first()
|
||||
privacy_policy = random_string()
|
||||
privacy_policy_date = datetime.now()
|
||||
app_config.privacy_policy = privacy_policy
|
||||
app_config.privacy_policy_date = privacy_policy_date
|
||||
|
||||
serialized_app_config = app_config.serialize()
|
||||
|
||||
assert serialized_app_config["privacy_policy"] == privacy_policy
|
||||
assert (
|
||||
serialized_app_config["privacy_policy_date"] == privacy_policy_date
|
||||
)
|
||||
|
||||
def test_it_returns_about(self, app: Flask) -> None:
|
||||
app_config = AppConfig.query.first()
|
||||
about = random_string()
|
||||
app_config.about = about
|
||||
|
||||
serialized_app_config = app_config.serialize()
|
||||
|
||||
assert serialized_app_config["about"] == about
|
||||
|
Reference in New Issue
Block a user