Ejemplo n.º 1
0
    def test_eq__if_other_object_type__should_return_false(self, val):
        obj = ZKDevice(mac='00:17:61:C8:EC:17',
                       ip='192.168.1.201',
                       serial_number='DGD9190019050335134',
                       model=ZK400,
                       version='AC Ver 4.3.4 Apr 28 2017')

        assert obj.__eq__(val) is False
Ejemplo n.º 2
0
    def test_eq__should_return_comparing_result(self, attributes, expect):
        init = {
            'mac': '00:17:61:C8:EC:17',
            'ip': '192.168.1.201',
            'serial_number': 'DGD9190019050335134',
            'model': ZK400,
            'version': 'AC Ver 4.3.4 Apr 28 2017'
        }
        obj = ZKDevice(**init)
        init.update(attributes)
        other_obj = ZKDevice(**init)

        assert obj.__eq__(other_obj) == expect
Ejemplo n.º 3
0
    def test_repr__should_return_name_of_class(self):
        obj = ZKDevice(mac='00:17:61:C8:EC:17',
                       ip='192.168.1.201',
                       serial_number='DGD9190019050335134',
                       model=ZK400,
                       version='AC Ver 4.3.4 Apr 28 2017')

        assert repr(obj).startswith('Device[C3-400](')
Ejemplo n.º 4
0
    def test_init__if_device_string_passed__should_parse_and_fill_object_attributes(
            self, device_string):
        obj = ZKDevice(device_string)

        assert obj.mac == '00:17:61:C8:EC:17'
        assert obj.ip == '192.168.1.201'
        assert obj.serial_number == 'DGD9190019050335134'
        assert obj.model == ZK400
        assert obj.version == 'AC Ver 4.3.4 Apr 28 2017'
Ejemplo n.º 5
0
    def test_search_devices__should_return_list_of_found_device_objects(self):
        self.sdk.search_device.return_value = [
            'MAC=00:17:61:C8:EC:17,IP=192.168.1.201,SN=DGD9190019050335134,'
            'Device=C3-400,Ver=AC Ver 4.3.4 Apr 28 2017',
            'MAC=00:17:61:C8:EC:18,IP=192.168.1.202,SN=DGD9190019050335135,'
            'Device=C3-200,Ver=AC Ver 4.3.4 Apr 28 2017'
        ]
        expect = (
            ZKDevice(mac='00:17:61:C8:EC:17', ip='192.168.1.201',
                     serial_number='DGD9190019050335134', model=ZK400,
                     version='AC Ver 4.3.4 Apr 28 2017'),
            ZKDevice(mac='00:17:61:C8:EC:18', ip='192.168.1.202',
                     serial_number='DGD9190019050335135', model=ZK200,
                     version='AC Ver 4.3.4 Apr 28 2017'),
        )

        res = ZKAccess.search_devices('192.168.1.255')
        assert res == expect
Ejemplo n.º 6
0
    def test_init__if_device_is_specified__should_override_device_model(self):
        device = ZKDevice(mac='00:17:61:C8:EC:17',
                          ip='192.168.1.201',
                          serial_number='DGD9190019050335134',
                          model=ZK100,
                          version='AC Ver 4.3.4 Apr 28 2017')

        obj = ZKAccess(device=device, device_model=ZK200)

        assert obj.device_model == ZK200
Ejemplo n.º 7
0
    def test_device_prop__if_device_was_passed_to_init__should_return_it(self):
        device = ZKDevice(mac='00:17:61:C8:EC:17',
                          ip='192.168.1.201',
                          serial_number='DGD9190019050335134',
                          model=ZK100,
                          version='AC Ver 4.3.4 Apr 28 2017')
        obj = ZKAccess(device=device)

        res = obj.device

        assert res is device
Ejemplo n.º 8
0
    def test_init__if_device_is_specified__should_automatically_connect(self):
        self.sdk.handle = None
        self.sdk.is_connected = False
        device = ZKDevice(mac='00:17:61:C8:EC:17',
                          ip='192.168.1.201',
                          serial_number='DGD9190019050335134',
                          model=ZK100,
                          version='AC Ver 4.3.4 Apr 28 2017')
        expect_connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd='

        _ = ZKAccess(device=device)

        self.sdk.connect.assert_called_once_with(expect_connstr)
Ejemplo n.º 9
0
    def test_init__if_parameters_are_passed__should_set_object_attributes(
            self):
        obj = ZKDevice(mac='00:17:61:C8:EC:17',
                       ip='192.168.1.201',
                       serial_number='DGD9190019050335134',
                       model=ZK400,
                       version='AC Ver 4.3.4 Apr 28 2017')

        assert obj.mac == '00:17:61:C8:EC:17'
        assert obj.ip == '192.168.1.201'
        assert obj.serial_number == 'DGD9190019050335134'
        assert obj.model == ZK400
        assert obj.version == 'AC Ver 4.3.4 Apr 28 2017'
Ejemplo n.º 10
0
    def test_init__if_both_connstr_and_device_are_specified__connstr_takes_precedence(self):
        self.sdk.handle = None
        self.sdk.is_connected = False
        device = ZKDevice(mac='00:17:61:C8:EC:17',
                          ip='192.168.1.201',
                          serial_number='DGD9190019050335134',
                          model=ZK100,
                          version='AC Ver 4.3.4 Apr 28 2017')
        connstr = 'protocol=TCP,ipaddress=10.0.0.23,port=4370,timeout=4000,passwd='

        _ = ZKAccess(device=device, connstr=connstr)

        self.sdk.connect.assert_called_once_with(connstr)
Ejemplo n.º 11
0
 def test_init__if_nothing_passed__should_raise_error(self):
     with pytest.raises(TypeError):
         ZKDevice()
Ejemplo n.º 12
0
 def test_init__if_device_string_is_incorrect__should_raise_error(
         self, device_string):
     with pytest.raises(ValueError):
         ZKDevice(device_string)