示例#1
0
    def test_004_onMessage_update_setting_ok(self):
        setting_update = testData.SETTING_UPDATE
        setting_data = json.loads(setting_update['data'])
        setting_name, setting_val = setting_data['setting_name'], setting_data['value']

        setting_before = settings_dao.get_setting_by_name(testData.burner, setting_name)
        self.assertEquals(setting_before['value'], 100)
        config.LOCAL = False
        SyncManager.onMessage(testData.SETTING_UPDATE)

        setting_after = settings_dao.get_setting_by_name(testData.burner, setting_name)
        self.assertEquals(setting_after['value'], setting_val)
示例#2
0
    def test_013_test_settings_correction_ack(self):

        settings_correction_ack = testData.SETTING_CORRECTION_ACK
        correction = json.loads(settings_correction_ack['correction'])

        setting_before = settings_dao.get_setting_by_name(settings_correction_ack['burner_sn'], correction['setting_name'])
        self.assertNotEqual(correction, setting_before)

        SyncManager.onMessage(settings_correction_ack)

        setting_after = settings_dao.get_setting_by_name(settings_correction_ack['burner_sn'], correction['setting_name'])
        self.assertEqual(correction, setting_after)
示例#3
0
    def test_011_test_not_accept_settings_update(self):
        settings_conflict = testData.SETTING_UPDATE_CONFLICT


        setting_before = settings_dao.get_setting_by_name(settings_conflict['burner_sn'], json.loads(settings_conflict['data'])['setting_name'])
        self.assertNotEqual(json.loads(settings_conflict['prev']), setting_before)
        config.LOCAL = True

        SyncManager.send_correction_ack = MagicMock(return_value="ok")
        SyncManager.onMessage(settings_conflict)

        setting_after = settings_dao.get_setting_by_name(settings_conflict['burner_sn'], json.loads(settings_conflict['data'])['setting_name'])

        self.assertEqual(setting_before, setting_after)
        SyncManager.send_correction_ack.assert_called_with(settings_conflict['id'], settings_conflict['burner_sn'], setting_before)
示例#4
0
def update_setting(setting, burner_sn, sync = True):
    print("update: ", setting)
    prev = settings_dao.get_setting_by_name(burner_sn, setting['setting_name'])
    updated = settings_dao.update_setting(setting, burner_sn)
    if updated and sync:
        sync = sync_queue_dao.insert_params(burner_sn, 'settings', 'update', setting, prev)
    return updated
示例#5
0
    def test_011_setting_trigger(self):
        settings_dao.update_setting(self.SETTING, self.BURNER_ID)
        new_settings = NewSettingsDao.get_all()
        self.assertEqual(1, len(new_settings))

        inserted = new_settings[0]

        real_setting = settings_dao.get_setting_by_name(self.BURNER_ID, self.SETTING['setting_name'])
        self.assertEqual(real_setting['burner_sn'], inserted['burner_sn'])
        self.assertEqual(real_setting['setting_name'], inserted['setting_name'])
        self.assertEqual(real_setting['value'], inserted['value'])

        self.SETTING['value'] = 666
        settings_dao.update_setting(self.SETTING, self.BURNER_ID)
        new_settings = NewSettingsDao.get_all()
        self.assertEqual(1, len(new_settings))

        inserted = new_settings[0]
        real_setting = settings_dao.get_setting_by_name(self.BURNER_ID, self.SETTING['setting_name'])
        self.assertEqual(real_setting['burner_sn'], inserted['burner_sn'])
        self.assertEqual(real_setting['setting_name'], inserted['setting_name'])
        self.assertEqual(real_setting['value'], inserted['value'])
示例#6
0
def get_setting(burner_sn, setting_name):
    return settings_dao.get_setting_by_name(burner_sn, setting_name)