Beispiel #1
0
def test_file_descriptors_no_team(mock_block):
    block = mock_block(
        descriptions=['The first file', 'The second file'],
        names=['File A', 'File B'],
        sizes=[22, 44],
    )
    block.is_team_assignment.return_value = False

    file_manager = api.FileUploadManager(block)

    actual_descriptors = file_manager.file_descriptors()
    expected_descriptors = [
        {
            'download_url': '',
            'name': 'File A',
            'size': 22,
            'description': 'The first file',
            'show_delete_button': True
        },
        {
            'download_url': '',
            'name': 'File B',
            'size': 44,
            'description': 'The second file',
            'show_delete_button': True
        },
    ]

    assert expected_descriptors == actual_descriptors
Beispiel #2
0
def test_file_descriptors_after_sharing_with_old_team(
        mock_get_download_url, mock_remove_file, shared_file_upload_fixture, mock_block
):
    # Include a deleted file entry, and later assert that we have empty file descriptors
    # returned by ``file_descriptors()``
    block = mock_block(
        descriptions=['The first file', 'The deleted file', 'The second file'],
        names=['File A', 'File that is deleted', 'File B'],
        sizes=[22, 666, 44],
    )
    block.team.team_id = DEFAULT_TEAM_ID
    block.is_team_assignment.return_value = True

    student_item_dict = {
        'student_id': DEFAULT_OWNER_ID,
        'course_id': DEFAULT_COURSE_ID,
        'item_id': DEFAULT_ITEM_ID,
    }
    key_a = api.get_student_file_key(student_item_dict, index=0)
    key_deleted = api.get_student_file_key(student_item_dict, index=1)
    key_b = api.get_student_file_key(student_item_dict, index=2)

    # create a shared upload that was shared with an old team
    _ = shared_file_upload_fixture(team_id='an-old-team', file_key=key_a)

    # create one for the file we're going to delete
    _ = shared_file_upload_fixture(team_id=block.team.team_id, file_key=key_deleted)

    # create a shared upload that's shared with the learner's current team
    _ = shared_file_upload_fixture(team_id=block.team.team_id, file_key=key_b)

    file_manager = api.FileUploadManager(block)

    # go and delete the file we want to delete
    file_manager.delete_upload(1)

    # file_descriptors() should only give back a record for the upload shared with the current team
    actual_descriptors = file_manager.file_descriptors(team_id=block.team.team_id, include_deleted=True)
    expected_descriptors = [
        {
            'download_url': None,
            'name': None,
            'description': None,
            'size': 0,
            'show_delete_button': False,
        },
        {
            'download_url': mock_get_download_url.return_value,
            'name': 'File B',
            'description': 'The second file',
            'size': 44,
            'show_delete_button': True,
        }
    ]

    assert expected_descriptors == actual_descriptors
    mock_get_download_url.assert_called_once_with(key_b)
    mock_remove_file.assert_called_once_with(key_deleted)
Beispiel #3
0
def test_file_descriptor_tuples_no_team(mock_block):
    block = mock_block(
        descriptions=['The first file', 'The second file'],
        names=['File A', 'File B'],
        sizes=[22, 44],
    )
    block.is_team_assignment.return_value = False

    file_manager = api.FileUploadManager(block)

    actual_descriptors = file_manager.file_descriptor_tuples()
    expected_descriptors = [
        api.FileDescriptor(download_url='', name='File A', description='The first file', show_delete_button=True),
        api.FileDescriptor(download_url='', name='File B', description='The second file', show_delete_button=True),
    ]

    assert expected_descriptors == actual_descriptors
Beispiel #4
0
def test_shared_uploads_for_student_by_key(shared_file_upload_fixture, mock_block):
    file_keys = ['key-1', 'key-2', 'key-3']

    for file_key in file_keys:
        _ = shared_file_upload_fixture(file_key=file_key)

    block = mock_block()
    file_manager = api.FileUploadManager(block)

    shared_uploads_by_key = file_manager.shared_uploads_for_student_by_key

    assert len(shared_uploads_by_key) == 3

    for expected_key in file_keys:
        shared_file_upload = shared_uploads_by_key[expected_key]

        assert shared_file_upload.team_id == DEFAULT_TEAM_ID
        assert shared_file_upload.course_id == DEFAULT_COURSE_ID
        assert shared_file_upload.item_id == DEFAULT_ITEM_ID
Beispiel #5
0
 def file_manager(self):
     return file_upload_api.FileUploadManager(self)
Beispiel #6
0
def test_team_files_metadata(mock_get_download_url, shared_file_upload_fixture, mock_block):
    mock_get_download_url.return_value = "some-download-url"
    block = mock_block(
        descriptions=['The first file'],
        names=['File A'],
        sizes=[22],
    )
    block.team.team_id = DEFAULT_TEAM_ID
    block.is_team_assignment.return_value = True

    student_item_dict = {
        'student_id': DEFAULT_OWNER_ID,
        'course_id': DEFAULT_COURSE_ID,
        'item_id': DEFAULT_ITEM_ID,
    }
    key_a = api.get_student_file_key(student_item_dict, index=0)

    # create a shared upload that's shared with the learner's current team
    _ = shared_file_upload_fixture(team_id=block.team.team_id, file_key=key_a)

    # create a couple of files uploaded by teammates
    key_beta = api.get_student_file_key(
        {'student_id': 'another-student', 'course_id': DEFAULT_COURSE_ID, 'item_id': DEFAULT_ITEM_ID}
    )
    _ = shared_file_upload_fixture(
        description='Another file',
        name='File Beta',
        team_id=block.team.team_id,
        owner_id='another-student',
        file_key=key_beta,
    )

    key_delta = api.get_student_file_key(
        {'student_id': 'yet-another-student', 'course_id': DEFAULT_COURSE_ID, 'item_id': DEFAULT_ITEM_ID}
    )
    _ = shared_file_upload_fixture(
        description='Yet another file',
        name='File Delta',
        team_id=block.team.team_id,
        owner_id='yet-another-student',
        file_key=key_delta,
    )

    file_manager = api.FileUploadManager(block)

    # team_file_descriptors() should only give back records for files owned by teammates
    actual_descriptors = file_manager.team_file_descriptors(team_id=block.team.team_id)

    expected_descriptors = [
        {
            'download_url': mock_get_download_url.return_value,
            'name': 'File Beta',
            'description': 'Another file',
            'size': 0,
            'uploaded_by': 'some_username',
        },
        {
            'download_url': mock_get_download_url.return_value,
            'name': 'File Delta',
            'description': 'Yet another file',
            'size': 0,
            'uploaded_by': 'some_username',
        }
    ]
    assert expected_descriptors == actual_descriptors
    mock_get_download_url.assert_has_calls([
        mock.call(key_beta),
        mock.call(key_delta),
    ])