Skip to content
Snippets Groups Projects
Select Git revision
  • 6104cfdf7d9af35c127c4e8d5e40a56d9701f3b5
  • master default protected
  • docs-release-checklist-037
  • release
  • release-v0.37.0
  • staging
  • reprovide-sweep
  • copilot/fix-859994d3-9d4e-4a8e-bea3-58b58c75a399
  • feat/boxo-retrieval-diagnostics
  • dependabot/github_actions/codecov/codecov-action-5.5.0
  • config-api-for-path
  • fix/panic-and-zombie-daemons
  • chore-golangci-v2
  • config-reprovider-test
  • release-v036
  • release-v0.36.0
  • telemetry-plugin
  • fix-editor-env-handling
  • fix-flush-files-rm
  • unixfs-percent-encoding-poc
  • fix/systemd-path
  • v0.37.0
  • v0.37.0-rc1
  • v0.36.0
  • v0.36.0-rc2
  • v0.36.0-rc1
  • v0.35.0
  • v0.35.0-rc2
  • v0.35.0-rc1
  • v0.34.1
  • v0.34.0
  • v0.34.0-rc2
  • v0.34.0-rc1
  • v0.33.2
  • v0.33.1
  • v0.33.0
  • v0.33.0-rc3
  • v0.33.0-rc2
  • v0.33.0-rc1
  • v0.32.1
  • v0.32.0
41 results

webui.go

Blame
  • test_server.py 2.01 KiB
    import uuid
    
    import mock
    import pytest
    
    from pi_mqtt_gpio import server
    
    
    @mock.patch("pkg_resources.WorkingSet")
    def test_imr_no_attribute(mock_ws):
        """
        Should not bother looking up what's installed when there's no requirements.
        """
        module = object()
        server.install_missing_requirements(module)
        mock_ws.assert_not_called()
    
    
    @mock.patch("pkg_resources.WorkingSet")
    def test_imr_blank_list(mock_ws):
        """
        Should not bother looking up what's installed when there's no requirements.
        """
        module = mock.Mock()
        module.REQUIREMENTS = []
        server.install_missing_requirements(module)
        mock_ws.assert_not_called()
    
    
    @mock.patch("pkg_resources.WorkingSet.find", return_value=None)
    @mock.patch("subprocess.check_call")
    def test_imr_has_requirements(mock_check_call, mock_find):
        """
        Should install all missing args.
        """
        module = mock.Mock()
        module.REQUIREMENTS = ["testreq1", "testreq2==1.2.3"]
        server.install_missing_requirements(module)
        args, _ = mock_check_call.call_args
        assert args == (["/usr/bin/env", "pip", "install", "testreq1", "testreq2==1.2.3"],)
    
    
    @mock.patch("pkg_resources.WorkingSet.find", return_value=None)
    def test_imr_bad_pkg_fails(mock_find):
        """
        Should raise exception when pkg installation fails.
        """
        module = mock.Mock()
        module.REQUIREMENTS = [str(uuid.uuid4())]
        with pytest.raises(server.CannotInstallModuleRequirements):
            server.install_missing_requirements(module)
    
    
    def test_onfts_no_set():
        """
        Should raise a ValueError when there's no /set at the end of the topic.
        """
        with pytest.raises(ValueError):
            server.output_name_from_topic(
                "myprefix/output/myoutputname", "myprefix", "set")
    
    
    def test_onfts_returns_output_name():
        """
        Should return the proper output name.
        """
        output_name = "myoutputname"
        ret = server.output_name_from_topic(
            "myprefix/output/%s/%s" % (output_name, server.SET_TOPIC),
            "myprefix",
            "set"
        )
        assert ret == output_name