コード例 #1
0
ファイル: test_data.py プロジェクト: zeantsoi/reddit
    def test_str_to_date(self):
        """Assert that str_to_date takes an exact format and returns a date."""

        invalid_str = '2011-11-11T11:11:11'

        # Assert that an invalid string format will raise a ValueError
        with self.assertRaises(ValueError):
            str_to_date(invalid_str)

        # Assert that a valid string will return a datetime
        valid_date = str_to_date(self.valid_date_str)
        self.assertTrue(type(valid_date), datetime.datetime)
コード例 #2
0
ファイル: test_data.py プロジェクト: zeantsoi/reddit
    def test_str_to_date(self):
        """Assert that str_to_date takes an exact format and returns a date."""

        invalid_str = '2011-11-11T11:11:11'

        # Assert that an invalid string format will raise a ValueError
        with self.assertRaises(ValueError):
            str_to_date(invalid_str)

        # Assert that a valid string will return a datetime
        valid_date = str_to_date(self.valid_date_str)
        self.assertTrue(type(valid_date), datetime.datetime)
コード例 #3
0
ファイル: test_data.py プロジェクト: zeantsoi/reddit
    def test_write_batch_settlement(self, settlement, write_statistic,
                                    update_transactions):
        """Assert that AuthorizeBatchSettlement is initialized with the correct
        args and that _write_batch_statistic is called accordingly.

        """

        time_str = self.valid_date_str
        xml = '<batchid>123</batchid>' + \
              '<settlementtimeutc>' + time_str + '</settlementtimeutc>' + \
              '<settlementstate>OK</settlementstate>' + \
              '<statistic></statistic><statistic></statistic>'
        data = BeautifulStoneSoup(xml)

        _write_batch_settlement(data)

        # Assert that AuthorizeBatchSettlement is correctly initialized
        settlement.assert_called_once_with(
            batch_id=123,
            settlement_state='OK',
            settlement_time=str_to_date(time_str),
        )

        # Assert that _write_batch_statistic is called once for each incidence
        # of <transaction</transaction> in the XML
        self.assertEquals(write_statistic.call_count, 2)

        # Assert that update_transactions is called with batch ID
        update_transactions.assert_called_once_with(123)
コード例 #4
0
ファイル: test_data.py プロジェクト: zeantsoi/reddit
    def test_write_batch_settlement(self, settlement, write_statistic,
                                    update_transactions):
        """Assert that AuthorizeBatchSettlement is initialized with the correct
        args and that _write_batch_statistic is called accordingly.

        """

        time_str = self.valid_date_str
        xml = '<batchid>123</batchid>' + \
              '<settlementtimeutc>' + time_str + '</settlementtimeutc>' + \
              '<settlementstate>OK</settlementstate>' + \
              '<statistic></statistic><statistic></statistic>'
        data = BeautifulStoneSoup(xml)

        _write_batch_settlement(data)

        # Assert that AuthorizeBatchSettlement is correctly initialized
        settlement.assert_called_once_with(
            batch_id=123,
            settlement_state='OK',
            settlement_time=str_to_date(time_str),
        )

        # Assert that _write_batch_statistic is called once for each incidence
        # of <transaction</transaction> in the XML
        self.assertEquals(write_statistic.call_count, 2)

        # Assert that update_transactions is called with batch ID
        update_transactions.assert_called_once_with(123)