# Path: shelf/hook/background/action.py
# def execute_command(command, log_level, event, uri, meta_uri, cwd="."):
# def create_container(log_level):
# def create_background_logger(level):
# 
# Path: shelf/hook/event.py
# class Event(object):
#     ARTIFACT_UPLOADED = "ARTIFACT_UPLOADED"
#     METADATA_UPDATED = "METADATA_UPDATED"
# 
# Path: tests/test_base.py
# class TestBase(pyproctor.TestBase):
#     @classmethod
#     def setUpClass(cls):
#         """
#             This exists to make sure that no matter what, tests
#             will log on stdout.  Every call to basicConfig after
#             this point will be a no-op
#         """
#         # AGI-731
#         # See jira for more information
#         #
#         # https://github.com/gabrielfalcao/HTTPretty/issues/280
#         #
#         # logging.basicConfig(
#         #     stream=sys.stdout
#         # )


from mock import Mock
from shelf.hook.background import action
from shelf.hook.event import Event
from tests.test_base import TestBase
from pyproctor import MonkeyPatcher
import json
import os
import logging

    def setUp(self):
        super(ExecuteCommandTest, self).setUp()
        self.cwd = os.path.join(os.path.dirname(__file__), "../../..")
        self.logger = Mock()
        MonkeyPatcher.patch(action, "create_background_logger", Mock(return_value=self.logger))

    def create_data(self, command, event):
        data = {
            "command": command,
            "log_level": logging.DEBUG,
            "event": event,
            "uri": "https://api.shelf.com/fake/artifact/1",
            "meta_uri": "https://api.shelf.com/fake/artifact/1/_meta",
            "cwd": self.cwd
        }

        return data

    def create_stdout(self, data):
        l = [
            "SHELF_EVENT={0}".format(data["event"]),
            "SHELF_URI={0}".format(data["uri"]),
            "SHELF_META_URI={0}".format(data["meta_uri"])
        ]

        return ", ".join(l)

    def test_success(self):
        data = self.create_data("./tests/bin/hook-test", Event.ARTIFACT_UPLOADED)

# Path: shelf/hook/background/action.py
# def execute_command(command, log_level, event, uri, meta_uri, cwd="."):
# def create_container(log_level):
# def create_background_logger(level):
# 
# Path: shelf/hook/event.py
# class Event(object):
#     ARTIFACT_UPLOADED = "ARTIFACT_UPLOADED"
#     METADATA_UPDATED = "METADATA_UPDATED"
# 
# Path: tests/test_base.py
# class TestBase(pyproctor.TestBase):
#     @classmethod
#     def setUpClass(cls):
#         """
#             This exists to make sure that no matter what, tests
#             will log on stdout.  Every call to basicConfig after
#             this point will be a no-op
#         """
#         # AGI-731
#         # See jira for more information
#         #
#         # https://github.com/gabrielfalcao/HTTPretty/issues/280
#         #
#         # logging.basicConfig(
#         #     stream=sys.stdout
#         # )


# Path: tests/hook/background/execute_command_test.py
from mock import Mock
from shelf.hook.background import action
from shelf.hook.event import Event
from tests.test_base import TestBase
from pyproctor import MonkeyPatcher
import json
import os
import logging


    def setUp(self):
        super(ExecuteCommandTest, self).setUp()
        self.cwd = os.path.join(os.path.dirname(__file__), "../../..")
        self.logger = Mock()
        MonkeyPatcher.patch(action, "create_background_logger", Mock(return_value=self.logger))

    def create_data(self, command, event):
        data = {
            "command": command,
            "log_level": logging.DEBUG,
            "event": event,
            "uri": "https://api.shelf.com/fake/artifact/1",
            "meta_uri": "https://api.shelf.com/fake/artifact/1/_meta",
            "cwd": self.cwd
        }

        return data

    def create_stdout(self, data):
        l = [
            "SHELF_EVENT={0}".format(data["event"]),
            "SHELF_URI={0}".format(data["uri"]),
            "SHELF_META_URI={0}".format(data["meta_uri"])
        ]

        return ", ".join(l)

    def test_success(self):
        data = self.create_data("./tests/bin/hook-test", Event.ARTIFACT_UPLOADED)

        result = action.execute_command(**data)