# Path: gocdapi_tests/systests/base.py
# class BaseSystemTest(unittest.TestCase):
#     def pipeline_group_name(self):
#         return DEFAULT_GO_PIPELINE_GROUP
# 
#     def setUp(self):
#         self.go = Go('%s:%d' % (DEFAULT_GO_URL, DEFAULT_GO_PORT))
#         self._delete_test_pipelines_group(self.pipeline_group_name())
#         self._create_test_pipelines_group(self.pipeline_group_name())
#         self.go.admin.create_pipeline_from_xml(self.pipeline_group_name(), EMPTY_PIPELINE % "pipe_for_tests")
# 
#     def tearDown(self):
#         self._delete_test_pipelines_group(self.pipeline_group_name())
# 
#     def _delete_test_pipelines_group(self, name):
#         if name in self.go.pipeline_groups:
#             self.go.admin.delete_pipeline_group(name)
# 
#     def _create_test_pipelines_group(self, name):
#         if name not in self.go.pipeline_groups:
#             pipeline_group = self.go.admin.create_pipeline_group(name)
# 
#     def assert_pipeline_is_present(self, name):
#         self.assertTrue(self.go.pipeline_exist(name), 'Pipeline %r is absent in Go.' % name)
# 
#     def wait_for_agent_reconnection(self, agent_uuid):
#         for _ in xrange(3):
#             log.info("Waiting for agent %s connect" % agent_uuid)
#             time.sleep(10)
#             if agent_uuid in self.go.agents:
#                 return
#         raise Exception("Agent %s didn't connect again to the server" % agent_uuid)
# 
# Path: gocdapi_tests/systests/pipeline_configs.py
# EMPTY_PIPELINE = '''\
# <pipeline name="%s">
#   <materials>
#     <git url="git://127.0.0.1/precommit.git"/>
#   </materials>
#   <stage name="stage1">
#     <environmentvariables>
#       <variable name="PYTHONUNBUFFERED">
#         <value>1</value>
#       </variable>
#     </environmentvariables>
#     <jobs>
#       <job name="job1">
#         <tasks>
#           <exec command="python">
#             <arg>foo.py</arg>
#             <runif status="passed"/>
#           </exec>
#         </tasks>
#       </job>
#     </jobs>
#   </stage>
#   <stage name="stage2">
#     <environmentvariables>
#       <variable name="PYTHONUNBUFFERED">
#         <value>True</value>
#       </variable>
#     </environmentvariables>
#     <jobs>
#       <job name="job1">
#         <tasks>
#           <exec command="python">
#             <arg>bar.py</arg>
#             <runif status="passed"/>
#           </exec>
#         </tasks>
#       </job>
#     </jobs>
#   </stage>
# </pipeline>
# '''.strip()
# 
# UPDATED_PIPELINE = '''\
# <pipeline name="%s">
#   <materials>
#     <git url="git://127.0.0.1/precommit.git"/>
#   </materials>
#   <stage name="super_stage">
#     <environmentvariables>
#       <variable name="PYTHONUNBUFFERED">
#         <value>1</value>
#       </variable>
#     </environmentvariables>
#     <jobs>
#       <job name="job1">
#         <tasks>
#           <exec command="python">
#             <arg>foo.py</arg>
#             <runif status="passed"/>
#           </exec>
#         </tasks>
#       </job>
#     </jobs>
#   </stage>
# </pipeline>
# '''.strip()
# 
# Path: gocdapi_tests/test_utils/random_strings.py
# def random_string(length=10):
#     return ''.join(random.choice(string.ascii_lowercase) for i in range(length))


import unittest
from gocdapi_tests.systests.base import BaseSystemTest
from gocdapi_tests.systests.pipeline_configs import EMPTY_PIPELINE, UPDATED_PIPELINE
from gocdapi_tests.test_utils.random_strings import random_string
'''
System tests for `gocdapi.go` module.
'''



class TestAdmin(BaseSystemTest):
    def test_create_delete_pipeline(self):
        pipeline_name = 'test_pipeline_%s' % random_string()
        self.go.admin.create_pipeline_from_xml(self.pipeline_group_name(), EMPTY_PIPELINE % pipeline_name)
        self.assert_pipeline_is_present(pipeline_name)

    def test_create_delete_pipeline_group(self):

# Path: gocdapi_tests/systests/base.py
# class BaseSystemTest(unittest.TestCase):
#     def pipeline_group_name(self):
#         return DEFAULT_GO_PIPELINE_GROUP
# 
#     def setUp(self):
#         self.go = Go('%s:%d' % (DEFAULT_GO_URL, DEFAULT_GO_PORT))
#         self._delete_test_pipelines_group(self.pipeline_group_name())
#         self._create_test_pipelines_group(self.pipeline_group_name())
#         self.go.admin.create_pipeline_from_xml(self.pipeline_group_name(), EMPTY_PIPELINE % "pipe_for_tests")
# 
#     def tearDown(self):
#         self._delete_test_pipelines_group(self.pipeline_group_name())
# 
#     def _delete_test_pipelines_group(self, name):
#         if name in self.go.pipeline_groups:
#             self.go.admin.delete_pipeline_group(name)
# 
#     def _create_test_pipelines_group(self, name):
#         if name not in self.go.pipeline_groups:
#             pipeline_group = self.go.admin.create_pipeline_group(name)
# 
#     def assert_pipeline_is_present(self, name):
#         self.assertTrue(self.go.pipeline_exist(name), 'Pipeline %r is absent in Go.' % name)
# 
#     def wait_for_agent_reconnection(self, agent_uuid):
#         for _ in xrange(3):
#             log.info("Waiting for agent %s connect" % agent_uuid)
#             time.sleep(10)
#             if agent_uuid in self.go.agents:
#                 return
#         raise Exception("Agent %s didn't connect again to the server" % agent_uuid)
# 
# Path: gocdapi_tests/systests/pipeline_configs.py
# EMPTY_PIPELINE = '''\
# <pipeline name="%s">
#   <materials>
#     <git url="git://127.0.0.1/precommit.git"/>
#   </materials>
#   <stage name="stage1">
#     <environmentvariables>
#       <variable name="PYTHONUNBUFFERED">
#         <value>1</value>
#       </variable>
#     </environmentvariables>
#     <jobs>
#       <job name="job1">
#         <tasks>
#           <exec command="python">
#             <arg>foo.py</arg>
#             <runif status="passed"/>
#           </exec>
#         </tasks>
#       </job>
#     </jobs>
#   </stage>
#   <stage name="stage2">
#     <environmentvariables>
#       <variable name="PYTHONUNBUFFERED">
#         <value>True</value>
#       </variable>
#     </environmentvariables>
#     <jobs>
#       <job name="job1">
#         <tasks>
#           <exec command="python">
#             <arg>bar.py</arg>
#             <runif status="passed"/>
#           </exec>
#         </tasks>
#       </job>
#     </jobs>
#   </stage>
# </pipeline>
# '''.strip()
# 
# UPDATED_PIPELINE = '''\
# <pipeline name="%s">
#   <materials>
#     <git url="git://127.0.0.1/precommit.git"/>
#   </materials>
#   <stage name="super_stage">
#     <environmentvariables>
#       <variable name="PYTHONUNBUFFERED">
#         <value>1</value>
#       </variable>
#     </environmentvariables>
#     <jobs>
#       <job name="job1">
#         <tasks>
#           <exec command="python">
#             <arg>foo.py</arg>
#             <runif status="passed"/>
#           </exec>
#         </tasks>
#       </job>
#     </jobs>
#   </stage>
# </pipeline>
# '''.strip()
# 
# Path: gocdapi_tests/test_utils/random_strings.py
# def random_string(length=10):
#     return ''.join(random.choice(string.ascii_lowercase) for i in range(length))


# Path: gocdapi_tests/systests/test_admin.py
import unittest
from gocdapi_tests.systests.base import BaseSystemTest
from gocdapi_tests.systests.pipeline_configs import EMPTY_PIPELINE, UPDATED_PIPELINE
from gocdapi_tests.test_utils.random_strings import random_string

'''
System tests for `gocdapi.go` module.
'''



class TestAdmin(BaseSystemTest):
    def test_create_delete_pipeline(self):
        pipeline_name = 'test_pipeline_%s' % random_string()
        self.go.admin.create_pipeline_from_xml(self.pipeline_group_name(), EMPTY_PIPELINE % pipeline_name)
        self.assert_pipeline_is_present(pipeline_name)

    def test_create_delete_pipeline_group(self):

        pipeline_group = 'test_pipeline_group_%s' % random_string()