-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API & Client - add analysis visibility level
- Loading branch information
Showing
29 changed files
with
1,433 additions
and
281 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
fittrackee/migrations/versions/44_8a80bec0a410_add_analysis_visibility_level.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""add analysis visibility level | ||
Revision ID: 8a80bec0a410 | ||
Revises: 70f12f8c0218 | ||
Create Date: 2024-12-23 10:16:23.026455 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '8a80bec0a410' | ||
down_revision = '70f12f8c0218' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
visibility_levels = postgresql.ENUM( | ||
'PUBLIC', | ||
'FOLLOWERS_AND_REMOTE', # for a next version, not used for now | ||
'FOLLOWERS', | ||
'PRIVATE', | ||
name='visibility_levels', | ||
) | ||
|
||
|
||
def upgrade(): | ||
visibility_levels.create(op.get_bind()) | ||
with op.batch_alter_table('users', schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column( | ||
'analysis_visibility', | ||
visibility_levels, | ||
server_default='PRIVATE', | ||
nullable=True, | ||
) | ||
) | ||
op.execute("UPDATE users SET analysis_visibility = 'PRIVATE';") | ||
op.alter_column('users', 'analysis_visibility', nullable=False) | ||
|
||
with op.batch_alter_table('workouts', schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column( | ||
'analysis_visibility', | ||
visibility_levels, | ||
server_default='PRIVATE', | ||
nullable=True, | ||
) | ||
) | ||
op.execute("UPDATE workouts SET analysis_visibility = 'PRIVATE';") | ||
op.alter_column('workouts', 'analysis_visibility', nullable=False) | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('workouts', schema=None) as batch_op: | ||
batch_op.drop_column('analysis_visibility') | ||
|
||
with op.batch_alter_table('users', schema=None) as batch_op: | ||
batch_op.drop_column('analysis_visibility') | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,69 @@ | ||
import pytest | ||
|
||
from fittrackee.visibility_levels import VisibilityLevel, get_map_visibility | ||
from fittrackee.visibility_levels import ( | ||
VisibilityLevel, | ||
get_calculated_visibility, | ||
) | ||
|
||
|
||
class TestMapVisibility: | ||
@pytest.mark.parametrize( | ||
'input_map_visibility', | ||
'input_visibility', | ||
[ | ||
VisibilityLevel.PUBLIC, | ||
VisibilityLevel.FOLLOWERS, | ||
VisibilityLevel.PRIVATE, | ||
], | ||
) | ||
def test_it_returns_map_visibility_when_workout_visibility_is_public( | ||
def test_it_returns_visibility_when_parent_visibility_is_public( | ||
self, | ||
input_map_visibility: VisibilityLevel, | ||
input_visibility: VisibilityLevel, | ||
) -> None: | ||
assert ( | ||
get_map_visibility(input_map_visibility, VisibilityLevel.PUBLIC) | ||
== input_map_visibility | ||
get_calculated_visibility( | ||
visibility=input_visibility, | ||
parent_visibility=VisibilityLevel.PUBLIC, | ||
) | ||
== input_visibility | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
'input_map_visibility, expected_map_visibility', | ||
'input_visibility, expected_visibility', | ||
[ | ||
(VisibilityLevel.PUBLIC, VisibilityLevel.FOLLOWERS), | ||
(VisibilityLevel.FOLLOWERS, VisibilityLevel.FOLLOWERS), | ||
(VisibilityLevel.PRIVATE, VisibilityLevel.PRIVATE), | ||
], | ||
) | ||
def test_it_returns_map_visibility_when_workout_visibility_is_followers_only( # noqa | ||
def test_it_returns_map_visibility_when_analysis_visibility_is_followers_only( # noqa | ||
self, | ||
input_map_visibility: VisibilityLevel, | ||
expected_map_visibility: VisibilityLevel, | ||
input_visibility: VisibilityLevel, | ||
expected_visibility: VisibilityLevel, | ||
) -> None: | ||
assert ( | ||
get_map_visibility(input_map_visibility, VisibilityLevel.FOLLOWERS) | ||
== expected_map_visibility | ||
get_calculated_visibility( | ||
visibility=input_visibility, | ||
parent_visibility=VisibilityLevel.FOLLOWERS, | ||
) | ||
== expected_visibility | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
'input_map_visibility', | ||
'input_visibility', | ||
[ | ||
VisibilityLevel.PUBLIC, | ||
VisibilityLevel.FOLLOWERS, | ||
VisibilityLevel.PRIVATE, | ||
], | ||
) | ||
def test_it_returns_map_visibility_when_workout_visibility_is_private( | ||
def test_it_returns_visibility_when_parent_visibility_is_private( | ||
self, | ||
input_map_visibility: VisibilityLevel, | ||
input_visibility: VisibilityLevel, | ||
) -> None: | ||
assert ( | ||
get_map_visibility(input_map_visibility, VisibilityLevel.PRIVATE) | ||
get_calculated_visibility( | ||
visibility=input_visibility, | ||
parent_visibility=VisibilityLevel.PRIVATE, | ||
) | ||
== VisibilityLevel.PRIVATE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.