예제 #1
0
def test_source_collection():
    # Create some test submissions and replies
    source = Source(journalist_designation="testy test",
                    uuid="test",
                    is_flagged=False,
                    public_key='test',
                    interaction_count=1,
                    is_starred=False,
                    last_updated='test')
    submission = Submission(source=source,
                            uuid="test",
                            size=123,
                            filename="2-test.doc.gpg")
    user = User('hehe')
    reply = Reply(source=source,
                  journalist=user,
                  filename="1-reply.gpg",
                  size=1234,
                  uuid='test')
    source.submissions = [submission]
    source.replies = [reply]

    # Now these items should be in the source collection in the proper order
    assert source.collection[0] == reply
    assert source.collection[1] == submission
예제 #2
0
def test_string_representation_of_reply():
    user = User('hehe')
    source = Source(journalist_designation="testy test", uuid="test",
                    is_flagged=False, public_key='test', interaction_count=1,
                    is_starred=False, last_updated='test')
    reply = Reply(source=source, journalist=user, filename="reply.gpg",
                  size=1234, uuid='test')
    reply.__repr__()
예제 #3
0
def test_reply_content_not_downloaded():
    source = Source(journalist_designation="testy test", uuid="test",
                    is_flagged=False, public_key='test', interaction_count=1,
                    is_starred=False, last_updated='test')
    journalist = User('Testy mcTestface')
    reply = Reply(source=source, uuid="test", size=123,
                  filename="test.docx", journalist=journalist)
    assert reply.content is None
예제 #4
0
def test_reply_content_downloaded():
    source = Source(journalist_designation="testy test", uuid="test",
                    is_flagged=False, public_key='test', interaction_count=1,
                    is_starred=False, last_updated='test')
    journalist = User('Testy mcTestface')
    reply = Reply(source=source, uuid="test", size=123,
                  filename="test.docx", journalist=journalist)
    reply.is_downloaded = True
    with mock.patch('builtins.open', mock.mock_open(read_data="blah")):
        assert reply.content == "blah"
예제 #5
0
def find_or_create_user(uuid, username, session):
    """
    Returns a user object representing the referenced journalist UUID.
    If the user does not already exist in the data, a new instance is created.
    If the user exists but the username has changed, the username is updated.
    """
    user = session.query(User).filter_by(uuid=uuid).one_or_none()
    if user and user.username == username:
        # User exists in the local database and the username is unchanged.
        return user
    elif user and user.username != username:
        # User exists in the local database but the username is changed.
        user.username = username
        session.add(user)
        session.commit()
        return user
    else:
        # User does not exist in the local database.
        new_user = User(username)
        new_user.uuid = uuid
        session.add(new_user)
        session.commit()
        return new_user
예제 #6
0
def test_string_representation_of_user():
    user = User('hehe')
    user.__repr__()