Пример #1
0
    def test_initialization__invalid(self, m_log: NonCallableMock) -> None:
        """Test initialization that is invalid"""
        # With only ip
        device = Device(
            device_name=faker.word(),
            local_auth_token=faker.local_auth_token(),
            ip_address=faker.ipv4_private(),
        )
        self.assertEqual(m_log.call_count, 1)
        self.assertIsNone(device.local_auth_token)

        # With only port
        device = Device(
            device_name=faker.word(),
            local_auth_token=faker.local_auth_token(),
            port=faker.port_number(),
        )
        self.assertEqual(m_log.call_count, 2)
        self.assertIsNone(device.local_auth_token)

        # Invalid local_auth_token
        device = Device(device_name=faker.word(),
                        local_auth_token=faker.word())
        self.assertEqual(m_log.call_count, 3)
        self.assertIsNone(device.local_auth_token)
Пример #2
0
    def test_get_google_devices_json(self, m_get_google_devices):
        device_name = faker.word()
        local_auth_token = faker.local_auth_token()
        ip = faker.ipv4()
        port = faker.port_number()
        hardware = faker.word()
        google_device = Device(
            device_name=device_name,
            local_auth_token=local_auth_token,
            ip=ip,
            port=port,
            hardware=hardware,
        )
        m_get_google_devices.return_value = [google_device]

        json_string = self.client.get_google_devices_json(
            disable_discovery=True)
        self.assertEqual(m_get_google_devices.call_count, 1)
        self.assertIsString(json_string)
        received_json = json.loads(json_string)
        received_device = received_json[0]
        self.assertEqual(received_device[JSON_KEY_DEVICE_NAME], device_name)
        self.assertEqual(received_device[JSON_KEY_HARDWARE], hardware)
        self.assertEqual(received_device[JSON_KEY_LOCAL_AUTH_TOKEN],
                         local_auth_token)
        self.assertEqual(
            received_device[JSON_KEY_GOOGLE_DEVICE][JSON_KEY_PORT], port)
        self.assertEqual(received_device[JSON_KEY_GOOGLE_DEVICE][JSON_KEY_IP],
                         ip)
Пример #3
0
    def test_initialization__valid(self):
        local_auth_token = faker.local_auth_token()

        # With ip and port
        device = Device(device_name=faker.word(),
                        local_auth_token=local_auth_token)

        self.assertEqual(device.local_auth_token, local_auth_token)
Пример #4
0
    def test_initialization__valid(self) -> None:
        """Test initialization that is valid"""
        local_auth_token = faker.local_auth_token()

        # With ip and port
        device = Device(
            device_name=faker.word(),
            ip_address=faker.ipv4(),
            port=faker.port_number(),
            local_auth_token=local_auth_token,
        )

        self.assertEqual(device.local_auth_token, local_auth_token)
Пример #5
0
    def test_initialization__invalid(self, m_log):
        # With only ip
        device = Device(
            device_name=faker.word(),
            local_auth_token=faker.local_auth_token(),
            ip=faker.ipv4_private(),
        )
        self.assertEqual(m_log.call_count, 1)
        self.assertIsNone(device.local_auth_token)

        # With only port
        device = Device(
            device_name=faker.word(),
            local_auth_token=faker.local_auth_token(),
            port=faker.port_number(),
        )
        self.assertEqual(m_log.call_count, 2)
        self.assertIsNone(device.local_auth_token)

        # Invalid local_auth_token
        device = Device(device_name=faker.word(),
                        local_auth_token=faker.word())
        self.assertEqual(m_log.call_count, 3)
        self.assertIsNone(device.local_auth_token)