Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update current user info during sync #1135

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions securedrop_client/api_jobs/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sqlalchemy.orm.session import Session

from securedrop_client.api_jobs.base import ApiJob
from securedrop_client.storage import get_remote_data, update_local_storage
from securedrop_client.storage import get_remote_data, update_and_get_user, update_local_storage

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,8 +37,11 @@ def call_api(self, api_client: API, session: Session) -> Any:
# This timeout is used for 3 different requests: `get_sources`, `get_all_submissions`, and
# `get_all_replies`
api_client.default_request_timeout = 60
remote_sources, remote_submissions, remote_replies = get_remote_data(api_client)

update_local_storage(
session, remote_sources, remote_submissions, remote_replies, self.data_dir
)
sources, submissions, replies = get_remote_data(api_client)

update_local_storage(session, sources, submissions, replies, self.data_dir)
user = api_client.get_current_user()
if "uuid" in user and "username" in user and "first_name" in user and "last_name" in user:
update_and_get_user(
user["uuid"], user["username"], user["first_name"], user["last_name"], session,
)
34 changes: 31 additions & 3 deletions tests/api_jobs/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,37 @@ def test_MetadataSyncJob_success(mocker, homedir, session, session_maker):
"securedrop_client.api_jobs.sync.get_remote_data", return_value=([mock_source], [], [])
)

api_client = mocker.MagicMock()
api_client.default_request_timeout = mocker.MagicMock()
api_client.default_request_timeout = mocker.MagicMock()
user = factory.User(uuid="mock1", username="mock1", firstname="mock1", lastname="mock1")
session.add(user)

api_client = mocker.patch("securedrop_client.logic.sdclientapi.API")

user = {"uuid": "mock1", "username": "mock1", "first_name": "mock1", "last_name": "mock1"}
mocker.patch.object(api_client, "get_current_user", return_value=user)

job.call_api(api_client, session)

assert mock_get_remote_data.call_count == 1


def test_MetadataSyncJob_success_current_user_name_change(mocker, homedir, session, session_maker):
job = MetadataSyncJob(homedir)

mock_source = factory.RemoteSource(
key={"type": "PGP", "public": PUB_KEY, "fingerprint": "123456ABC"}
)

mock_get_remote_data = mocker.patch(
"securedrop_client.api_jobs.sync.get_remote_data", return_value=([mock_source], [], [])
)

user = factory.User(uuid="mock1", username="mock1", firstname="mock1", lastname="mock1")
session.add(user)

api_client = mocker.patch("securedrop_client.logic.sdclientapi.API")

user = {"uuid": "mock2", "username": "mock2", "first_name": "mock2", "last_name": "mock2"}
mocker.patch.object(api_client, "get_current_user", return_value=user)

job.call_api(api_client, session)

Expand Down
542 changes: 246 additions & 296 deletions tests/functional/cassettes/test_delete_source.yaml

Large diffs are not rendered by default.

295 changes: 125 additions & 170 deletions tests/functional/cassettes/test_download_file.yaml

Large diffs are not rendered by default.

396 changes: 139 additions & 257 deletions tests/functional/cassettes/test_export_dialog.yaml

Large diffs are not rendered by default.

339 changes: 191 additions & 148 deletions tests/functional/cassettes/test_login_as_journalist.yaml

Large diffs are not rendered by default.

293 changes: 128 additions & 165 deletions tests/functional/cassettes/test_login_from_offline.yaml

Large diffs are not rendered by default.

259 changes: 107 additions & 152 deletions tests/functional/cassettes/test_logout_as_journalist.yaml

Large diffs are not rendered by default.

422 changes: 108 additions & 314 deletions tests/functional/cassettes/test_offline_delete_source_attempt.yaml

Large diffs are not rendered by default.

422 changes: 108 additions & 314 deletions tests/functional/cassettes/test_offline_read_conversation.yaml

Large diffs are not rendered by default.

285 changes: 124 additions & 161 deletions tests/functional/cassettes/test_offline_send_reply_to_source.yaml

Large diffs are not rendered by default.

342 changes: 108 additions & 234 deletions tests/functional/cassettes/test_offline_star_source.yaml

Large diffs are not rendered by default.

259 changes: 107 additions & 152 deletions tests/functional/cassettes/test_receive_message_from_source.yaml

Large diffs are not rendered by default.

673 changes: 114 additions & 559 deletions tests/functional/cassettes/test_send_reply_to_source.yaml

Large diffs are not rendered by default.

430 changes: 112 additions & 318 deletions tests/functional/cassettes/test_star_source.yaml

Large diffs are not rendered by default.

360 changes: 121 additions & 239 deletions tests/functional/cassettes/test_user_icon_click.yaml

Large diffs are not rendered by default.