def test_claim_node_unclaimed_no_claim_code(settings, httpretty, mocker, client_uri, node_uuid):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=403)

    mocker.patch('octoprint_authentise.helpers.run_client_and_wait', return_value=None)

    with pytest.raises(helpers.ClaimNodeException) as error:
        helpers.claim_node(node_uuid, settings, logger)
    assert error.value.message == "Could not get a claim code from Authentise"
def test_claim_node_unclaimed_good_claim_code(settings, httpretty, mocker, client_uri, node_uuid, claim_code, claim_code_uri):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=403)

    mocker.patch('octoprint_authentise.helpers.run_client_and_wait', return_value=claim_code)

    httpretty.register_uri(httpretty.PUT, claim_code_uri, status=200)

    helpers.claim_node(node_uuid, settings, logger)
def test_claim_node_unclaimed_no_claim_code(settings, httpretty, mocker,
                                            client_uri, node_uuid):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=403)

    mocker.patch('octoprint_authentise.helpers.run_client_and_wait',
                 return_value=None)

    with pytest.raises(helpers.ClaimNodeException) as error:
        helpers.claim_node(node_uuid, settings, logger)
    assert error.value.message == "Could not get a claim code from Authentise"
def test_claim_node_unclaimed_bad_claim_code(settings, httpretty, mocker, client_uri, node_uuid, claim_code, claim_code_uri):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=403)

    mocker.patch('octoprint_authentise.helpers.run_client_and_wait', return_value=claim_code)

    httpretty.register_uri(httpretty.PUT, claim_code_uri, status=404)

    with pytest.raises(helpers.ClaimNodeException) as error:
        helpers.claim_node(node_uuid, settings, logger)

    assert error.value.message == "Could not use claim code {} for node {}".format(claim_code, node_uuid)
def test_claim_node_unclaimed_good_claim_code(settings, httpretty, mocker,
                                              client_uri, node_uuid,
                                              claim_code, claim_code_uri):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=403)

    mocker.patch('octoprint_authentise.helpers.run_client_and_wait',
                 return_value=claim_code)

    httpretty.register_uri(httpretty.PUT, claim_code_uri, status=200)

    helpers.claim_node(node_uuid, settings, logger)
def test_claim_node_unclaimed_bad_claim_code(settings, httpretty, mocker,
                                             client_uri, node_uuid, claim_code,
                                             claim_code_uri):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=403)

    mocker.patch('octoprint_authentise.helpers.run_client_and_wait',
                 return_value=claim_code)

    httpretty.register_uri(httpretty.PUT, claim_code_uri, status=404)

    with pytest.raises(helpers.ClaimNodeException) as error:
        helpers.claim_node(node_uuid, settings, logger)

    assert error.value.message == "Could not use claim code {} for node {}".format(
        claim_code, node_uuid)
Beispiel #7
0
    def connect(self, port=None, baudrate=None):
        try:
            self._session = helpers.session(self._settings)  #pylint: disable=no-member
            helpers.claim_node(self.node_uuid, self._settings, self._logger)  #pylint: disable=no-member
        except (helpers.ClaimNodeException, helpers.SessionException) as e:
            self._errorValue = e.message
            self._change_state(PRINTER_STATE['ERROR'])
            return

        if port == None:
            port = settings().get(["serial", "port"])
        if baudrate == None:
            settings_baudrate = settings().getInt(["serial", "baudrate"])
            if settings_baudrate is None:
                baudrate = 0
            else:
                baudrate = settings_baudrate

        self._port = port
        self._baudrate = baudrate
        self._printer_uri = self._get_or_create_printer(port, baudrate)

        self._authentise_process = helpers.run_client(self._settings)  #pylint: disable=no-member

        # monitoring thread
        self._monitoring_active = True
        self.monitoring_thread = threading.Thread(target=self._monitor_loop,
                                                  name="comm._monitor")
        self.monitoring_thread.daemon = True
        self.monitoring_thread.start()

        self._printer_status_timer = RepeatedTimer(
            lambda: comm_helpers.get_interval("temperature",
                                              default_value=10.0),
            self._update_printer_data,
            run_first=True)
        self._printer_status_timer.start()

        self._change_state(PRINTER_STATE['CONNECTING'])
    def connect(self, port=None, baudrate=None):
        try:
            self._session = helpers.session(self._settings) #pylint: disable=no-member
            helpers.claim_node(self.node_uuid, self._settings, self._logger) #pylint: disable=no-member
        except (helpers.ClaimNodeException, helpers.SessionException) as e:
            self._errorValue = e.message
            self._change_state(PRINTER_STATE['ERROR'])
            return

        if port == None:
            port = settings().get(["serial", "port"])
        if baudrate == None:
            settings_baudrate = settings().getInt(["serial", "baudrate"])
            if settings_baudrate is None:
                baudrate = 0
            else:
                baudrate = settings_baudrate

        self._port = port
        self._baudrate = baudrate
        self._printer_uri = self._get_or_create_printer(port, baudrate)

        self._authentise_process = helpers.run_client(self._settings) #pylint: disable=no-member

        # monitoring thread
        self._monitoring_active = True
        self.monitoring_thread = threading.Thread(target=self._monitor_loop, name="comm._monitor")
        self.monitoring_thread.daemon = True
        self.monitoring_thread.start()

        self._printer_status_timer = RepeatedTimer(
            lambda: comm_helpers.get_interval("temperature", default_value=10.0),
            self._update_printer_data,
            run_first=True
        )
        self._printer_status_timer.start()

        self._change_state(PRINTER_STATE['CONNECTING'])
def test_claim_node_no_node_uuid(settings, mocker):
    logger = mocker.Mock()
    with pytest.raises(helpers.ClaimNodeException) as error:
        helpers.claim_node(None, settings, logger)
    assert error.value.message == "No Authentise node uuid available to claim"
def test_claim_node_already_claimed(settings, httpretty, mocker, client_uri, node_uuid):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=200)

    helpers.claim_node(node_uuid, settings, logger)
def test_claim_node_no_node_uuid(settings, mocker):
    logger = mocker.Mock()
    with pytest.raises(helpers.ClaimNodeException) as error:
        helpers.claim_node(None, settings, logger)
    assert error.value.message == "No Authentise node uuid available to claim"
def test_claim_node_already_claimed(settings, httpretty, mocker, client_uri,
                                    node_uuid):
    logger = mocker.Mock()
    httpretty.register_uri(httpretty.GET, client_uri, status=200)

    helpers.claim_node(node_uuid, settings, logger)