Ejemplo n.º 1
0
    _ID = 'id'
    FIRST_NAME = 'given_name'
    LAST_NAME = 'family_name'
    userDict = loads(data)
    return addUser(
        userDict[_ID],
        userDict[FIRST_NAME],
        userDict[LAST_NAME],
        userDict[EMAIL],
        userDict[EMAIL][0:userDict[EMAIL].find("@")])


SUCCESS_MESSAGE = 'Success'


@google_oauth.route(getPathWithPrefix(AUTHORIZED_URL))
@google.authorized_handler
@possibleException
def authorized(resp):
    try:
        access_token = resp['access_token']
    except TypeError:
        raise AuthorizationError
    headers = {'Authorization': 'OAuth ' + access_token}
    request = Request('https://www.googleapis.com/oauth2/v1/userinfo',
                      None, headers)
    res = urlopen(request)
    try:
        res = urlopen(request)
    except URLError:
        raise AuthorizationError
Ejemplo n.º 2
0
        return facebook.authorize(callback=getFacebookRedirectUrl())


SUCCESS_MESSAGE = 'Success'


def saveUserData(userDict):
    EMAIL = 'email'
    _ID = 'id'
    space = userDict["name"].find(" ")
    return addUser(userDict[_ID], userDict["name"][0:space],
                   userDict["name"][space + 2::], userDict[EMAIL],
                   userDict[EMAIL][0:userDict[EMAIL].find("@")])


@facebook_oauth.route(getPathWithPrefix(AUTHORIZED_URL))
@facebook.authorized_handler
@possibleException
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'], request.args['error_description'])
    session['oauth_token'] = (resp['access_token'], '')
    responce = facebook.get('/me?fields=name,email').data
    ID = saveUserData(responce)
    logUserIn(ID)
    return SUCCESS_MESSAGE


@facebook.tokengetter
def get_facebook_oauth_token():
 def testGetPathWithPrefix(self):
     RESULT_PATH = getPathWithPrefix('/status')
     self.assertEqual(RESULT_PATH, TEST_PATH)
Ejemplo n.º 4
0
def addResources():
    getApi().representations = DEFAULT_REPRESENTATIONS
    getApi().add_resource(ChannelsListResource, getPathWithPrefix(
        '/service/<string:serviceName>/channel'))
    getApi().add_resource(ChannelResource, getPathWithPrefix(
        '/service/<string:serviceName>/channel/<string:channelId>'))
    getApi().add_resource(PointResource, getPathWithPrefix(
        '/service/<string:serviceName>/point/<string:pointId>'))
    getApi().add_resource(PointListResource, getPathWithPrefix(
        '/service/<string:serviceName>/point'))
    getApi().add_resource(LogoutResource, getPathWithPrefix('/logout'))
    getApi().add_resource(LoginResource, getPathWithPrefix('/login'))
    getApi().add_resource(LoginGoogleResource, getPathWithPrefix(
        '/login/google'))
    getApi().add_resource(LoginFacebookResource,
                          getPathWithPrefix('/login/facebook'))
    getApi().add_resource(DebugLoginResource, getPathWithPrefix(
        '/login/debug'))
    getApi().add_resource(TestsResource, getPathWithPrefix('/tests'))
    getApi().add_resource(AdminServiceListResource, getPathWithPrefix(
        '/admin/service'))
    getApi().add_resource(AdminServiceResource, getPathWithPrefix(
        '/admin/service/<service_id>'))
    getApi().add_resource(
        MapResource,
        getPathWithPrefix('/service/<string:serviceName>/map'))
    getApi().add_resource(
        GetAllPluginsWithStatusResource,
        getPathWithPrefix('/plugin'))
    getApi().add_resource(
        ManagePluginsResource,
        getPathWithPrefix('/manage_plugins'))
    getApi().add_resource(
        InternalTestsResource,
        getPathWithPrefix('/internal_tests'))
    getApi().add_resource(
        AdminResource,
        getPathWithPrefix('/admin'))
    getApi().add_resource(
        AdminLogResource,
        getPathWithPrefix('/admin/log'))
    getApi().add_resource(
        ServiceResource,
        getPathWithPrefix('/service/<string:serviceName>'))
    getApi().add_resource(
        StatusResource,
        getPathWithPrefix('/status'))
    getApi().add_resource(
        ServiceListResource,
        getPathWithPrefix('/service'))
    getApi().add_resource(
        DebugInfoResource,
        getPathWithPrefix('/debug_info'))
    getApi().add_resource(
        LogResource,
        getPathWithPrefix('/service/<string:serviceName>/log'),
        getPathWithPrefix('/log'))
    getApi().add_resource(
        UserFindResource,
        getPathWithPrefix('/user/<string:user_id>'))
    getApi().add_resource(
        PluginConfigResource,
        getPathWithPrefix('/plugin_config/<string:pluginName>'))
    getApi().add_resource(
        UserListResource,
        getPathWithPrefix('/user'))
    getApi().add_resource(
        MacrosTestsResource,
        getPathWithPrefix('/macros_tests'))
    getApi().add_resource(
        MetadataResource,
        getPathWithPrefix(
            '/service/<string:serviceName>/metadata/<string:metadata_id>'))
    getApi().add_resource(
        MetadataListResource,
        getPathWithPrefix(
            '/service/<string:serviceName>/metadata'))
    getApi().add_resource(AdminPluginListResource, getPathWithPrefix(
        '/admin/plugin'))
    getApi().add_resource(AdminPluginConfigResource, getPathWithPrefix(
        '/admin/plugin/config/<string:pluginName>'))
    getApi().add_resource(IconResource, getPathWithPrefix(
        '/service/<string:serviceName>/get_icon'))

    # end of the list of imported resources

    atexit.register(closeConnection)

    initApp(getApi())
Ejemplo n.º 5
0
def addResources():
    getApi().representations = DEFAULT_REPRESENTATIONS
    getApi().add_resource(ChannelsListResource, getPathWithPrefix(
        '/service/<string:serviceName>/channel'))
    getApi().add_resource(ChannelResource, getPathWithPrefix(
        '/service/<string:serviceName>/channel/<string:channelId>'))
    getApi().add_resource(PointResource, getPathWithPrefix(
        '/service/<string:serviceName>/point/<string:pointId>'))
    getApi().add_resource(PointListResource, getPathWithPrefix(
        '/service/<string:serviceName>/point'))
    getApi().add_resource(LogoutResource, getPathWithPrefix('/logout'))
    getApi().add_resource(LoginResource, getPathWithPrefix('/login'))
    getApi().add_resource(LoginGoogleResource, getPathWithPrefix(
        '/login/google'))
    getApi().add_resource(LoginFacebookResource,
                          getPathWithPrefix('/login/facebook'))
    getApi().add_resource(DebugLoginResource, getPathWithPrefix(
        '/login/debug'))
    getApi().add_resource(TestsResource, getPathWithPrefix('/tests'))
    getApi().add_resource(AdminServiceListResource, getPathWithPrefix(
        '/admin/service'))
    getApi().add_resource(AdminServiceResource, getPathWithPrefix(
        '/admin/service/<service_id>'))
    getApi().add_resource(
        MapResource,
        getPathWithPrefix('/service/<string:serviceName>/map'))
    getApi().add_resource(
        GetAllPluginsWithStatusResource,
        getPathWithPrefix('/plugin'))
    getApi().add_resource(
        ManagePluginsResource,
        getPathWithPrefix('/manage_plugins'))
    getApi().add_resource(
        InternalTestsResource,
        getPathWithPrefix('/internal_tests'))
    getApi().add_resource(
        AdminResource,
        getPathWithPrefix('/admin'))
    getApi().add_resource(
        AdminLogResource,
        getPathWithPrefix('/admin/log'))
    getApi().add_resource(
        ServiceResource,
        getPathWithPrefix('/service/<string:serviceName>'))
    getApi().add_resource(
        StatusResource,
        getPathWithPrefix('/status'))
    getApi().add_resource(
        ServiceListResource,
        getPathWithPrefix('/service'))
    getApi().add_resource(
        DebugInfoResource,
        getPathWithPrefix('/debug_info'))
    getApi().add_resource(
        LogResource,
        getPathWithPrefix('/service/<string:serviceName>/log'),
        getPathWithPrefix('/log'))
    getApi().add_resource(
        UserFindResource,
        getPathWithPrefix('/user/<string:user_id>'))
    getApi().add_resource(
        PluginConfigResource,
        getPathWithPrefix('/plugin_config/<string:pluginName>'))
    getApi().add_resource(
        UserListResource,
        getPathWithPrefix('/user'))
    getApi().add_resource(
        MacrosTestsResource,
        getPathWithPrefix('/macros_tests'))
    getApi().add_resource(
        MetadataResource,
        getPathWithPrefix(
            '/service/<string:serviceName>/metadata/<string:metadata_id>'))
    getApi().add_resource(
        MetadataListResource,
        getPathWithPrefix(
            '/service/<string:serviceName>/metadata'))
    # end of the list of imported resources

    atexit.register(closeConnection)

    initApp(getApi())
from unittest import TestCase
from flask import Flask
from rest_api_routines import createWebCacheInvalidator
from flask import g
from url_utils import getPathWithPrefix

TEST_URL = getPathWithPrefix('/login')

app = Flask(__name__)


class TestCacheIvalidator(TestCase):

    def testCacheIvalidator(self):
        with app.test_request_context(TEST_URL):
            createWebCacheInvalidator()
            self.assertIsNotNone(g.cache_invalidator)
Ejemplo n.º 7
0
SUCCESS_MESSAGE = 'Success'


def saveUserData(userDict):
    EMAIL = 'email'
    _ID = 'id'
    space = userDict["name"].find(" ")
    return addUser(
        userDict[_ID],
        userDict["name"][0:space],
        userDict["name"][space + 2::],
        userDict[EMAIL],
        userDict[EMAIL][0:userDict[EMAIL].find("@")])


@facebook_oauth.route(getPathWithPrefix(AUTHORIZED_URL))
@facebook.authorized_handler
@possibleException
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['oauth_token'] = (resp['access_token'], '')
    responce = facebook.get('/me?fields=name,email').data
    ID = saveUserData(responce)
    logUserIn(ID)
    return SUCCESS_MESSAGE

 def testGetPathWithPrefix(self):
     RESULT_PATH = getPathWithPrefix('/status')
     self.assertEqual(RESULT_PATH, TEST_PATH)
from unittest import TestCase
from flask import Flask
from flask import g
from url_utils import getPathWithPrefix
from rest_api_routines import defineInstancePrefix

TEST_URL = getPathWithPrefix('/login')
INSTACNE_PREFIX = 'instance'

app = Flask(__name__)


class TestDefineInstancePrefixInBaseTemplate(TestCase):

    def testDefineInstancePrefixInBaseTemplate(self):
        with app.test_request_context(TEST_URL):
            defineInstancePrefix()
            self.assertEqual(g.instance_prefix, INSTACNE_PREFIX)