コード例 #1
1
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        db.create_all()
        test_password = '******'
        Organization.insert_org()
        UserScope.insert_scopes()
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)

        # set the vars for the connection
        self.cmisUrl =  \
            'https://alfresco.oceanobservatories.org/alfresco/s/api/cmis'
        self.cmisUsername = '******'
        self.cmisPassword = '******'
        self.cmisId = 'c161bc66-4f7e-4a4f-b5f2-aac9fbf1d3cd'

        # cmis is tested elsewhere

        from cmislib.model import CmisClient
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        repo = client.getRepository(self.cmisId)
コード例 #2
0
ファイル: manage.py プロジェクト: ssontag55/ooi-ui-services
def deploy(password, bulkload):
    from flask.ext.migrate import upgrade
    from ooiservices.app.models import User, UserScope, UserScopeLink, Array
    from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink
    from sh import psql
    #Create the local database
    app.logger.info('Creating DEV and TEST Databases')
    psql('-c', 'create database ooiuidev;', '-U', 'postgres')
    psql('ooiuidev', '-c', 'create schema ooiui')
    psql('ooiuidev', '-c', 'create extension postgis')
    #Create the local test database
    psql('-c', 'create database ooiuitest;', '-U', 'postgres')
    psql('ooiuitest', '-c', 'create schema ooiui')
    psql('ooiuitest', '-c', 'create extension postgis')
    db.create_all()
    if bulkload:
        with open('db/ooiui_schema_data.sql') as f:
            psql('ooiuidev', _in=f)
        app.logger.info('Bulk test data loaded.')

    # migrate database to latest revision
    #upgrade()
    UserScope.insert_scopes()
    app.logger.info('Insert default user, name: admin')
    User.insert_user(password=password)
    admin = User.query.first()
    admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
    db.session.add(admin)
    db.session.commit()
コード例 #3
0
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        from sqlalchemy.orm.mapper import configure_mappers
        configure_mappers()
        db.create_all()

        test_username = '******'
        test_password = '******'
        Organization.insert_org()
        User.insert_user(username=test_username,
                         password=test_password,
                         email='*****@*****.**')

        OperatorEventType.insert_operator_event_types()

        self.client = self.app.test_client(use_cookies=False)

        UserScope.insert_scopes()

        admin = User.query.filter_by(user_name='admin').first()
        scope = UserScope.query.filter_by(scope_name='user_admin').first()
        admin.scopes.append(scope)

        db.session.add(admin)
        db.session.commit()

        joe = User.insert_user(username='******',
                               password='******',
                               email='*****@*****.**')
        bob = User.insert_user(username='******',
                               password='******',
                               email='*****@*****.**')
コード例 #4
0
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        from sqlalchemy.orm.mapper import configure_mappers
        configure_mappers()
        db.create_all()

        test_username = '******'
        test_password = '******'
        Organization.insert_org()
        User.insert_user(username=test_username, password=test_password, email='*****@*****.**')


        OperatorEventType.insert_operator_event_types()

        self.client = self.app.test_client(use_cookies=False)

        UserScope.insert_scopes()

        admin = User.query.filter_by(user_name='admin').first()
        scope = UserScope.query.filter_by(scope_name='asset_manager').first()
        admin.scopes.append(scope)

        db.session.add(admin)
        db.session.commit()

        joe = User.insert_user(username='******', password='******', email='*****@*****.**')
        bob = User.insert_user(username='******', password='******', email='*****@*****.**')
コード例 #5
0
ファイル: test_sys.py プロジェクト: ssontag55/ooi-ui-services
 def setUp(self):
     self.app = create_app('TESTING_CONFIG')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client(use_cookies=False)
     User.insert_user(username=test_username, password=test_password)
     UserScope.insert_scopes()
コード例 #6
0
ファイル: test_sys.py プロジェクト: Bobfrat/ooi-ui-services
 def setUp(self):
     self.app = create_app('TESTING_CONFIG')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client(use_cookies=False)
     Organization.insert_org()
     User.insert_user(username=test_username, password=test_password)
     UserScope.insert_scopes()
コード例 #7
0
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_password = '******'
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)
コード例 #8
0
    def setUp(self):
        self.app = create_app("TESTING_CONFIG")
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_password = "******"
        Organization.insert_org()
        User.insert_user(password=test_password, email="test@localhost")

        self.client = self.app.test_client(use_cookies=False)
コード例 #9
0
ファイル: manage.py プロジェクト: ssontag55/ooi-ui-services
def add_admin_user(username, password, first_name, last_name, email, org_name):
    '''
    Creates a 'user_admin' scoped user using the supplied username and password
    :param username:
    :param password:
    :return:
    '''
    app.logger.info('Insert user, name: %s' % username)
    User.insert_user(username=username, password=password, first_name=first_name, last_name=last_name, email=email, org_name=org_name)
    admin = User.query.filter_by(user_name=username).first()
    admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
    db.session.add(admin)
    db.session.commit()
コード例 #10
0
ファイル: manage.py プロジェクト: RyanMaciel/ooi-ui-services
def add_admin_user(username, password, first_name, last_name, email, org_name):
    '''
    Creates a 'user_admin' scoped user using the supplied username and password
    :param username:
    :param password:
    :return:
    '''
    app.logger.info('Insert user_name: %s' % username)
    User.insert_user(username=username, password=password, first_name=first_name, last_name=last_name, email=email, org_name=org_name)
    admin = User.query.filter_by(user_name=username).first()
    admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
    admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
    db.session.add(admin)
    db.session.commit()
コード例 #11
0
def oauth_callback(provider):
    # rand_pass will be a new password every time a user logs in
    # with oauth.
    temp_pass = str(uuid.uuid4())

    # lets create the oauth object that will issue the request.
    oauth = OAuthSignIn.get_provider(provider)

    # assign the response
    email, first_name, last_name = oauth.callback()

    if email is None:
        return unauthorized('Invalid credentials')

    # see if this user already exists, and
    # and give the user a brand new password.
    user = User.query.filter_by(email=email).first()
    if user:
        user.password = temp_pass

    # if there is no user, create a new one and setup
    # it's defaults and give it a new password.
    else:
        user = User.insert_user(password=temp_pass,
                         username=email,
                         email=email,
                         first_name=first_name,
                         last_name=last_name)

    return jsonify({'uuid': temp_pass, 'username': email})
コード例 #12
0
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_username = '******'
        test_password = '******'
        Organization.insert_org()
        User.insert_user(username=test_username, password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        UserScope.insert_scopes()
        admin = User.query.filter_by(user_name='admin').first()
        scope = UserScope.query.filter_by(scope_name='user_admin').first()
        admin.scopes.append(scope)
        db.session.add(admin)
        db.session.commit()
コード例 #13
0
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_password = '******'
        Organization.insert_org()
        UserScope.insert_scopes()
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        with open(self.basedir + '/mock_data/event_post.json', 'r') as f:
            doc = json.load(f)
        self.event_json_in = doc

        with open(self.basedir + '/mock_results/event_from.json', 'r') as f:
            doc = json.load(f)
        self.event_from_json = doc
コード例 #14
0
    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_password = '******'
        Organization.insert_org()
        UserScope.insert_scopes()
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        with open(self.basedir + '/mock_data/event_post.json', 'r') as f:
            doc = json.load(f)
        self.event_json_in = doc

        with open(self.basedir + '/mock_results/event_from.json', 'r') as f:
            doc = json.load(f)
        self.event_from_json = doc
コード例 #15
0
    def setUp(self):
        self.app = create_app("TESTING_CONFIG")
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_username = "******"
        test_password = "******"
        Organization.insert_org()

        User.insert_user(username=test_username, password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        UserScope.insert_scopes()
        admin = User.query.filter_by(user_name="admin").first()
        scope = UserScope.query.filter_by(scope_name="user_admin").first()
        cc_scope = UserScope.query.filter_by(scope_name="command_control").first()
        admin.scopes.append(scope)
        admin.scopes.append(cc_scope)
        db.session.add(admin)
        db.session.commit()

        self.headers = self.get_api_headers("admin", "test")
コード例 #16
0
ファイル: manage.py プロジェクト: RyanMaciel/ooi-ui-services
def deploy(password, bulkload):
    from flask.ext.migrate import upgrade
    from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization
    from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink
    from sh import psql
    #Create the local database
    app.logger.info('Creating DEV and TEST Databases')
    psql('-c', 'create database ooiuidev;', '-U', 'postgres')
    psql('ooiuidev', '-c', 'create schema ooiui')
    psql('ooiuidev', '-c', 'create extension postgis')
    #Create the local test database
    psql('-c', 'create database ooiuitest;', '-U', 'postgres')
    psql('ooiuitest', '-c', 'create schema ooiui')
    psql('ooiuitest', '-c', 'create extension postgis')
    from sqlalchemy.orm.mapper import configure_mappers
    configure_mappers()
    db.create_all()
    if bulkload:
        with open('db/ooiui_schema_data.sql') as f:
            psql('ooiuidev', _in=f)
        app.logger.info('Bulk test data loaded.')

    # migrate database to latest revision
    #upgrade()
    if not os.getenv('TRAVIS'):
        Organization.insert_org()
        UserScope.insert_scopes()
        app.logger.info('Insert default user, name: admin')
        User.insert_user(password=password)
        admin = User.query.first()
        admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
        admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
        db.session.add(admin)
        db.session.commit()
        if bulkload:
            with open('db/ooiui_schema_data_notifications.sql') as f:
                psql('ooiuidev', _in=f)
            app.logger.info('Bulk test data loaded for notifications.')
コード例 #17
0
    def test_update_user_event_notification(self):
        verbose = False #self.verbose
        root = self.root

        if verbose: print '\n'
        content_type =  'application/json'
        headers = self.get_api_headers('admin', 'test')

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # Add a second user ('foo', password 'test')
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test_username = '******'
        test_password = '******'
        test_email = '*****@*****.**'
        Organization.insert_org()
        User.insert_user(username=test_username, password=test_password, email=test_email)
        self.client = self.app.test_client(use_cookies=False)
        UserScope.insert_scopes()
        foo = User.query.filter_by(user_name='foo').first()
        scope = UserScope.query.filter_by(scope_name='user_admin').first()
        foo.scopes.append(scope)
        scope = UserScope.query.filter_by(scope_name='redmine').first()     # added
        foo.scopes.append(scope)
        db.session.add(foo)
        db.session.commit()

        response = self.client.get(url_for('main.get_user',id=1), headers=headers)
        self.assertTrue(response.status_code == 200)

        response = self.client.get(url_for('main.get_user',id=2), headers=headers)
        self.assertTrue(response.status_code == 200)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # # Create alert and an alarm
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        ref_def = "CE01ISSP-XX099-01-CTDPFJ999"
        # Create an alarm with user_event_notification - uses definition 1 and user_id 1
        test_alarm = self.create_alert_alarm_definition(ref_def, event_type='alarm', uframe_id=2, severity=1)

        # Create an alarm without user_event_notification - uses definition 1 and user_id 1
        bad_alarm = self.create_alert_alarm_definition_wo_notification(ref_def, event_type='alarm',
                                                                       uframe_filter_id=2, severity=1)

        notification = self.create_user_event_notification(bad_alarm.id, 2)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # GET alarm definition by SystemEventDefinition id
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        response = self.client.get(url_for('main.get_alert_alarm_def', id=test_alarm.id), headers=headers)
        self.assertEquals(response.status_code, 200)
        alarm_definition = json.loads(response.data)
        self.assertTrue(alarm_definition is not None)

        response = self.client.get(url_for('main.get_alert_alarm_def', id=bad_alarm.id), headers=headers)
        self.assertEquals(response.status_code, 200)
        bad_alarm_definition = json.loads(response.data)
        self.assertTrue(bad_alarm_definition is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # Get user_event_notifications (1)
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        response = self.client.get(url_for('main.get_user_event_notifications'), headers=headers)
        self.assertEquals(response.status_code, 200)
        data = json.loads(response.data)
        self.assertTrue(data is not None)
        notifications = data['notifications']
        self.assertTrue(notifications is not None)
        self.assertEquals(len(notifications), 2)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # Get user_event_notification by id=1
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        url = url_for('main.get_user_event_notification', id=1)
        response = self.client.get(url, content_type=content_type, headers=headers)
        self.assertEquals(response.status_code, 200)
        notification = json.loads(response.data)
        self.assertTrue(len(notification) > 0)
        self.assertEquals(len(notification), 8)

        """
        Error messages for the following tests:

            1. bad_notification:  {}

            2. 'Invalid ID, user_event_notification record not found.'

            3. 'Inconsistent ID, user_event_notification id provided in data does not match id provided.'

            4. 'Inconsistent User ID, user_id provided in data does not match id.'

            5. 'IntegrityError creating user_event_notification.'

            6. (no error)

            7. 'Insufficient data, or bad data format.'
        """

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (1) Get user_event_notification by id=5 (doesn't exist) response: {}
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        url = url_for('main.get_user_event_notification', id=5)
        response = self.client.get(url, content_type=content_type, headers=headers)
        self.assertEquals(response.status_code, 200)
        bad_notification = json.loads(response.data)
        self.assertTrue(bad_notification is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (2) (Negative) Update event_event_notification;
        # error: 'Invalid ID, user_event_notification record not found.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {'user_id': 1,
                'system_event_definition_id': test_alarm.id,
                'use_email': False,
                'use_log': False,
                'use_phone': False,
                'use_redmine': False,
                'use_sms': False,
                'id': 50}
        bad_stuff = json.dumps(test)
        response = self.client.put(url_for('main.update_user_event_notification', id=50), headers=headers, data=bad_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (3) (Negative) Update event_event_notification
        # error: 'Inconsistent ID, user_event_notification id provided in data does not match id provided.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {'user_id': 999,
                'system_event_definition_id': 1,
                'use_email': True,
                'use_log': True,
                'use_phone': True,
                'use_redmine': True,
                'use_sms': True,
                'id': 1}
        good_stuff = json.dumps(test)
        response = self.client.put(url_for('main.update_user_event_notification', id=800), headers=headers, data=good_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (4) (Negative) Update user_event_notification, with invalid user_id
        # error: 'Inconsistent User ID, user_id provided in data does not match id.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {'user_id': 1,
                'system_event_definition_id': 2,
                'use_email': True,
                'use_log': True,
                'use_phone': True,
                'use_redmine': True,
                'use_sms': True,
                'id': 2}
        good_stuff = json.dumps(test)
        response = self.client.put(url_for('main.update_user_event_notification', id=2), headers=headers, data=good_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (5) # (Negative) Update event_event_notification
        # error: 'IntegrityError creating user_event_notification.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {'user_id': 2,
                'system_event_definition_id': bad_alarm.id,
                'use_email': False,
                'use_log': 'log',
                'use_phone': False,
                'use_redmine': False,
                'use_sms': False,
                'id': 2}
        bad_stuff = json.dumps(test)
        response = self.client.put(url_for('main.update_user_event_notification', id=2), headers=headers, data=bad_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (6) (Positive) Update event_event_notification
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {'user_id': 1,
                'system_event_definition_id': 1,
                'use_email': True,
                'use_log': True,
                'use_phone': True,
                'use_redmine': True,
                'use_sms': True,
                'id': 1}
        good_stuff = json.dumps(test)
        response = self.client.put(url_for('main.update_user_event_notification', id=1), headers=headers, data=good_stuff)
        self.assertEquals(response.status_code, 201)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue(len(notify_data) > 0)
        notify = UserEventNotification.query.get(1)

        for attribute in UserEventNotification.__table__.columns._data:
            self.assertTrue(attribute in notify_data)
            if attribute != 'user_id' or attribute != 'id':
                self.assertEquals(getattr(notify,attribute), True)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (Negative) Update event_event_notification - expect failure, invalid user_id
        # error 'Insufficient data, or bad data format.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        data = {'user_id': 10}
        good_stuff = json.dumps(data)
        response = self.client.put(url_for('main.update_user_event_notification', id=1), headers=headers, data=good_stuff)
        self.assertEquals(response.status_code, 409)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        if verbose: print '\n'
コード例 #18
0
    def test_update_user_event_notification(self):
        verbose = False  #self.verbose
        root = self.root

        if verbose: print '\n'
        content_type = 'application/json'
        headers = self.get_api_headers('admin', 'test')

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # Add a second user ('foo', password 'test')
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test_username = '******'
        test_password = '******'
        test_email = '*****@*****.**'
        Organization.insert_org()
        User.insert_user(username=test_username,
                         password=test_password,
                         email=test_email)
        self.client = self.app.test_client(use_cookies=False)
        UserScope.insert_scopes()
        foo = User.query.filter_by(user_name='foo').first()
        scope = UserScope.query.filter_by(scope_name='user_admin').first()
        foo.scopes.append(scope)
        scope = UserScope.query.filter_by(
            scope_name='redmine').first()  # added
        foo.scopes.append(scope)
        db.session.add(foo)
        db.session.commit()

        response = self.client.get(url_for('main.get_user', id=1),
                                   headers=headers)
        self.assertTrue(response.status_code == 200)

        response = self.client.get(url_for('main.get_user', id=2),
                                   headers=headers)
        self.assertTrue(response.status_code == 200)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # # Create alert and an alarm
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        ref_def = "CE01ISSP-XX099-01-CTDPFJ999"
        # Create an alarm with user_event_notification - uses definition 1 and user_id 1
        test_alarm = self.create_alert_alarm_definition(ref_def,
                                                        event_type='alarm',
                                                        uframe_id=2,
                                                        severity=1)

        # Create an alarm without user_event_notification - uses definition 1 and user_id 1
        bad_alarm = self.create_alert_alarm_definition_wo_notification(
            ref_def, event_type='alarm', uframe_filter_id=2, severity=1)

        notification = self.create_user_event_notification(bad_alarm.id, 2)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # GET alarm definition by SystemEventDefinition id
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        response = self.client.get(url_for('main.get_alert_alarm_def',
                                           id=test_alarm.id),
                                   headers=headers)
        self.assertEquals(response.status_code, 200)
        alarm_definition = json.loads(response.data)
        self.assertTrue(alarm_definition is not None)

        response = self.client.get(url_for('main.get_alert_alarm_def',
                                           id=bad_alarm.id),
                                   headers=headers)
        self.assertEquals(response.status_code, 200)
        bad_alarm_definition = json.loads(response.data)
        self.assertTrue(bad_alarm_definition is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # Get user_event_notifications (1)
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        response = self.client.get(
            url_for('main.get_user_event_notifications'), headers=headers)
        self.assertEquals(response.status_code, 200)
        data = json.loads(response.data)
        self.assertTrue(data is not None)
        notifications = data['notifications']
        self.assertTrue(notifications is not None)
        self.assertEquals(len(notifications), 2)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # Get user_event_notification by id=1
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        url = url_for('main.get_user_event_notification', id=1)
        response = self.client.get(url,
                                   content_type=content_type,
                                   headers=headers)
        self.assertEquals(response.status_code, 200)
        notification = json.loads(response.data)
        self.assertTrue(len(notification) > 0)
        self.assertEquals(len(notification), 8)
        """
        Error messages for the following tests:

            1. bad_notification:  {}

            2. 'Invalid ID, user_event_notification record not found.'

            3. 'Inconsistent ID, user_event_notification id provided in data does not match id provided.'

            4. 'Inconsistent User ID, user_id provided in data does not match id.'

            5. 'IntegrityError creating user_event_notification.'

            6. (no error)

            7. 'Insufficient data, or bad data format.'
        """

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (1) Get user_event_notification by id=5 (doesn't exist) response: {}
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        url = url_for('main.get_user_event_notification', id=5)
        response = self.client.get(url,
                                   content_type=content_type,
                                   headers=headers)
        self.assertEquals(response.status_code, 200)
        bad_notification = json.loads(response.data)
        self.assertTrue(bad_notification is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (2) (Negative) Update event_event_notification;
        # error: 'Invalid ID, user_event_notification record not found.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {
            'user_id': 1,
            'system_event_definition_id': test_alarm.id,
            'use_email': False,
            'use_log': False,
            'use_phone': False,
            'use_redmine': False,
            'use_sms': False,
            'id': 50
        }
        bad_stuff = json.dumps(test)
        response = self.client.put(url_for(
            'main.update_user_event_notification', id=50),
                                   headers=headers,
                                   data=bad_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (3) (Negative) Update event_event_notification
        # error: 'Inconsistent ID, user_event_notification id provided in data does not match id provided.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {
            'user_id': 999,
            'system_event_definition_id': 1,
            'use_email': True,
            'use_log': True,
            'use_phone': True,
            'use_redmine': True,
            'use_sms': True,
            'id': 1
        }
        good_stuff = json.dumps(test)
        response = self.client.put(url_for(
            'main.update_user_event_notification', id=800),
                                   headers=headers,
                                   data=good_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (4) (Negative) Update user_event_notification, with invalid user_id
        # error: 'Inconsistent User ID, user_id provided in data does not match id.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {
            'user_id': 1,
            'system_event_definition_id': 2,
            'use_email': True,
            'use_log': True,
            'use_phone': True,
            'use_redmine': True,
            'use_sms': True,
            'id': 2
        }
        good_stuff = json.dumps(test)
        response = self.client.put(url_for(
            'main.update_user_event_notification', id=2),
                                   headers=headers,
                                   data=good_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (5) # (Negative) Update event_event_notification
        # error: 'IntegrityError creating user_event_notification.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {
            'user_id': 2,
            'system_event_definition_id': bad_alarm.id,
            'use_email': False,
            'use_log': 'log',
            'use_phone': False,
            'use_redmine': False,
            'use_sms': False,
            'id': 2
        }
        bad_stuff = json.dumps(test)
        response = self.client.put(url_for(
            'main.update_user_event_notification', id=2),
                                   headers=headers,
                                   data=bad_stuff)
        self.assertEquals(response.status_code, 400)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (6) (Positive) Update event_event_notification
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        test = {
            'user_id': 1,
            'system_event_definition_id': 1,
            'use_email': True,
            'use_log': True,
            'use_phone': True,
            'use_redmine': True,
            'use_sms': True,
            'id': 1
        }
        good_stuff = json.dumps(test)
        response = self.client.put(url_for(
            'main.update_user_event_notification', id=1),
                                   headers=headers,
                                   data=good_stuff)
        self.assertEquals(response.status_code, 201)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue(len(notify_data) > 0)
        notify = UserEventNotification.query.get(1)

        for attribute in UserEventNotification.__table__.columns._data:
            self.assertTrue(attribute in notify_data)
            if attribute != 'user_id' or attribute != 'id':
                self.assertEquals(getattr(notify, attribute), True)

        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # (Negative) Update event_event_notification - expect failure, invalid user_id
        # error 'Insufficient data, or bad data format.'
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        data = {'user_id': 10}
        good_stuff = json.dumps(data)
        response = self.client.put(url_for(
            'main.update_user_event_notification', id=1),
                                   headers=headers,
                                   data=good_stuff)
        self.assertEquals(response.status_code, 409)
        notify_data = json.loads(response.data)
        self.assertTrue(notify_data is not None)
        self.assertTrue('message' in notify_data)
        self.assertTrue(notify_data['message'] is not None)

        if verbose: print '\n'
コード例 #19
0
ファイル: manage.py プロジェクト: Bobfrat/ooi-ui-services
def deploy(password, production, psqluser):
    from flask.ext.migrate import upgrade
    from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization
    from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink
    from sh import psql
    if production:
        app.logger.info('Creating PRODUCTION Database')
        try:
            psql('-c', 'CREATE ROLE postgres LOGIN SUPERUSER')
        except:
            pass
        psql('-c', 'create database ooiuiprod;', '-U', psqluser)
        psql('ooiuiprod', '-c', 'create schema ooiui', '-U', psqluser)
        psql('ooiuiprod', '-c', 'create extension postgis', '-U', psqluser)
    else:
        try:
            psql('-c', 'CREATE ROLE postgres LOGIN SUPERUSER')
        except:
            pass
        #Create the local database
        app.logger.info('Creating DEV and TEST Databases')
        psql('-c', 'create database ooiuidev;', '-U', psqluser)
        psql('ooiuidev', '-c', 'create schema ooiui', '-U', psqluser)
        psql('ooiuidev', '-c', 'create extension postgis', '-U', psqluser)
        #Create the local test database
        psql('-c', 'create database ooiuitest;', '-U', psqluser)
        psql('ooiuitest', '-c', 'create schema ooiui', '-U', psqluser)
        psql('ooiuitest', '-c', 'create extension postgis', '-U', psqluser)

    from sqlalchemy.orm.mapper import configure_mappers
    configure_mappers()
    db.create_all()

    if production:
        app.logger.info('Populating Production Database . . .')
        with open('db/ooiui_schema_data.sql') as f:
            psql('-U', psqluser, 'ooiuiprod', _in=f)
        with open('db/ooiui_params_streams_data.sql') as h:
            psql('-U', psqluser, 'ooiuiprod', _in=h)
        # with open('db/ooiui_vocab.sql') as i:
        #     psql('-U', psqluser, 'ooiuiprod', _in=i)
        app.logger.info('Production Database loaded.')
    else:
        app.logger.info('Populating Dev Database . . .')
        with open('db/ooiui_schema_data.sql') as f:
            psql('-U', psqluser, 'ooiuidev', _in=f)
        with open('db/ooiui_params_streams_data.sql') as h:
            psql('-U', psqluser, 'ooiuidev', _in=h)
        # with open('db/ooiui_vocab.sql') as i:
        #     psql('-U', psqluser, 'ooiuidev', _in=i)
        app.logger.info('Dev Database loaded.')

    # migrate database to latest revision
    #upgrade()
    if not os.getenv('TRAVIS'):
        UserScope.insert_scopes()
        app.logger.info('Insert default user, name: admin')
        User.insert_user(password=password)
        admin = User.query.first()
        admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
        admin.scopes.append(UserScope.query.filter_by(scope_name='sys_admin').first())
        admin.scopes.append(UserScope.query.filter_by(scope_name='data_manager').first())
        admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
        db.session.add(admin)
        db.session.commit()