Exemplo n.º 1
0
    def test_match_conditions_sandbox(self):
        """Testing IntegrationConfig.match_conditions with exceptions
        sandboxed
        """
        config = IntegrationConfig()
        config.settings['my_conditions'] = {
            'mode': 'all',
            'conditions': [
                {
                    'choice': 'branch',
                    'op': 'is',
                    'value': 'master',
                },
                {
                    'choice': 'summary',
                    'op': 'contains',
                    'value': '[WIP]',
                },
            ],
        }

        self.create_review_request(
            branch='master',
            summary='[WIP] This is a test.')

        self.spy_on(logging.exception)

        self.assertFalse(config.match_conditions(
            MyConfigForm,
            conditions_key='my_conditions',
            review_request='test'))

        self.assertTrue(logging.exception.spy.called)
Exemplo n.º 2
0
    def test_match_conditions(self):
        """Testing IntegrationConfig.match_conditions"""
        config = IntegrationConfig()
        config.settings['my_conditions'] = {
            'mode':
            'all',
            'conditions': [
                {
                    'choice': 'branch',
                    'op': 'is',
                    'value': 'master',
                },
                {
                    'choice': 'summary',
                    'op': 'contains',
                    'value': '[WIP]',
                },
            ],
        }

        review_request = self.create_review_request(
            branch='master', summary='[WIP] This is a test.')

        self.assertTrue(
            config.match_conditions(MyConfigForm,
                                    conditions_key='my_conditions',
                                    review_request=review_request))

        review_request = self.create_review_request(branch='master',
                                                    summary='This is a test.')

        self.assertFalse(
            config.match_conditions(MyConfigForm,
                                    conditions_key='my_conditions',
                                    review_request=review_request))
Exemplo n.º 3
0
    def test_match_conditions_sandbox(self):
        """Testing IntegrationConfig.match_conditions with exceptions
        sandboxed
        """
        config = IntegrationConfig()
        config.settings['my_conditions'] = {
            'mode':
            'all',
            'conditions': [
                {
                    'choice': 'branch',
                    'op': 'is',
                    'value': 'master',
                },
                {
                    'choice': 'summary',
                    'op': 'contains',
                    'value': '[WIP]',
                },
            ],
        }

        self.create_review_request(branch='master',
                                   summary='[WIP] This is a test.')

        self.spy_on(logging.exception)

        self.assertFalse(
            config.match_conditions(MyConfigForm,
                                    conditions_key='my_conditions',
                                    review_request='test'))

        self.assertTrue(logging.exception.spy.called)
Exemplo n.º 4
0
    def test_load_conditions_with_empty(self):
        """Testing IntegrationConfig.load_conditions with empty or missing
        data
        """
        config = IntegrationConfig()
        config.settings['conditions'] = None

        self.assertIsNone(config.load_conditions(MyConfigForm))
Exemplo n.º 5
0
    def test_load_conditions_with_empty(self):
        """Testing IntegrationConfig.load_conditions with empty or missing
        data
        """
        config = IntegrationConfig()
        config.settings['conditions'] = None

        self.assertIsNone(config.load_conditions(MyConfigForm))
Exemplo n.º 6
0
    def test_load_conditions_with_bad_data(self):
        """Testing IntegrationConfig.load_conditions with bad data"""
        config = IntegrationConfig()
        config.settings['conditions'] = 'dfsafas'

        self.spy_on(logging.debug)
        self.spy_on(logging.exception)

        self.assertIsNone(config.load_conditions(MyConfigForm))
        self.assertTrue(logging.debug.spy.called)
        self.assertTrue(logging.exception.spy.called)
Exemplo n.º 7
0
    def test_load_conditions_with_bad_data(self):
        """Testing IntegrationConfig.load_conditions with bad data"""
        config = IntegrationConfig()
        config.settings['conditions'] = 'dfsafas'

        self.spy_on(logging.debug)
        self.spy_on(logging.exception)

        self.assertIsNone(config.load_conditions(MyConfigForm))
        self.assertTrue(logging.debug.spy.called)
        self.assertTrue(logging.exception.spy.called)
Exemplo n.º 8
0
    def test_load_conditions(self):
        """Testing IntegrationConfig.load_conditions"""
        config = IntegrationConfig()
        config.settings['my_conditions'] = {
            'mode':
            'all',
            'conditions': [
                {
                    'choice': 'branch',
                    'op': 'is',
                    'value': 'master',
                },
                {
                    'choice': 'summary',
                    'op': 'contains',
                    'value': '[WIP]',
                },
            ],
        }

        condition_set = config.load_conditions(MyConfigForm,
                                               conditions_key='my_conditions')

        self.assertEqual(condition_set.mode, ConditionSet.MODE_ALL)

        conditions = condition_set.conditions
        self.assertEqual(len(conditions), 2)

        condition = conditions[0]
        self.assertEqual(condition.choice.choice_id, 'branch')
        self.assertEqual(condition.operator.operator_id, 'is')
        self.assertEqual(condition.value, 'master')

        condition = conditions[1]
        self.assertEqual(condition.choice.choice_id, 'summary')
        self.assertEqual(condition.operator.operator_id, 'contains')
        self.assertEqual(condition.value, '[WIP]')
Exemplo n.º 9
0
    def setUp(self):
        super(AdminIntegrationConfigFormViewTests, self).setUp()

        self.integration = MyIntegration(get_integration_manager())
        self.config = IntegrationConfig()
        self.request = RequestFactory().request()

        # NOTE: integration and config are normally set in dispatch(), but
        #       we're not calling into all that, so we're taking advantage of
        #       the fact that Django's class-based generic views will set any
        #       attribute passed in during construction.
        self.view = AdminIntegrationConfigFormView(
            request=self.request,
            integration=self.integration,
            config=self.config)
Exemplo n.º 10
0
    def test_match_conditions(self):
        """Testing IntegrationConfig.match_conditions"""
        config = IntegrationConfig()
        config.settings['my_conditions'] = {
            'mode': 'all',
            'conditions': [
                {
                    'choice': 'branch',
                    'op': 'is',
                    'value': 'master',
                },
                {
                    'choice': 'summary',
                    'op': 'contains',
                    'value': '[WIP]',
                },
            ],
        }

        review_request = self.create_review_request(
            branch='master',
            summary='[WIP] This is a test.')

        self.assertTrue(config.match_conditions(
            MyConfigForm,
            conditions_key='my_conditions',
            review_request=review_request))

        review_request = self.create_review_request(
            branch='master',
            summary='This is a test.')

        self.assertFalse(config.match_conditions(
            MyConfigForm,
            conditions_key='my_conditions',
            review_request=review_request))
Exemplo n.º 11
0
    def test_load_conditions(self):
        """Testing IntegrationConfig.load_conditions"""
        config = IntegrationConfig()
        config.settings['my_conditions'] = {
            'mode': 'all',
            'conditions': [
                {
                    'choice': 'branch',
                    'op': 'is',
                    'value': 'master',
                },
                {
                    'choice': 'summary',
                    'op': 'contains',
                    'value': '[WIP]',
                },
            ],
        }

        condition_set = config.load_conditions(MyConfigForm,
                                               conditions_key='my_conditions')

        self.assertEqual(condition_set.mode, ConditionSet.MODE_ALL)

        conditions = condition_set.conditions
        self.assertEqual(len(conditions), 2)

        condition = conditions[0]
        self.assertEqual(condition.choice.choice_id, 'branch')
        self.assertEqual(condition.operator.operator_id, 'is')
        self.assertEqual(condition.value, 'master')

        condition = conditions[1]
        self.assertEqual(condition.choice.choice_id, 'summary')
        self.assertEqual(condition.operator.operator_id, 'contains')
        self.assertEqual(condition.value, '[WIP]')