# Path: hoplite/builtin_plugins/constants.py
# class SyncPerforcePathJobConstants(object):
#     USER = "USER"
#     CLIENT_WORKSPACE = "CLIENT_WORKSPACE"
#     P4_HOST = "P4_HOST"
#     P4_PORT = "P4_PORT"
#     PERFORCE_PATH = "PERFORCE_PATH"
#     FORCE = "FORCE"
# 
# Path: hoplite/builtin_plugins/sync_perforce_path_job.py
# def run(config, status):
#     user = config.get(KEYS.USER, "")
#     client_workspace = config.get(KEYS.CLIENT_WORKSPACE, "")
#     p4_port = config.get(KEYS.P4_PORT, "perforce:1666")
#     force = config.get(KEYS.FORCE, True)
#     p4_path = config.get(KEYS.PERFORCE_PATH, "")
# 
#     stderr, stdout = p4_sync_command(
#         client_workspace, p4_path, p4_port, user, force=force)
# 
#     if stderr == "":
#         local_path = p4_where_command(client_workspace, p4_path, p4_port, user)
#         if re.search('\.\.\.', local_path):
#             # Perforce puts /... if you synced a directory, we need to remove
#             # it to have a valid path
#             local_path = os.path.dirname(local_path)
#         status.update(
#             {"succeeded": True, "stdout": stdout, "local_path": local_path})
#     else:
#         status.update({"succeeded": False, "stdout": stdout, "stderr": stderr})
# 
# Path: hoplite/client/status_updater.py
# class MockStatusUpdater(object):
#     """
#     For use while developing a job
#     """
#     def __init__(self, addr="0.0.0.0:5000", uuid="{0}", api_key=""):
#         self.addr = addr
#         self._uuid = uuid
#         self._daemon_addr = 'http://{0}'.format(self.addr)
#         self._api_key = api_key
#         self.status = {}
# 
#     def update(self, status):
#         """
#         Prints the status to stdout for debugging and sets the
#         member variable status for use in testing status updates
# 
#         :param status: status dictionary
#         """
#         self.status = status
#         print(self.status)


import os
import platform
import shutil
import stat
import unittest2
from hoplite.builtin_plugins.constants import SyncPerforcePathJobConstants as KEYS
from hoplite.builtin_plugins.sync_perforce_path_job import run as sync_perforce_path
from hoplite.client.status_updater import MockStatusUpdater



class TestSyncPerforcePathJob(unittest2.TestCase):
    def setUp(self):
        self.opsys = platform.system().lower()
        if self.opsys == 'windows':
            self.workspace = "riormt_hoplite_test_windows"
            self.workspace_root = r"C:\riormt_hoplite_test_windows"
            self.export_location_path = "C:\\riormt_hoplite_test_windows\\microDAQ\\exportLocation"
        elif self.opsys == 'linux' or self.opsys == 'darwin':
            self.workspace = "riormt_hoplite_test_posix"
            self.workspace_root = "/tmp/riormt_hoplite_test_posix"
            self.export_location_path = "/tmp/riormt_hoplite_test_posix/microDAQ/exportLocation"
        self.status = MockStatusUpdater()

    def test_sync_works(self):
        try:
            synced_file = os.path.join(self.workspace_root, "microDAQ", "exportLocation")
            config = {
                KEYS.USER: "riormt",
                KEYS.P4_PORT: "penguin.natinst.com:1666",
                KEYS.PERFORCE_PATH: "//microDAQ/exportLocation",

# Path: hoplite/builtin_plugins/constants.py
# class SyncPerforcePathJobConstants(object):
#     USER = "USER"
#     CLIENT_WORKSPACE = "CLIENT_WORKSPACE"
#     P4_HOST = "P4_HOST"
#     P4_PORT = "P4_PORT"
#     PERFORCE_PATH = "PERFORCE_PATH"
#     FORCE = "FORCE"
# 
# Path: hoplite/builtin_plugins/sync_perforce_path_job.py
# def run(config, status):
#     user = config.get(KEYS.USER, "")
#     client_workspace = config.get(KEYS.CLIENT_WORKSPACE, "")
#     p4_port = config.get(KEYS.P4_PORT, "perforce:1666")
#     force = config.get(KEYS.FORCE, True)
#     p4_path = config.get(KEYS.PERFORCE_PATH, "")
# 
#     stderr, stdout = p4_sync_command(
#         client_workspace, p4_path, p4_port, user, force=force)
# 
#     if stderr == "":
#         local_path = p4_where_command(client_workspace, p4_path, p4_port, user)
#         if re.search('\.\.\.', local_path):
#             # Perforce puts /... if you synced a directory, we need to remove
#             # it to have a valid path
#             local_path = os.path.dirname(local_path)
#         status.update(
#             {"succeeded": True, "stdout": stdout, "local_path": local_path})
#     else:
#         status.update({"succeeded": False, "stdout": stdout, "stderr": stderr})
# 
# Path: hoplite/client/status_updater.py
# class MockStatusUpdater(object):
#     """
#     For use while developing a job
#     """
#     def __init__(self, addr="0.0.0.0:5000", uuid="{0}", api_key=""):
#         self.addr = addr
#         self._uuid = uuid
#         self._daemon_addr = 'http://{0}'.format(self.addr)
#         self._api_key = api_key
#         self.status = {}
# 
#     def update(self, status):
#         """
#         Prints the status to stdout for debugging and sets the
#         member variable status for use in testing status updates
# 
#         :param status: status dictionary
#         """
#         self.status = status
#         print(self.status)


# Path: tests/builtin_plugins/test_sync_perforce_path_job.py
import os
import platform
import shutil
import stat
import unittest2
from hoplite.builtin_plugins.constants import SyncPerforcePathJobConstants as KEYS
from hoplite.builtin_plugins.sync_perforce_path_job import run as sync_perforce_path
from hoplite.client.status_updater import MockStatusUpdater




class TestSyncPerforcePathJob(unittest2.TestCase):
    def setUp(self):
        self.opsys = platform.system().lower()
        if self.opsys == 'windows':
            self.workspace = "riormt_hoplite_test_windows"
            self.workspace_root = r"C:\riormt_hoplite_test_windows"
            self.export_location_path = "C:\\riormt_hoplite_test_windows\\microDAQ\\exportLocation"
        elif self.opsys == 'linux' or self.opsys == 'darwin':
            self.workspace = "riormt_hoplite_test_posix"
            self.workspace_root = "/tmp/riormt_hoplite_test_posix"
            self.export_location_path = "/tmp/riormt_hoplite_test_posix/microDAQ/exportLocation"
        self.status = MockStatusUpdater()

    def test_sync_works(self):
        try:
            synced_file = os.path.join(self.workspace_root, "microDAQ", "exportLocation")
            config = {
                KEYS.USER: "riormt",
                KEYS.P4_PORT: "penguin.natinst.com:1666",
                KEYS.PERFORCE_PATH: "//microDAQ/exportLocation",

                KEYS.CLIENT_WORKSPACE: self.workspace,