示例#1
0
def test_add_remove(sqldb):
    db = rules_db.RulesDb(sqldb, MOCK_UDN, MOCK_NAME)

    # Rules
    assert len(db._rules) == 0
    rule = db.add_rule(
        rules_db.RulesRow(
            RuleID=501,
            Name="Long Press Rule",
            Type=MOCK_RULE_TYPE,
            State=1,
        ))
    assert len(db._rules) == 1
    db.remove_rule(rule)
    assert len(db._rules) == 0

    # RuleDevices
    assert len(db._rule_devices) == 0
    device = db.add_rule_devices(
        rules_db.RuleDevicesRow(RuleDevicePK=1, RuleID=501, DeviceID=MOCK_UDN))
    assert len(db._rule_devices) == 1
    db.remove_rule_devices(device)
    assert len(db._rule_devices) == 0

    # TargetDevices
    assert len(db._target_devices) == 0
    target = db.add_target_devices(
        rules_db.TargetDevicesRow(RuleID=501, DeviceID=MOCK_TARGET_UDN))
    assert len(db._target_devices) == 1
    db.remove_target_devices(target)
    assert len(db._target_devices) == 0
示例#2
0
def test_clear_all(sqldb):
    db = rules_db.RulesDb(sqldb, MOCK_UDN, MOCK_NAME)
    rule = db.add_rule(
        rules_db.RulesRow(
            RuleID=501,
            Name="Long Press Rule",
            Type=MOCK_RULE_TYPE,
            State=1,
        ))
    assert len(db._rules) == 1

    # RuleDevices
    assert len(db._rule_devices) == 0
    device = db.add_rule_devices(
        rules_db.RuleDevicesRow(RuleDevicePK=1, RuleID=501, DeviceID=MOCK_UDN))
    assert len(db._rule_devices) == 1

    # TargetDevices
    assert len(db._target_devices) == 0
    target = db.add_target_devices(
        rules_db.TargetDevicesRow(RuleID=501, DeviceID=MOCK_TARGET_UDN))
    assert len(db._target_devices) == 1

    db.clear_all()
    assert len(db._rules) == 0
    assert len(db._rule_devices) == 0
    assert len(db._target_devices) == 0
示例#3
0
def test_update_if_modified_field_changed(sqldb):
    cursor = sqldb.cursor()
    rules_db.RulesRow(
        RuleID=501,
        Name="Long Press Rule",
        Type=MOCK_RULE_TYPE,
        State=1,
    ).update_db(cursor)

    rules_db.RuleDevicesRow(RuleDevicePK=1, RuleID=501,
                            DeviceID=MOCK_UDN).update_db(cursor)

    db = rules_db.RulesDb(sqldb, MOCK_UDN, MOCK_NAME)
    rule, device = db.rules_for_device()[0]
    assert db.update_if_modified() is False

    # Modifying an entry in the db should cause update_if_modified() to be True
    rule.State = 0
    assert db.update_if_modified() is True
示例#4
0
                 StartDate="12201982",
                 EndDate="07301982",
                 State=1,
                 Sync="NOSYNC",
             ),
             rules_db.RuleDevicesRow(
                 RuleDevicePK=1,
                 RuleID=1,
                 DeviceID=MOCK_UDN,
                 GroupID=0,
                 DayID=-1,
                 StartTime=60,
                 RuleDuration=86340,
                 StartAction=long_press.ActionType.TOGGLE.value,
                 EndAction=-1.0,
                 SensorDuration=-1,
                 Type=-1,
                 Value=-1,
                 Level=-1,
                 ZBCapabilityStart='',
                 ZBCapabilityEnd='',
                 OnModeOffset=-1,
                 OffModeOffset=-1,
                 CountdownTime=-1,
                 EndTime=86400,
             ),
         ),
     ],
 ),
 # Test case 1: Long press rule exists, but has State=0.
 # Expect that the existing rules remain and all that is changed is