Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
*.py[co]
__pycache__*
.cache

# Packages
*.egg
*.egg-info
dist
build
eggs
.eggs
parts
bin
var
Expand All @@ -32,14 +34,7 @@ docs/_build*
.tox
.cache

tests/*
!tests/__init__.py
!tests/config.py
!tests/test_cloudy.py

tests/data/*
!tests/data/hello.txt
!tests/data/hello.js

tests/container_1/*
!tests/container_1/empty
!tests/testconf.py
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[metadata]
description-file = README.md
description-file = README.md

[aliases]
test=pytest
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
],
zip_safe=False
zip_safe=False,
test_suite="tests",
setup_requires=['pytest-runner'],
tests_require=['pytest']
)

22 changes: 15 additions & 7 deletions tests/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
"""Config for tests."""

class RemoteConfig(object):
"""Config for remote testing."""
STORAGE_PROVIDER = "S3"
STORAGE_KEY = ""
STORAGE_SECRET = ""
STORAGE_CONTAINER = "yoredis.com"
STORAGE_ALLOWED_EXTENSIONS = []

PROVIDER = "S3"
KEY = ""
SECRET = ""
CONTAINER = "yoredis.com"

# FOR LOCAL
PROVIDER = "LOCAL"
CONTAINER = "container_1"
class LocalConfig(object):
"""Config for local testing."""
STORAGE_KEY = ""
STORAGE_SECRET = ""
STORAGE_PROVIDER = "LOCAL"
STORAGE_CONTAINER = 'container_1'
STORAGE_ALLOWED_EXTENSIONS = []
69 changes: 69 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Defines fixtures available to all tests."""

import pytest
from tempfile import TemporaryDirectory, NamedTemporaryFile
import os
from flask import Flask
from flask_cloudy import Storage
from tests.config import LocalConfig
import random


@pytest.yield_fixture(scope='function')
def temp_dir():
"""A temporary directory for each test."""
with TemporaryDirectory() as temp_dir:
yield temp_dir

@pytest.yield_fixture(scope='function')
def temp_container():
"""A temporary container directory for each test."""
with TemporaryDirectory() as temp_dir:
yield temp_dir

@pytest.yield_fixture(scope='function')
def temp_txt_file():
"""A temporary txt file with random contents for each test."""
with NamedTemporaryFile(mode="w+", suffix=".txt") as temp_file:
temp_file.write('%s' % random.random())
temp_file.file.seek(0)
yield temp_file


@pytest.yield_fixture(scope='function')
def temp_png_file():
"""A temporary txt file with random contents for each test."""
with NamedTemporaryFile(suffix=".png") as temp_file:
yield temp_file


@pytest.yield_fixture(scope='function')
def temp_js_file():
"""A temporary js file with random contents for each test."""
with NamedTemporaryFile(mode="w+", suffix=".js") as temp_file:
temp_file.write('%s' % random.random())
temp_file.file.seek(0)
yield temp_file


@pytest.yield_fixture(scope='function')
def app(temp_container):
"""An application for the tests."""
app = Flask(__name__)
LocalConfig.STORAGE_CONTAINER = temp_container
app.config.from_object(LocalConfig)

ctx = app.test_request_context()
ctx.push()

yield app

ctx.pop()


@pytest.fixture(scope='function')
def storage(app):
"""A flask-cloudy storage instance for tests."""
storage = Storage(app=app)
storage.app = app
return storage
Empty file removed tests/container_1/empty
Empty file.
1 change: 0 additions & 1 deletion tests/data/hello.js

This file was deleted.

Empty file removed tests/data/hello.txt
Empty file.
Loading