コード例 #1
0
 def test_not_update_inactive_unknown_printer(self, mock_get_printer,
                                              mock_add_printer,
                                              mock_update_printer):
     save_printer_data(ip="1.2.3.4", client_props={"connected": False})
     self.assertEqual(mock_get_printer.call_count, 1)
     self.assertEqual(mock_add_printer.call_count, 0)
     self.assertEqual(mock_update_printer.call_count, 0)
コード例 #2
0
 def test_add_active_known_printer(
     self,
     mock_get_printer,
     mock_get_network_client,
     mock_add_network_client,
     mock_add_printer,
     mock_update_printer,
 ):
     uuid = guid.uuid4()
     ncuid = guid.uuid4()
     orguid = guid.uuid4()
     save_printer_data(
         uuid=uuid,
         network_client_uuid=ncuid,
         organization_uuid=orguid,
         name="myname",
         ip="1.2.3.4",
         port=80,
         client="octoprint",
         client_props={"connected": True},
     )
     self.assertEqual(mock_get_printer.call_count, 1)
     self.assertEqual(mock_add_printer.call_count, 1)
     self.assertEqual(mock_update_printer.call_count, 0)
     self.assertEqual(mock_add_network_client.call_count, 0)
     mock_add_printer.any_call_with({
         "uuid": uuid,
         "network_client_uuid": ncuid,
         "organization_uuid": orguid,
         "name": "myname",
         "client_props": {
             "connected": True
         },
         "printer_props": None,
     })
コード例 #3
0
 def test_update_any_known_printer(self, mock_get_printer, mock_add_printer,
                                   mock_update_printer):
     save_printer_data(ip="1.2.3.4",
                       client_props={"connected": True},
                       name="1.2.3.4")
     save_printer_data(ip="1.2.3.4",
                       client_props={"connected": False},
                       name="1.2.3.4")
     self.assertEqual(mock_get_printer.call_count, 2)
     self.assertEqual(mock_add_printer.call_count, 0)
     self.assertEqual(mock_update_printer.call_count, 2)
     args, update_kwargs = mock_update_printer.call_args
     # Should not overwrite custom editable name
     self.assertEqual(update_kwargs["name"], "1234")
コード例 #4
0
 def test_not_update_any_known_printer(
     self,
     mock_get_printer,
     mock_get_network_client,
     mock_add_printer,
     mock_update_printer,
 ):
     save_printer_data(
         uuid=guid.uuid4(),
         ip="1.2.3.4",
         client_props={"connected": True},
         name="1.2.3.4",
     )
     self.assertEqual(mock_get_printer.call_count, 1)
     self.assertEqual(mock_get_network_client.call_count, 1)
     self.assertEqual(mock_add_printer.call_count, 0)
     self.assertEqual(mock_update_printer.call_count, 0)
コード例 #5
0
 def test_add_active_unknown_printer(
     self,
     mock_get_printer,
     mock_get_network_client,
     mock_add_network_client,
     mock_add_printer,
     mock_update_printer,
 ):
     save_printer_data(
         uuid=guid.uuid4(),
         network_client_uuid=guid.uuid4(),
         organization_uuid=guid.uuid4(),
         ip="192.168.%s" %
         ".".join([str(random.randint(0, 255)) for _ in range(2)]),
         port=80,
         client="octoprint",
         client_props={"connected": True},
     )
     self.assertEqual(mock_get_network_client.call_count, 1)
     self.assertEqual(mock_get_printer.call_count, 0)
     self.assertEqual(mock_add_printer.call_count, 1)
     self.assertEqual(mock_update_printer.call_count, 0)
     self.assertEqual(mock_add_network_client.call_count, 1)