Пример #1
0
def test_tool_upgrade(users, tools, update_tool_status):
    user = User.objects.first()
    tool = Tool.objects.first()
    id_token = "secret user id_token"

    with patch("controlpanel.frontend.consumers.ToolDeployment"
               ) as ToolDeployment:
        tool_deployment = Mock()
        ToolDeployment.return_value = tool_deployment

        message = {
            "user_id": user.auth0_id,
            "tool_name": tool.chart_name,
            "id_token": id_token,
        }

        consumer = consumers.BackgroundTaskConsumer("test")
        consumer.tool_deploy = Mock()  # mock tool_deploy() method
        consumer.tool_upgrade(message=message)

        # 1. calls/reuse tool_deploy()
        consumer.tool_deploy.assert_called_with(message)
        # 2. Instanciate `ToolDeployment` correctly
        ToolDeployment.assert_called_with(tool, user)
        # 3. Send status update
        update_tool_status.assert_called_with(
            tool_deployment,
            id_token,
            TOOL_UPGRADED,
        )
Пример #2
0
def test_tool_deploy(users, tools, update_tool_status, wait_for_deployment):
    user = User.objects.first()
    tool = Tool.objects.first()
    id_token = "secret user id_token"

    with patch("controlpanel.frontend.consumers.ToolDeployment"
               ) as ToolDeployment:
        tool_deployment = Mock()
        ToolDeployment.return_value = tool_deployment

        consumer = consumers.BackgroundTaskConsumer("test")
        consumer.tool_deploy(
            message={
                "user_id": user.auth0_id,
                "tool_name": tool.chart_name,
                "id_token": id_token,
            })

        # 1. Instanciate `ToolDeployment` correctly
        ToolDeployment.assert_called_with(tool, user)
        # 2. Send status update
        update_tool_status.assert_called_with(
            tool_deployment,
            id_token,
            TOOL_DEPLOYING,
        )
        # 3. Call save() on ToolDeployment (trigger deployment)
        tool_deployment.save.assert_called()
        # 4. Wait for deployment to complete
        wait_for_deployment.assert_called_with(tool_deployment, id_token)