コード例 #1
0
    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])
コード例 #2
0
    def test_committer_signature_matches_committer_and_committer_date(self):
        """Verify that the committer signature matches committer name/date."""

        action = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 +0100',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 +0100',
            'This is a commit message')
        signature = action.committer_signature()

        self.assertEqual(signature.name, 'Jeff Arnold')
        self.assertEqual(signature.email, '*****@*****.**')
        self.assertEqual(signature.time, 1374782771)
        self.assertEqual(signature.offset, 60)

        action = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 -0100',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 -0100',
            'This is a commit message')
        signature = action.committer_signature()

        self.assertEqual(signature.name, 'Aidan Wilkins')
        self.assertEqual(signature.email, '*****@*****.**')
        self.assertEqual(signature.time, 1376405234)
        self.assertEqual(signature.offset, -60)
コード例 #3
0
    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'),
        ])
コード例 #4
0
    def test_different_commit_actions_are_different(self):
        """Verify that different commit actions are different."""

        action1 = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 +0100',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 +0100',
            'This is a commit message')
        action2 = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 +0100',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 +0100',
            'This is a different commit message')
        self.assertFalse(action1 == action2)
コード例 #5
0
    def test_equal_commit_actions_are_equal(self):
        """Verify that equal commit actions are equal."""

        action1 = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 +0100',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 +0100',
            'This is a commit message')
        action2 = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 +0100',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 +0100',
            'This is a commit message')
        self.assertEqual(action1, action2)
コード例 #6
0
    def test_constructor_sets_action_id_and_other_fields(self):
        """Verify that the constructor sets the action id and other fields."""

        action = actions.CommitAction(
            'foo', 'refs/heads/master',
            'Jannis Pohlmann <*****@*****.**>',
            '1379947345 +0100',
            'Jannis Pohlmann <*****@*****.**>',
            '1380614011 +0100',
            'This is a commit message')

        self.assertEqual(action.id, 'foo')
        self.assertEqual(action.target, 'refs/heads/master')
        self.assertEqual(action.author,
                         'Jannis Pohlmann <*****@*****.**>')
        self.assertEqual(action.author_date, '1379947345 +0100')
        self.assertEqual(action.committer,
                         'Jannis Pohlmann <*****@*****.**>')
        self.assertEqual(action.committer_date, '1380614011 +0100')
        self.assertEqual(action.message, 'This is a commit message')

        action = actions.CommitAction(
            'bar', 'refs/heads/user/branch',
            'Aidan Wilkins <*****@*****.**>',
            '1376405234 +0100',
            'Jeff Arnold <*****@*****.**>',
            '1374782771 +0100',
            'This is a different commit message')

        self.assertEqual(action.id, 'bar')
        self.assertEqual(action.target, 'refs/heads/user/branch')
        self.assertEqual(action.author,
                         'Aidan Wilkins <*****@*****.**>')
        self.assertEqual(action.author_date, '1376405234 +0100')
        self.assertEqual(action.committer,
                         'Jeff Arnold <*****@*****.**>')
        self.assertEqual(action.committer_date, '1374782771 +0100')
        self.assertEqual(action.message, 'This is a different commit message')
コード例 #7
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)
コード例 #8
0
    def _parse_commit_action(self, phase, part):
        self._check_for_content_type(phase, part, 'application/x-yaml',
                                     'application/json')

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

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

        if not phase.errors:
            if 'target' not in data:
                phase.error(ActionTargetRefUndefinedError(phase, part))

            if not isinstance(data.get('target', ''), basestring):
                phase.error(ActionTargetRefNotAStringError(phase, part))

            if 'author' not in data:
                phase.error(ActionAuthorUndefinedError(phase, part))

            author = data.get('author', None)
            if not expressions.commit_author.match(author):
                phase.error(ActionAuthorInvalidError(phase, part, author))

            if 'author-date' not in data:
                phase.error(ActionAuthorDateUndefinedError(phase, part))

            author_date = data.get('author-date', None)
            if not expressions.commit_date.match(author_date):
                phase.error(
                    ActionAuthorDateInvalidError(phase, part, author_date))

            if 'committer' not in data:
                phase.error(ActionCommitterUndefinedError(phase, part))

            committer = data.get('committer', None)
            if not expressions.commit_committer.match(committer):
                phase.error(ActionCommitterInvalidError(
                    phase, part, committer))

            if 'committer-date' not in data:
                phase.error(ActionCommitterDateUndefinedError(phase, part))

            committer_date = data.get('committer-date', None)
            if not expressions.commit_date.match(committer_date):
                phase.error(
                    ActionCommitterDateInvalidError(phase, part,
                                                    committer_date))

            if 'message' not in data:
                phase.error(ActionCommitMessageUndefinedError(phase, part))

            if not isinstance(data.get('message', ''), basestring):
                phase.error(ActionCommitMessageNotAStringError(phase, part))

        if not phase.errors:
            return actions.CommitAction(data.get('id', None), data['target'],
                                        data['author'], data['author-date'],
                                        data['committer'],
                                        data['committer-date'],
                                        data['message'])