Exemple #1
0
from api.system.logger import ilogger as logger
from api.util import api_cfg
from api.util import lowercase_all
from api.domain.user import User

from flask import jsonify
from flask import make_response
from flask import request
from flask.ext.httpauth import HTTPBasicAuth
from flask.ext.restful import Resource

from werkzeug.exceptions import BadRequest

from functools import wraps

espa = APIv1()
auth = HTTPBasicAuth()
cache = memcache.Client(['127.0.0.1:11211'], debug=0)


def greylist(func):
    """
    Provide a decorator to enact black and white lists on user endpoints

    References http://flask.pocoo.org/docs/0.11/deploying/wsgi-standalone/#proxy_setups
    and http://github.com/mattupsate/flask-security
    """
    @wraps(func)
    def decorated(*args, **kwargs):
        black_ls = api_cfg().get('user_blacklist')
        white_ls = api_cfg().get('user_whitelist')
Exemple #2
0
from api import ValidationException, InventoryException, __location__

import os
from api.domain.mocks.order import MockOrder
from api.domain.mocks.user import MockUser
from api.domain.order import Order
from api.domain.user import User
from api.providers.configuration.configuration_provider import ConfigurationProvider
from api.providers.production.mocks.production_provider import MockProductionProvider
from api.providers.production.production_provider import ProductionProvider
from api.external.mocks import lta as mocklta
from api.external.mocks import inventory as mockinventory
from api.system.logger import ilogger as logger
from mock import patch

api = APIv1()
production_provider = ProductionProvider()
mock_production_provider = MockProductionProvider()
cfg = ConfigurationProvider()


class TestAPI(unittest.TestCase):
    def setUp(self):
        logger.warning('Testing API started...')
        os.environ['espa_api_testing'] = 'True'
        # create a user
        self.mock_user = MockUser()
        self.mock_order = MockOrder()
        user_id = self.mock_user.add_testing_user()
        order_id = self.mock_order.generate_testing_order(user_id)
        self.order = Order.find(order_id)