Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Update vagrant image #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Vagrant.configure("2") do |config|
config.vm.hostname = "flask-example-berkshelf"

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "quantal64-vanilla"
config.vm.box = "virtualbox"

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "https://dl.dropboxusercontent.com/u/165709740/boxes/quantal64-vanilla.box"
config.vm.box_url = "https://vagrantcloud.com/ubuntu/trusty64/version/1/provider/virtualbox.box"

# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Manager module
"""

from flask.ext.script import Manager
from flask_script import Manager

from overholt.api import create_app
from overholt.manage import CreateUserCommand, DeleteUserCommand, ListUsersCommand
Expand Down
2 changes: 1 addition & 1 deletion overholt/manage/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from flask import current_app
from flask.ext.script import Command, prompt, prompt_pass
from flask_script import Command, prompt, prompt_pass
from flask_security.forms import RegisterForm
from flask_security.registerable import register_user
from werkzeug.datastructures import MultiDict
Expand Down
6 changes: 3 additions & 3 deletions overholt/products/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

Product forms
"""

from flask_wtf import Form, TextField, SelectMultipleField, Required, \
Optional
from flask_wtf import Form
from wtforms import TextField, SelectMultipleField
from wtforms.validators import Required, Optional

from ..services import products

Expand Down
4 changes: 3 additions & 1 deletion overholt/stores/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
Store forms
"""

from flask_wtf import Form, TextField, Required, Optional
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import Required, Optional

__all__ = ['NewStoreForm', 'UpdateStoreForm']

Expand Down
76 changes: 40 additions & 36 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
Flask==0.10.1
Flask-Assets==0.8
Flask-Login==0.2.3
Flask-Mail==0.7.3
Flask-Principal==0.3.3
Flask-SQLAlchemy==0.16
Flask-Script==0.5.3
Flask-Security==1.6.4
Flask-WTF==0.8
Jinja2==2.7
Mako==0.8.1
MarkupSafe==0.18
MySQL-python==1.2.4
Flask-Assets==0.9
Flask-Login==0.2.11
Flask-Mail==0.9.0
Flask-Principal==0.4.0
Flask-SQLAlchemy==1.0
Flask-Script==2.0.5
Flask-Security==1.7.2
Flask-WTF==0.9.5
Flask-fillin==0.2
Jinja2==2.7.3
Mako==1.0.0
MarkupSafe==0.23
MySQL-python==1.2.5
Pygments==1.6
SQLAlchemy==0.8.1
Sphinx==1.2b1
WTForms==1.0.4
Werkzeug==0.9.1
alembic==0.5.0
amqp==1.0.12
SQLAlchemy==0.9.4
Sphinx==1.2.2
WTForms==2.0
Werkzeug==0.9.6
alembic==0.6.5
amqp==1.4.5
anyjson==0.3.3
billiard==2.7.3.30
blinker==1.2
celery==3.0.20
cssmin==0.1.4
distribute==0.6.34
docutils==0.10
factory-boy==1.3.0
itsdangerous==0.21
jsmin==2.0.3
kombu==2.5.12
argparse==1.2.1
billiard==3.3.0.17
blinker==1.3
celery==3.1.11
cssmin==0.2.0
distribute==0.7.3
docutils==0.11
factory-boy==2.3.1
itsdangerous==0.24
jsmin==2.0.9
kombu==3.0.18
lxml==3.3.5
mock==1.0.1
nose==1.3.0
passlib==1.6.1
python-dateutil==2.1
redis==2.7.6
simplejson==3.3.0
six==1.3.0
sphinxcontrib-httpdomain==1.1.8
webassets==0.8
nose==1.3.3
passlib==1.6.2
python-dateutil==2.2
pytz==2014.4
redis==2.10.1
simplejson==3.5.2
six==1.7.2
sphinxcontrib-httpdomain==1.2.1
webassets==0.9
wsgiref==0.1.2
12 changes: 8 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
tests package
"""

from flask_fillin import FormWrapper
from flask.testing import FlaskClient
from unittest import TestCase

from overholt.core import db

from .factories import UserFactory
from .factories import UserFactory, RoleFactory
from .utils import FlaskTestCaseMixin


Expand All @@ -24,24 +26,26 @@ def _create_app(self):
raise NotImplementedError

def _create_fixtures(self):
self.user = UserFactory()
role = RoleFactory()
self.user = UserFactory(roles=[role])

def setUp(self):
super(OverholtAppTestCase, self).setUp()
self.app = self._create_app()
self.client = self.app.test_client()
self.client = FlaskClient(self.app, response_wrapper=FormWrapper)
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
self._create_fixtures()
self._create_csrf_token()

def tearDown(self):
super(OverholtAppTestCase, self).tearDown()
db.drop_all()
self.app_context.pop()

def _login(self, email=None, password=None):
r = self.get('/login')
self.csrf_token = r.form.fields['csrf_token']
email = email or self.user.email
password = password or 'password'
return self.post('/login', data={'email': email, 'password': password},
Expand Down
47 changes: 28 additions & 19 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,57 @@
from overholt.models import *


def create_sqlalchemy_model_function(class_to_create, *args, **kwargs):
entity = class_to_create(**kwargs)
db.session.add(entity)
db.session.commit()
return entity
class TestFactory(Factory):
@classmethod
def _create(cls, target_class, *args, **kwargs):
entity = target_class(**kwargs)
db.session.add(entity)
db.session.commit()
return entity

class RoleFactory(TestFactory):
class Meta:
model = Role

Factory.set_creation_function(create_sqlalchemy_model_function)


class RoleFactory(Factory):
FACTORY_FOR = Role
name = 'admin'
description = 'Administrator'


class UserFactory(Factory):
FACTORY_FOR = User
class UserFactory(TestFactory):
class Meta:
model = User

email = Sequence(lambda n: 'user{0}@overholt.com'.format(n))
password = LazyAttribute(lambda a: encrypt_password('password'))
last_login_at = datetime.utcnow()
current_login_at = datetime.utcnow()
last_login_ip = '127.0.0.1'
current_login_ip = '127.0.0.1'
login_count = 1
roles = LazyAttribute(lambda _: [RoleFactory()])
roles = []
active = True


class StoreFactory(Factory):
FACTORY_FOR = Store
class StoreFactory(TestFactory):
class Meta:
model = Store

name = Sequence(lambda n: 'Store Number {0}'.format(n))
address = '123 Overholt Alley'
city = 'Overholt'
state = 'New York'
zip_code = '12345'


class ProductFactory(Factory):
FACTORY_FOR = Product
class ProductFactory(TestFactory):
class Meta:
model = Product

name = Sequence(lambda n: 'Product Number {0}'.format(n))


class CategoryFactory(Factory):
FACTORY_FOR = Category
class CategoryFactory(TestFactory):
class Meta:
model = Category

name = Sequence(lambda n: 'Category {0}'.format(n))
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

DEBUG = False
TESTING = True
LOGIN_DISABLED = False

SQLALCHEMY_POOL_SIZE = None
SQLALCHEMY_POOL_TIMEOUT = None
Expand Down
11 changes: 0 additions & 11 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ def get_auth_headers(username=None, password=None):

class FlaskTestCaseMixin(object):

def _create_csrf_token(self):
csrf_key = 'csrf_token'
with self.client.session_transaction() as session:
session['csrf'] = csrf_key
secret_key = self.app.config['SECRET_KEY']
expires = (datetime.now() + timedelta(minutes=30)).strftime('%Y%m%d%H%M%S')
csrf_build = '%s%s' % (csrf_key, expires)
csrf_token = csrf_build.encode('utf8')
csrf_hmac = hmac.new(secret_key, csrf_token, digestmod=sha1)
self.csrf_token = '%s##%s' % (expires, csrf_hmac.hexdigest())

def _html_data(self, kwargs):
if 'data' in kwargs:
kwargs['data']['csrf_token'] = self.csrf_token
Expand Down