예제 #1
0
    def test_deactivate_bad_data_responding_printer(self, mock_get_data,
                                                    mock_update_printer,
                                                    mock_upsert, mock_get_val):
        def mock_call(key):
            return 3600

        mock_get_val.side_effect = mock_call
        mock_get_data.return_value.status_code = 200
        mock_get_data.return_value.json.return_value = {"text": "Fumbleprint"}
        retry_after_at_least = datetime.utcnow() + timedelta(hours=1)
        sniff_printer("octopi.local", "192.168.1.11")
        self.assertEqual(mock_update_printer.call_count, 1)
        self.assertEqual(mock_upsert.call_count, 1)
        args, upsert_kwargs = mock_upsert.call_args
        self.assertEqual(upsert_kwargs["ip"], "192.168.1.11")
        self.assertTrue(upsert_kwargs["retry_after"] > retry_after_at_least)
        mock_update_printer.assert_called_with(
            **{
                "hostname": "octopi.local",
                "ip": "192.168.1.11",
                "name": "octopi.local",
                "client": "octoprint",
                "client_props": {
                    "connected": False,
                    "version": {
                        "text": "Fumbleprint"
                    },
                    "read_only": False,
                },
            })
예제 #2
0
    def test_activate_responding_printer(self, mock_get_data,
                                         mock_update_printer, mock_upsert,
                                         mock_get_val):
        def mock_call(key):
            return 3600

        mock_get_val.side_effect = mock_call
        mock_get_data.return_value.status_code = 200
        mock_get_data.return_value.json.return_value = {"text": "OctoPrint"}
        sniff_printer("octopi.local", "192.168.1.12")
        self.assertEqual(mock_update_printer.call_count, 1)
        self.assertEqual(mock_upsert.call_count, 1)
        mock_upsert.assert_called_with(**{
            "ip": "192.168.1.12",
            "retry_after": None,
            "disabled": False
        })
        mock_update_printer.assert_called_with(
            **{
                "hostname": "octopi.local",
                "ip": "192.168.1.12",
                "name": "octopi.local",
                "client": "octoprint",
                "client_props": {
                    "connected": True,
                    "version": {
                        "text": "OctoPrint"
                    },
                    "read_only": False,
                },
            })
예제 #3
0
 def test_add_responding_printer(self, mock_get_data, mock_update_printer,
                                 mock_redis, mock_uuid):
     mock_redis.get.return_value = pickle.dumps(
         Response(200, {"text": "OctoPrint"}))
     sniff_printer(UUID_ORG, "octopi.local", "192.168.1.12")
     self.assertEqual(mock_get_data.call_count, 2)
     self.assertEqual(mock_update_printer.call_count, 1)
     mock_update_printer.assert_called_with(
         **{
             "uuid": "1234",
             "network_client_uuid": "1234",
             "organization_uuid": UUID_ORG,
             "protocol": "http",
             "name": "octopi.local",
             "ip": "192.168.1.12",
             "hostname": "octopi.local",
             "port": 80,
             "path": "",
             "token": None,
             "client": "octoprint",
             "client_props": {
                 "connected": True,
                 "version": {
                     "text": "OctoPrint"
                 },
                 "access_level": PrinterClientAccessLevel.UNLOCKED,
                 "api_key": None,
                 "webcam": {
                     "message": "Webcam disabled in octoprint"
                 },
                 "plugins": [],
             },
             "printer_props": None,
         })
예제 #4
0
 def test_not_add_bad_data_responding_printer(self, mock_get_data,
                                              mock_save_printer,
                                              mock_redis):
     mock_redis.get.return_value = None
     mock_get_data.return_value.status_code = 200
     mock_get_data.return_value.json.return_value = {"text": "Fumbleprint"}
     sniff_printer(UUID_ORG, "octopi.local", "192.168.1.11")
     self.assertEqual(mock_save_printer.call_count, 0)
예제 #5
0
    def test_try_http_and_https(self, mock_octoprint_redis, mock_get_data,
                                mock_update_printer, mock_uuid):
        def mock_call(uri, **kwargs):
            if "https" in uri:
                return Response(200, {"text": "OctoPrint"})
            return None

        mock_get_data.side_effect = mock_call
        mock_octoprint_redis.get.return_value = None

        sniff_printer(UUID_ORG, "octopi.local", "192.168.1.12")
        self.assertEqual(mock_update_printer.call_count, 1)
        self.assertEqual(mock_get_data.call_count, 4)
        mock_update_printer.assert_called_with(
            **{
                "uuid": "1234",
                "network_client_uuid": "1234",
                "organization_uuid": UUID_ORG,
                "name": "octopi.local",
                "protocol": "https",
                "ip": "192.168.1.12",
                "hostname": "octopi.local",
                "port": 443,
                "path": "",
                "token": None,
                "client": "octoprint",
                "client_props": {
                    "connected": True,
                    "version": {
                        "text": "OctoPrint"
                    },
                    "access_level": PrinterClientAccessLevel.UNLOCKED,
                    "api_key": None,
                    "webcam": {
                        "message": "Webcam disabled in octoprint"
                    },
                    "plugins": [],
                },
                "printer_props": None,
            })
예제 #6
0
 def test_not_add_no_data_responding_printer(self, mock_get_data,
                                             mock_save_printer):
     sniff_printer(UUID_ORG, "octopi.local", "192.168.1.10")
     self.assertEqual(mock_save_printer.call_count, 0)