Example #1
0
    def test_DifferentGroupAlertLevels(self, session=None):
        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        session.add(sm1)

        group1 = create_group(name='GLOBAL')
        group2 = create_group(name='GLOBAL2')

        session.add_all([group1, group2])

        fac1 = Facility(facility_id=1, groups=[group1])

        fac2 = Facility(facility_id=2, groups=[group2])

        fs1 = FacilityShaking(shakemap=sm1, alert_level='gray', facility=fac1)

        fs2 = FacilityShaking(shakemap=sm1, alert_level='green', facility=fac2)

        session.add_all([fac1, fac2, fs1, fs2])

        session.commit()

        level1 = sm1.get_alert_level(group1)
        level2 = sm1.get_alert_level(group2)

        self.assertTrue(level1 == 'gray')
        self.assertTrue(level2 == 'green')

        objs = [sm1, group1, group2, fac1, fac2]
        for obj in objs:
            session.delete(obj)

        session.commit()
Example #2
0
    def test_updateNotificationNoneNone(self, session=None):

        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='shakemap1', shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)

        self.assertTrue(has_alert_level)
        self.assertFalse(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group]
        for obj in objs:
            session.delete(obj)

        session.commit()
Example #3
0
    def step03_createGroup(self):
        session = Session()
        
        global_group = create_group(name='GLOBAL')
        scenario_group = create_group(name='GLOBAL_SCENARIO', event_type='SCENARIO')
        high_prio = create_group(name='HIGH_INSP',
                                    insp_prios=['RED'])
        
        no_new_event_group = create_group(name='NO_NEW_EVENT', new_event=False)
        no_insp_group = create_group(name='NO_INSP', insp_prios=[])
        all_group = create_group(name='ALL', event_type='all')
        mms_group = create_group(
            name='MMS',
            event_type='all',
            notification_format='mms'
        )

        session.add(global_group)
        session.add(scenario_group)
        session.add(high_prio)
        session.add(no_new_event_group)
        session.add(no_insp_group)
        session.add(all_group)
        session.add(mms_group)

        session.commit()
        Session.remove()
Example #4
0
    def step03_createGroup(self):
        session = Session()

        global_group = create_group(name='GLOBAL')
        scenario_group = create_group(name='GLOBAL_SCENARIO',
                                      event_type='SCENARIO')
        high_prio = create_group(name='HIGH_INSP', insp_prios=['RED'])

        no_new_event_group = create_group(name='NO_NEW_EVENT', new_event=False)
        no_insp_group = create_group(name='NO_INSP', insp_prios=[])
        all_group = create_group(name='ALL', event_type='all')
        mms_group = create_group(name='MMS',
                                 event_type='all',
                                 notification_format='mms')

        session.add(global_group)
        session.add(scenario_group)
        session.add(high_prio)
        session.add(no_new_event_group)
        session.add(no_insp_group)
        session.add(all_group)
        session.add(mms_group)

        session.commit()
        Session.remove()
Example #5
0
    def test_changedNotificationGreyGreen(self, session=None):

        sm1 = ShakeMap(
            shakemap_id = 'shakemap1',
            shakemap_version = 1
        )

        sm2 = ShakeMap(
            shakemap_id = 'shakemap1',
            shakemap_version = 2
        )

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(
            shakemap = sm1
        )

        n2 = Notification(
            shakemap = sm2
        )

        session.add_all([n1, n2])

        fs1 = FacilityShaking(
            shakemap = sm1,
            weight = .1
        )

        fs2 = FacilityShaking(
            shakemap = sm2,
            weight = 1
        )

        session.add_all([fs1, fs2])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
                                                    group,
                                                    n2,
                                                    session=session
                                                )
        self.assertTrue(has_alert_level)
        self.assertTrue(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group]
        for obj in objs:
            session.delete(obj)
        
        session.commit()
Example #6
0
    def step02_createSmallGroup(self):
        session = Session()
        
        small_group = create_group(name='small')
        small_group.lat_min = -1
        small_group.lat_max = 1
        small_group.lon_min = -1
        small_group.lon_max = 1

        session.add(small_group)

        session.commit()
        Session.remove()
Example #7
0
    def step02_createSmallGroup(self):
        session = Session()

        small_group = create_group(name='small')
        small_group.lat_min = -1
        small_group.lat_max = 1
        small_group.lon_min = -1
        small_group.lon_max = 1

        session.add(small_group)

        session.commit()
        Session.remove()
Example #8
0
    def test_changedNotificationLength(self, session=None):
        sm1 = ShakeMap(shakemap_id='test_changedNotificationLength',
                       shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='test_changedNotificationLength',
                       shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        fac1 = Facility(facility_id=1, groups=[group])

        fac2 = Facility(facility_id=2, groups=[group])

        fac3 = Facility(facility_id=3, groups=[group])

        fs1 = FacilityShaking(shakemap=sm1, alert_level='green', facility=fac1)

        fs2 = FacilityShaking(shakemap=sm2, alert_level='green', facility=fac2)

        fs3 = FacilityShaking(shakemap=sm2, alert_level='gray', facility=fac3)

        session.add_all([fac1, fac2, fac3, fs1, fs2, fs3])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)

        self.assertTrue(has_alert_level)
        self.assertTrue(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group, fac1, fac2, fac3]
        for obj in objs:
            session.delete(obj)

        session.commit()
Example #9
0
    def test_updateNotificationNoneNone(self, session=None):

        sm1 = ShakeMap(
            shakemap_id = 'shakemap1',
            shakemap_version = 1
        )

        sm2 = ShakeMap(
            shakemap_id = 'shakemap1',
            shakemap_version = 2
        )

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(
            shakemap = sm1
        )

        n2 = Notification(
            shakemap = sm2
        )

        session.add_all([n1, n2])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
                                                    group,
                                                    n2,
                                                    session=session
                                                )
        self.assertTrue(has_alert_level)
        self.assertFalse(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group]
        for obj in objs:
            session.delete(obj)
        
        session.commit()
Example #10
0
    def test_changedNotificationNoneGrey(self, session=None):

        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='shakemap1', shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        facility = Facility(groups=[group])

        fs = FacilityShaking(shakemap=sm2,
                             alert_level='gray',
                             facility=facility)

        session.add(fs)

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)
        self.assertTrue(has_alert_level)
        self.assertTrue(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group]
        for obj in objs:
            session.delete(obj)

        session.commit()
Example #11
0
    def test_unchangedNotificationGreenGreen(self, session=None):
        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='shakemap1', shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        fac1 = Facility(facility_id=1)

        fs1 = FacilityShaking(shakemap=sm1, weight=1, facility=fac1)

        fs2 = FacilityShaking(shakemap=sm2, weight=1, facility=fac1)

        session.add_all([fac1, fs1, fs2])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)
        self.assertTrue(has_alert_level)
        self.assertFalse(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group, fac1]
        for obj in objs:
            session.delete(obj)

        session.commit()