def test_constructor_sets_actions(self):
        """Verify that the constructor sets actions."""

        t = transaction.Transaction([])
        self.assertEqual(t.actions, [])

        t = transaction.Transaction([
            actions.BeginAction('1',
                                '7926b7228356b3b79b77fe5c8617a33a6fcf5849'),
            actions.UpdateAction(
                '2', 'e03debd2-b1e5-459c-9ca6-2b91c8c8217e', None,
                [properties.TextProperty('title', 'new title')]),
            actions.CommitAction('3', 'refs/heads/master', 'author',
                                 '1379682134 +0100', 'committer',
                                 '1379683379 +0100', 'message'),
        ])
        self.assertEqual(t.actions, [
            actions.BeginAction('1',
                                '7926b7228356b3b79b77fe5c8617a33a6fcf5849'),
            actions.UpdateAction(
                '2', 'e03debd2-b1e5-459c-9ca6-2b91c8c8217e', None,
                [properties.TextProperty('title', 'new title')]),
            actions.CommitAction('3', 'refs/heads/master', 'author',
                                 '1379682134 +0100', 'committer',
                                 '1379683379 +0100', 'message'),
        ])
    def test_commit_action_matches_first_action(self):
        """Verify that equal transactions are equal."""

        transaction1 = transaction.Transaction([
            actions.BeginAction('1',
                                '7926b7228356b3b79b77fe5c8617a33a6fcf5849'),
            actions.UpdateAction(
                '2', 'e03debd2-b1e5-459c-9ca6-2b91c8c8217e', None,
                [properties.TextProperty('title', 'new title')]),
            actions.CommitAction('3', 'refs/heads/master', 'author',
                                 '1379682134 +0100', 'committer',
                                 '1379683379 +0100', 'message'),
        ])

        self.assertEqual(transaction1.commit(), transaction1.actions[2])

        transaction2 = transaction.Transaction([
            actions.BeginAction('1',
                                '7926b7228356b3b79b77fe5c8617a33a6fcf5849'),
            actions.UpdateAction(
                '2', 'e03debd2-b1e5-459c-9ca6-2b91c8c8217e', None,
                [properties.TextProperty('title', 'new title')]),
            actions.CommitAction('2', 'refs/heads/yourbranch', 'author',
                                 '1379682134 +0100', 'committer',
                                 '1379683379 +0100', 'message'),
        ])

        self.assertEqual(transaction2.commit(), transaction2.actions[2])
Пример #3
0
    def test_equal_begin_actions_are_equal(self):
        """Verify that equal begin actions are equal."""

        action1 = actions.BeginAction(
            'foo', 'dca2e18637af3d0d73bb575c7501869fdc3aad15')
        action2 = actions.BeginAction(
            'foo', 'dca2e18637af3d0d73bb575c7501869fdc3aad15')
        self.assertEqual(action1, action2)
Пример #4
0
    def test_different_begin_actions_are_not_equal(self):
        """Verify that different begin actions are not equal."""

        action1 = actions.BeginAction(
            'foo', 'dca2e18637af3d0d73bb575c7501869fdc3aad15')
        action2 = actions.BeginAction(
            'bar', 'dca2e18637af3d0d73bb575c7501869fdc3aad15')
        self.assertFalse(action1 == action2)

        action1 = actions.BeginAction(
            'foo', 'dca2e18637af3d0d73bb575c7501869fdc3aad15')
        action2 = actions.BeginAction(
            'foo', '54d4bca0df18a068061c135ca6c3d35cff44770e')
        self.assertFalse(action1 == action2)
Пример #5
0
    def test_constructor_sets_action_id_and_source_sha1(self):
        """Verify that the constructor sets the action id and source."""

        action = actions.BeginAction(
            '1', 'b5f538a424ef18782dfe11fe5be764275394a14a')
        self.assertEqual(action.id, '1')
        self.assertEqual(
            action.source, 'b5f538a424ef18782dfe11fe5be764275394a14a')

        action = actions.BeginAction(
            '2', 'b5f538a424ef18782dfe11fe5be764275394a14a')
        self.assertEqual(action.id, '2')
        self.assertEqual(
            action.source, 'b5f538a424ef18782dfe11fe5be764275394a14a')

        action = actions.BeginAction(
            '2', '4a723c3748b984962f58dfcfc274995f4a7e75db')
        self.assertEqual(action.id, '2')
        self.assertEqual(
            action.source, '4a723c3748b984962f58dfcfc274995f4a7e75db')
Пример #6
0
    def test_equality_operator_is_false_if_action_classes_dont_match(self):
        """Verify that the equality operator is false if classes differ."""

        acts = [
            actions.BeginAction('foo', 'source'),
            actions.CommitAction(
                'foo', 'target', 'author', 'author date',
                'committer', 'committer date', 'message'),
            actions.CreateAction('foo', 'klass', []),
            actions.DeleteAction('foo', 'uuid', None),
            actions.UpdateAction('foo', 'uuid', None, []),
            actions.UpdateRawPropertyAction(
                'foo', 'uuid', None, 'p', 't', 'data'),
            actions.UnsetRawPropertyAction('foo', 'uuid', None, 'prop'),
            ]

        for action1, action2 in itertools.permutations(acts, 2):
            self.assertFalse(action1 == action2)
Пример #7
0
    def _parse_begin_action(self, phase, part):
        self._check_for_content_type(phase, part, 'application/json',
                                     'application/x-yaml')

        if not phase.errors:
            data = self._load_action_data(phase, part)

        if not phase.errors:
            if data.get('action', None) != 'begin':
                phase.error(ActionNoBeginActionError(phase, part))

            if 'source' not in data:
                phase.error(ActionSourceCommitUndefinedError(phase, part))

            source = data.get('source', None)

            if not expressions.commit_sha1.match(source):
                phase.error(ActionSourceCommitInvalidError(
                    phase, part, source))

        if not phase.errors:
            return actions.BeginAction(data.get('id', None), source)