# 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/container.py
# class Container(object):
#     def __init__(self, logger):
#         """
#             Args:
#                 logger(logging.Logger)
#                 command(string)
#         """
#         self.logger = logger
# 
#     def create_manager(self, host, command=None):
#         """
#             Args:
#                 host(string)
#                 command(string)
# 
#             Returns:
#                 shelf.hook.manager.Manager
#         """
#         return Manager(
#             self,
#             multiprocessing,
#             host,
#             command
#         )
# 
#     def create_null_manager(self):
#         """
#             Returns:
#                 shelf.hook.null_manager.NullManager
#         """
#         return NullManager()
# 
# Path: shelf/hook/event.py
# class Event(object):
#     ARTIFACT_UPLOADED = "ARTIFACT_UPLOADED"
#     METADATA_UPDATED = "METADATA_UPDATED"
# 
# Path: shelf/hook/manager.py
# class Manager(object):
#     def __init__(self, container, multiprocessing, host, command):
#         """
#             Args:
#                 container(shelf.hook.container)
#                 multiprocessing(multiprocessing)
#                 host(string) The protocol + hostname which hosts shelf.
#                 command(string) Command to run for each event.
#         """
#         self.container = container
#         self.multiprocessing = multiprocessing
#         self.host = host
#         self.command = command
# 
#     def notify_artifact_uploaded(self, identity):
#         """
#             Fires an event that describes an artifact being uploaded.
# 
#             Args:
#                 identity(shelf.resource_identity)
#         """
#         self._notify(identity, Event.ARTIFACT_UPLOADED)
# 
#     def notify_metadata_updated(self, identity):
#         """
#             Fires an event that describes an artifact's metadata being updated.
#             This will notify any hooks that are listening.
# 
#             Args:
#                 identity(shelf.resource_identity)
#         """
#         self._notify(identity, Event.METADATA_UPDATED)
# 
#     def _notify(self, identity, event):
#         # I am assured that the identity's properties
#         # will always begin with a "/" and the host
#         # will NOT end in one.
#         # Because the identity's properties start with "/"
#         # os.path.join will not work.
#         uri = self.host + identity.resource_url
#         meta_uri = self.host + identity.metadata
#         data = {
#             "command": self.command,
#             "event": event,
#             "uri": uri,
#             "meta_uri": meta_uri,
#             "log_level": self.container.logger.level
#         }
#         process = self.multiprocessing.Process(target=action.execute_command, kwargs=data)
#         process.start()
# 
# 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.container import Container
from shelf.hook.event import Event
from shelf.hook.manager import Manager
from shelf.resource_identity import ResourceIdentity
from tests.test_base import TestBase
import logging
        self.logger = logging.getLogger("TestLogger")
        self.logger.setLevel(logging.INFO)
        self.container = Container(self.logger)
        self.manager = Manager(
            self.container,
            self.multiprocessing,
            self.host,
            self.command
        )

    def assert_process(self, event):
        self.multiprocessing.Process.assert_called_with(
            target=action.execute_command,
            kwargs={
                "command": self.command,
                "event": event,
                "uri": "https://api.shelf.com/blah/artifact/my/path",
                "meta_uri": "https://api.shelf.com/blah/artifact/my/path/_meta",
                "log_level": logging.INFO
            }
        )

        self.process.start.assert_called_once_with()

    def test_notify_artifact_uploaded(self):
        self.manager.notify_artifact_uploaded(self.identity)
        self.assert_process(Event.ARTIFACT_UPLOADED)

    def test_notify_metadata_updated(self):
        self.manager.notify_metadata_updated(self.identity)

# 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/container.py
# class Container(object):
#     def __init__(self, logger):
#         """
#             Args:
#                 logger(logging.Logger)
#                 command(string)
#         """
#         self.logger = logger
# 
#     def create_manager(self, host, command=None):
#         """
#             Args:
#                 host(string)
#                 command(string)
# 
#             Returns:
#                 shelf.hook.manager.Manager
#         """
#         return Manager(
#             self,
#             multiprocessing,
#             host,
#             command
#         )
# 
#     def create_null_manager(self):
#         """
#             Returns:
#                 shelf.hook.null_manager.NullManager
#         """
#         return NullManager()
# 
# Path: shelf/hook/event.py
# class Event(object):
#     ARTIFACT_UPLOADED = "ARTIFACT_UPLOADED"
#     METADATA_UPDATED = "METADATA_UPDATED"
# 
# Path: shelf/hook/manager.py
# class Manager(object):
#     def __init__(self, container, multiprocessing, host, command):
#         """
#             Args:
#                 container(shelf.hook.container)
#                 multiprocessing(multiprocessing)
#                 host(string) The protocol + hostname which hosts shelf.
#                 command(string) Command to run for each event.
#         """
#         self.container = container
#         self.multiprocessing = multiprocessing
#         self.host = host
#         self.command = command
# 
#     def notify_artifact_uploaded(self, identity):
#         """
#             Fires an event that describes an artifact being uploaded.
# 
#             Args:
#                 identity(shelf.resource_identity)
#         """
#         self._notify(identity, Event.ARTIFACT_UPLOADED)
# 
#     def notify_metadata_updated(self, identity):
#         """
#             Fires an event that describes an artifact's metadata being updated.
#             This will notify any hooks that are listening.
# 
#             Args:
#                 identity(shelf.resource_identity)
#         """
#         self._notify(identity, Event.METADATA_UPDATED)
# 
#     def _notify(self, identity, event):
#         # I am assured that the identity's properties
#         # will always begin with a "/" and the host
#         # will NOT end in one.
#         # Because the identity's properties start with "/"
#         # os.path.join will not work.
#         uri = self.host + identity.resource_url
#         meta_uri = self.host + identity.metadata
#         data = {
#             "command": self.command,
#             "event": event,
#             "uri": uri,
#             "meta_uri": meta_uri,
#             "log_level": self.container.logger.level
#         }
#         process = self.multiprocessing.Process(target=action.execute_command, kwargs=data)
#         process.start()
# 
# 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/manager_test.py
from mock import Mock
from shelf.hook.background import action
from shelf.hook.container import Container
from shelf.hook.event import Event
from shelf.hook.manager import Manager
from shelf.resource_identity import ResourceIdentity
from tests.test_base import TestBase
import logging

        self.logger = logging.getLogger("TestLogger")
        self.logger.setLevel(logging.INFO)
        self.container = Container(self.logger)
        self.manager = Manager(
            self.container,
            self.multiprocessing,
            self.host,
            self.command
        )

    def assert_process(self, event):
        self.multiprocessing.Process.assert_called_with(
            target=action.execute_command,
            kwargs={
                "command": self.command,
                "event": event,
                "uri": "https://api.shelf.com/blah/artifact/my/path",
                "meta_uri": "https://api.shelf.com/blah/artifact/my/path/_meta",
                "log_level": logging.INFO
            }
        )

        self.process.start.assert_called_once_with()

    def test_notify_artifact_uploaded(self):
        self.manager.notify_artifact_uploaded(self.identity)
        self.assert_process(Event.ARTIFACT_UPLOADED)

    def test_notify_metadata_updated(self):
        self.manager.notify_metadata_updated(self.identity)

        self.assert_process(Event.METADATA_UPDATED)