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])
    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'),
        ])
Beispiel #3
0
class TransactionParser(object):
    """Parser for multipart/mixed transaction."""
    def parse(self, data):
        """Parse a transaction and return a Transaction object."""

        # phase 1: read transaction from stream, if necessary
        with ParserPhase() as phase:
            try:
                if not isinstance(data, basestring):
                    data = data.read()
            except Exception, e:
                phase.error(e)

        # phase 2: load the multipart/mixed data
        with ParserPhase() as phase:
            message = email.message_from_string(data)
            if not message.is_multipart():
                phase.error(TransactionNotMultipartMixedError(phase))

        # phase 3: parse and validate actions
        with ParserPhase() as phase:
            parts = message.get_payload()
            _actions = self._parse_actions(phase, parts)
            self._validate_action_ids(phase, _actions)
            return transaction.Transaction(_actions)
    def test_transaction_and_non_transaction_are_not_equal(self):
        """Verify that a Transaction and a non-Transaction are not equal."""

        self.assertFalse(transaction.Transaction([]) == [])