Exemplo n.º 1
0
    def test_purchased_csv(self):
        """
        Tests that a generated purchase report CSV is as we expect
        """
        # coerce the purchase times to self.test_time so that the test can match.
        # It's pretty hard to patch datetime.datetime b/c it's a python built-in, which is immutable, so we
        # make the times match this way
        for item in OrderItem.purchased_items_btw_dates(self.now - self.FIVE_MINS, self.now + self.FIVE_MINS):
            item.fulfilled_time = self.test_time
            item.save()

        # add annotation to the
        csv_file = StringIO.StringIO()
        OrderItem.csv_purchase_report_btw_dates(csv_file, self.now - self.FIVE_MINS, self.now + self.FIVE_MINS)
        csv = csv_file.getvalue()
        csv_file.close()
        # Using excel mode csv, which automatically ends lines with \r\n, so need to convert to \n
        self.assertEqual(csv.replace('\r\n', '\n').strip(), self.CORRECT_CSV.strip())
Exemplo n.º 2
0
    def test_purchased_csv(self):
        """
        Tests that a generated purchase report CSV is as we expect
        """
        # coerce the purchase times to self.test_time so that the test can match.
        # It's pretty hard to patch datetime.datetime b/c it's a python built-in, which is immutable, so we
        # make the times match this way
        for item in OrderItem.purchased_items_btw_dates(
                self.now - self.FIVE_MINS, self.now + self.FIVE_MINS):
            item.fulfilled_time = self.test_time
            item.save()

        # add annotation to the
        csv_file = StringIO.StringIO()
        OrderItem.csv_purchase_report_btw_dates(csv_file,
                                                self.now - self.FIVE_MINS,
                                                self.now + self.FIVE_MINS)
        csv = csv_file.getvalue()
        csv_file.close()
        # Using excel mode csv, which automatically ends lines with \r\n, so need to convert to \n
        self.assertEqual(
            csv.replace('\r\n', '\n').strip(), self.CORRECT_CSV.strip())