示例#1
0
def test_get_hls_access_cookies(cloudfront_client, s3_uploads_client):
    user_id = 'uid'
    post_id = 'pid'
    item = {
        'postedByUserId': user_id,
        'postId': post_id,
        'postType': PostType.VIDEO,
        'postStatus': PostStatus.COMPLETED,
    }
    domain = 'cf-domain'
    expires_at = pendulum.now('utc')
    presigned_cookies = {
        'ExpiresAt': expires_at.to_iso8601_string(),
        'CloudFront-Policy': 'cf-policy',
        'CloudFront-Signature': 'cf-signature',
        'CloudFront-Key-Pair-Id': 'cf-kpid',
    }
    cloudfront_client.configure_mock(
        **{'generate_presigned_cookies.return_value': presigned_cookies, 'domain': domain}
    )

    post = Post(item, cloudfront_client=cloudfront_client, s3_uploads_client=s3_uploads_client)
    access_cookies = post.get_hls_access_cookies()

    assert access_cookies == {
        'domain': domain,
        'path': f'/{user_id}/post/{post_id}/video-hls/',
        'expiresAt': expires_at.to_iso8601_string(),
        'policy': 'cf-policy',
        'signature': 'cf-signature',
        'keyPairId': 'cf-kpid',
    }

    cookie_path = f'{user_id}/post/{post_id}/video-hls/video*'
    assert cloudfront_client.mock_calls == [mock.call.generate_presigned_cookies(cookie_path)]
示例#2
0
def test_get_image_readonly_url(cloudfront_client, s3_uploads_client):
    item = {
        'postedByUserId': 'user-id',
        'postId': 'post-id',
        'postType': PostType.IMAGE,
        'postStatus': PostStatus.PENDING,
    }
    expected_url = {}
    cloudfront_client.configure_mock(**{'generate_presigned_url.return_value': expected_url})

    post = Post(item, cloudfront_client=cloudfront_client, s3_uploads_client=s3_uploads_client)
    url = post.get_image_readonly_url(image_size.NATIVE)
    assert url == expected_url

    expected_path = f'user-id/post/post-id/image/{image_size.NATIVE.filename}'
    assert cloudfront_client.mock_calls == [mock.call.generate_presigned_url(expected_path, ['GET', 'HEAD'])]
示例#3
0
def test_get_video_writeonly_url(cloudfront_client, s3_uploads_client):
    item = {
        'postedByUserId': 'user-id',
        'postId': 'post-id',
        'postType': PostType.VIDEO,
        'postStatus': PostStatus.PENDING,
    }
    expected_url = {}
    cloudfront_client.configure_mock(**{'generate_presigned_url.return_value': expected_url})

    post = Post(item, cloudfront_client=cloudfront_client, s3_uploads_client=s3_uploads_client)
    url = post.get_video_writeonly_url()
    assert url == expected_url

    expected_path = 'user-id/post/post-id/video-original.mov'
    assert cloudfront_client.mock_calls == [mock.call.generate_presigned_url(expected_path, ['PUT'])]