예제 #1
0
    def test_wants_not_message_to(self):
        conf = {'messages-we-want': {'to': '*****@*****.**'}}
        mgr = gocd.Manager(conf)

        wants = mgr.wants_message('', ['*****@*****.**'], '')

        self.assertFalse(wants)
예제 #2
0
    def test_wants_not_message_from(self):
        conf = {'messages-we-want': {'from': '*****@*****.**'}}
        mgr = gocd.Manager(conf)

        wants = mgr.wants_message('*****@*****.**', [], '')

        self.assertFalse(wants)
예제 #3
0
    def test_test_msgs(self):
        mgr = gocd.Manager(dict())
        mgr._pipeline_groups = [
            {
                'name':
                'g1',
                'pipelines': [
                    {
                        'name': 'p11',
                        'extra': 'removed'
                    },
                    {
                        'name': 'p12'
                    },
                ]
            },
            {
                'name': 'g2',
                'pipelines': [
                    {
                        'name': 'p21'
                    },
                ]
            },
        ]
        expected = [
            dict(event=gocd.Event.BREAKS, pipeline='p11'),
            dict(event=gocd.Event.CANCELLED, pipeline='p11'),
            dict(event=gocd.Event.FAILS, pipeline='p11'),
            dict(event=gocd.Event.FIXED, pipeline='p11'),
            dict(event=gocd.Event.PASSES, pipeline='p11'),
            dict(event=gocd.Event.BREAKS, pipeline='p12'),
            dict(event=gocd.Event.CANCELLED, pipeline='p12'),
            dict(event=gocd.Event.FAILS, pipeline='p12'),
            dict(event=gocd.Event.FIXED, pipeline='p12'),
            dict(event=gocd.Event.PASSES, pipeline='p12'),
            dict(event=gocd.Event.BREAKS, pipeline='p21'),
            dict(event=gocd.Event.CANCELLED, pipeline='p21'),
            dict(event=gocd.Event.FAILS, pipeline='p21'),
            dict(event=gocd.Event.FIXED, pipeline='p21'),
            dict(event=gocd.Event.PASSES, pipeline='p21'),
        ]

        loop = asyncio.get_event_loop()
        test_task = loop.create_task(mgr.test_msgs())
        loop.run_until_complete(test_task)
        actual = test_task.result()

        self.maxDiff = 1000
        self.assertEqual(list(actual), expected)
예제 #4
0
        async def check_process_message(process_message_future):
            rules = [
                {
                    'actions': ['mailto:[email protected]'],
                    'filter': {
                        'events': ['BREAKS'],
                        'function': 'pipelines.any',
                    }
                },
            ]
            mgr = gocd.Manager(dict(rules=rules))
            mgr.previous_pipeline_state = defaultdict(gocd.BuildStateSuccess)

            mail_from = '*****@*****.**'
            rcpt_tos = ['*****@*****.**']
            msg = EmailMessage()
            msg['Subject'] = 'Stage [my-pipeline/232/my-stage/1] failed'
            msg['From'] = mail_from
            msg['To'] = rcpt_tos
            msg.set_content('test')

            process_message_future.set_result(await mgr.process_message(
                mail_from, rcpt_tos, msg.as_bytes()))
예제 #5
0
    def test_parse_cctray(self):
        xml = """<?xml version="1.0" encoding="utf-8"?>
<Projects>
  <Project
    name="p1 :: build"
    activity="Sleeping"
    lastBuildStatus="Success"
    lastBuildLabel="22"
    lastBuildTime="2017-05-29T13:27:55"
    webUrl="http://go.pagero.local/go/pipelines/p1/22/build/1"
  />
  <Project
    name="p1 :: build :: defaultJob"
    activity="Sleeping"
    lastBuildStatus="Success"
    lastBuildLabel="22"
    lastBuildTime="2017-05-29T13:27:55"
    webUrl="http://go.pagero.local/go/tab/build/detail/p1/22/build/1/defaultJob"
  />
  <Project
    name="p2 :: build"
    activity="Sleeping" lastBuildStatus="Success"
    lastBuildLabel="6"
    lastBuildTime="2017-05-24T10:11:07"
    webUrl="http://go.pagero.local/go/pipelines/p2/6/build/1"
  />
  <Project
    name="p2 :: build :: defaultJob"
    activity="Sleeping"
    lastBuildStatus="Success"
    lastBuildLabel="6"
    lastBuildTime="2017-05-24T10:11:07"
    webUrl="http://go.pagero.local/go/tab/build/detail/p2/6/build/1/defaultJob"
  />
  <Project name="p2 :: test"
    activity="Sleeping"
    lastBuildStatus="Failure"
    lastBuildLabel="6"
    lastBuildTime="2017-05-24T10:20:57"
    webUrl="http://go.pagero.local/go/pipelines/p2/6/test/1"
  />
  <Project
    name="p2 :: test :: EJB_Integration_Tests"
    activity="Sleeping"
    lastBuildStatus="Success"
    lastBuildLabel="6"
    lastBuildTime="2017-05-24T10:20:57"
    webUrl="http://go.pagero.local/go/tab/build/detail/p2/6/test/1/EJB_Integration_Tests"
  />
  <Project
    name="p2 :: test :: REST-API_Integration_tests"
    activity="Sleeping"
    lastBuildStatus="Success"
    lastBuildLabel="6"
    lastBuildTime="2017-05-24T10:16:16"
    webUrl="http://go.pagero.local/go/tab/build/detail/p2/6/test/1/REST-API_Integration_tests"
  />
</Projects>"""
        mgr = gocd.Manager({})
        mgr.parse_cctray(Et.fromstring(xml))

        self.assertEqual(mgr.previous_pipeline_state['p1/build'],
                         gocd.BuildStateSuccess())
        self.assertEqual(mgr.previous_pipeline_state['p2/build'],
                         gocd.BuildStateSuccess())
        self.assertEqual(mgr.previous_pipeline_state['p2/test'],
                         gocd.BuildStateFailure())
예제 #6
0
    def test_test(self):
        pipeline_groups = [
            {
                'name':
                'g1',
                'pipelines': [
                    {
                        'name': 'p11',
                        'extra': 'removed'
                    },
                    {
                        'name': 'p12'
                    },
                ]
            },
            {
                'name': 'g2',
                'pipelines': [
                    {
                        'name': 'p21'
                    },
                ]
            },
        ]
        rules = [
            {
                'actions': ['mailto:[email protected]'],
                'filter': {
                    'events': ['BREAKS', 'FIXED'],
                    'function': 'pipelines.in_group',
                    'args': ['g1']
                }
            },
            {
                'actions': ['mailto:[email protected]'],
                'filter': {
                    'events': ['FAILS'],
                    'function': 'pipelines.in_group',
                    'args': ['g2']
                }
            },
            {
                'actions': ['mailto:[email protected]'],
                'filter': {
                    'events': ['FAILS', 'CANCELLED'],
                    'function': 'pipelines.any',
                }
            },
        ]
        expected = [
            {
                'pipeline_group':
                'g1',
                'pipelines': [
                    {
                        'pipeline':
                        'p11',
                        'alerts': [
                            {
                                'actions': ['mailto:[email protected]'],
                                'events': ['BREAKS', 'FIXED']
                            },
                            {
                                'actions': ['mailto:[email protected]'],
                                'events': ['CANCELLED', 'FAILS']
                            },
                        ]
                    },
                    {
                        'pipeline':
                        'p12',
                        'alerts': [
                            {
                                'actions': ['mailto:[email protected]'],
                                'events': ['BREAKS', 'FIXED']
                            },
                            {
                                'actions': ['mailto:[email protected]'],
                                'events': ['CANCELLED', 'FAILS']
                            },
                        ]
                    },
                ]
            },
            {
                'pipeline_group':
                'g2',
                'pipelines': [
                    {
                        'pipeline':
                        'p21',
                        'alerts': [
                            {
                                'actions': ['mailto:[email protected]'],
                                'events': ['CANCELLED', 'FAILS']
                            },
                            {
                                'actions': ['mailto:[email protected]'],
                                'events': ['FAILS']
                            },
                        ]
                    },
                ]
            },
        ]
        mgr = gocd.Manager(dict(rules=rules))
        mgr._pipeline_groups = pipeline_groups

        loop = asyncio.get_event_loop()
        test_task = loop.create_task(mgr.test())
        loop.run_until_complete(test_task)
        actual = test_task.result()

        self.maxDiff = 10000
        self.assertEqual(actual, expected)