Skip to content

Commit

Permalink
Fix longstanding bugs in test_storage.test_update_replies
Browse files Browse the repository at this point in the history
  • Loading branch information
rmol committed Apr 23, 2020
1 parent bbf332d commit 236e8f6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
22 changes: 21 additions & 1 deletion tests/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import List
import uuid

from sdclientapi import Source as SDKSource
from sdclientapi import Reply as SDKReply, Source as SDKSource

from securedrop_client import db
from securedrop_client.api_jobs.base import ApiJob
Expand Down Expand Up @@ -195,3 +195,23 @@ def RemoteSource(**attrs):
defaults.update(attrs)

return SDKSource(**defaults)


def RemoteReply(**attrs):

source_url = "/api/v1/sources/{}".format(str(uuid.uuid4()))
defaults = dict(
filename="1-reply.filename",
journalist_uuid=str(uuid.uuid4()),
journalist_username="test",
file_counter=1,
is_deleted_by_source=False,
reply_url="test",
size=1234,
uuid=str(uuid.uuid4()),
source_url=source_url,
)

defaults.update(attrs)

return SDKReply(**defaults)
31 changes: 20 additions & 11 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,21 +687,10 @@ def test_update_replies(homedir, mocker, session):
source = factory.Source()
session.add(source)

# Some remote reply objects from the API, one of which will exist in the
# local database, the other will NOT exist in the local database
# (this will be added to the database)
remote_reply_update = make_remote_reply(source.uuid, journalist.uuid)
remote_reply_create = make_remote_reply(source.uuid, journalist.uuid)
remote_reply_create.file_counter = 3
remote_reply_create.filename = "3-reply.gpg"

remote_replies = [remote_reply_update, remote_reply_create]

# Some local reply objects. One already exists in the API results
# (this will be updated), one does NOT exist in the API results (this will
# be deleted from the local database).
local_reply_update = factory.Reply(
uuid=remote_reply_update.uuid,
source_id=source.id,
source=source,
journalist_id=journalist.id,
Expand All @@ -717,7 +706,27 @@ def test_update_replies(homedir, mocker, session):
session.add(local_reply_delete)

local_replies = [local_reply_update, local_reply_delete]
# Some remote reply objects from the API, one of which will exist in the
# local database, the other will NOT exist in the local database
# (this will be added to the database)
remote_reply_update = factory.RemoteReply(
journalist_uuid=journalist.uuid,
uuid=local_reply_update.uuid,
source_url="/api/v1/sources/{}".format(source.uuid),
file_counter=local_reply_update.file_counter,
filename=local_reply_update.filename,
)

remote_reply_create = factory.RemoteReply(
journalist_uuid=journalist.uuid,
source_url="/api/v1/sources/{}".format(source.uuid),
file_counter=factory.REPLY_COUNT + 1,
filename="{}-filename.gpg".format(factory.REPLY_COUNT + 1),
)

remote_replies = [remote_reply_update, remote_reply_create]

session.commit()
update_replies(remote_replies, local_replies, session, data_dir)
session.commit()

Expand Down

0 comments on commit 236e8f6

Please sign in to comment.