# Path: buckets/views.py
# def validate_payload(payload):
# def signed_url(request):
# 
# Path: buckets/exceptions.py
# class InvalidPayload(BaseException):
# class S3ResourceNotFound(BaseException):
#     def __init__(self, errors={}, *args, **kwargs):
# 
# Path: buckets/test/mocks.py
# def create_file(subdir=None, name='text.txt'):
#     path = 's3'
#     if subdir:
#         path += '/' + subdir
#     path = os.path.join(settings.MEDIA_ROOT, path, name)
#     file = open(path, 'wb')
#     file.write('Some content'.encode('utf-8'))
#     file.close()
# 
#     return file
# 
# @pytest.fixture(scope='function')
# def make_dirs(request):
#     ensure_dirs('uploads', 'downloads', 'uploads/files')
# 
#     def teardown():
#         shutil.rmtree(os.path.join(settings.MEDIA_ROOT, 's3'))
#     request.addfinalizer(teardown)


import pytest
import json
from django.http import HttpRequest
from django.core.files.storage import FileSystemStorage
from buckets import views, exceptions
from buckets.test.mocks import create_file, make_dirs  # noqa
    post_payload = {'key': 'file.txt'}
    views.validate_payload(post_payload)


def test_validate_empty_payload():
    post_payload = {}
    with pytest.raises(exceptions.InvalidPayload) as e:
        views.validate_payload(post_payload)

    assert ("'key' is required" in e.value.errors['key'])


def test_get_signed_url():
    """View should reply with error code 405 because only POST is allowed as
       request method"""
    request = HttpRequest()
    setattr(request, 'method', 'GET')

    response = views.signed_url(request)
    assert response.status_code == 405


def test_post_signed_url_with_valid_payload():
    """View should reply with error code 200 and a signed AWS URL"""
    post_payload = {'key': 'file.txt'}

    request = HttpRequest()
    setattr(request, 'method', 'POST')
    setattr(request, 'POST', post_payload)


# Path: buckets/views.py
# def validate_payload(payload):
# def signed_url(request):
# 
# Path: buckets/exceptions.py
# class InvalidPayload(BaseException):
# class S3ResourceNotFound(BaseException):
#     def __init__(self, errors={}, *args, **kwargs):
# 
# Path: buckets/test/mocks.py
# def create_file(subdir=None, name='text.txt'):
#     path = 's3'
#     if subdir:
#         path += '/' + subdir
#     path = os.path.join(settings.MEDIA_ROOT, path, name)
#     file = open(path, 'wb')
#     file.write('Some content'.encode('utf-8'))
#     file.close()
# 
#     return file
# 
# @pytest.fixture(scope='function')
# def make_dirs(request):
#     ensure_dirs('uploads', 'downloads', 'uploads/files')
# 
#     def teardown():
#         shutil.rmtree(os.path.join(settings.MEDIA_ROOT, 's3'))
#     request.addfinalizer(teardown)


# Path: tests/test_views.py
import pytest
import json
from django.http import HttpRequest
from django.core.files.storage import FileSystemStorage
from buckets import views, exceptions
from buckets.test.mocks import create_file, make_dirs  # noqa

    post_payload = {'key': 'file.txt'}
    views.validate_payload(post_payload)


def test_validate_empty_payload():
    post_payload = {}
    with pytest.raises(exceptions.InvalidPayload) as e:
        views.validate_payload(post_payload)

    assert ("'key' is required" in e.value.errors['key'])


def test_get_signed_url():
    """View should reply with error code 405 because only POST is allowed as
       request method"""
    request = HttpRequest()
    setattr(request, 'method', 'GET')

    response = views.signed_url(request)
    assert response.status_code == 405


def test_post_signed_url_with_valid_payload():
    """View should reply with error code 200 and a signed AWS URL"""
    post_payload = {'key': 'file.txt'}

    request = HttpRequest()
    setattr(request, 'method', 'POST')
    setattr(request, 'POST', post_payload)


    response = views.signed_url(request)