def create_transaction(self, amount=10, timestamp=timezone.now(), description="spent dough", user=None): if not user: user = self.create_user() transaction = Transaction() transaction.amount = Decimal(amount) transaction.description = description transaction.user = user transaction.timestamp = timestamp transaction.save() return transaction
def test_date_filter(self): mock = Transaction() mock.amount = Decimal(10) mock.description = 'Date Test' mock.user = User.objects.create_user('*****@*****.**') mock.user.activate_timezone() mock.timestamp = datetime.datetime(2014, 1, 1, 8, 15, 2, 0, timezone.get_current_timezone()) mock.save() filter_date = datetime.datetime.combine(datetime.datetime(2014, 1, 1), datetime.time.max) actual = Transaction.objects.date(filter_date).first() self.assertEqual(actual.description, 'Date Test') filter_date = datetime.datetime(2014, 1, 2, 8, 15, 2, 0, timezone.get_current_timezone()) actual = Transaction.objects.date(filter_date).exists() self.assertFalse(actual)
def test_date_range_filter(self): mock = Transaction() mock.amount = Decimal(10) mock.description = 'Date Range Test' mock.user = User.objects.create_user('*****@*****.**') mock.user.activate_timezone() mock.timestamp = datetime.datetime(2014, 1, 1, 8, 15, 2, 0, timezone.get_current_timezone()) mock.save() start = datetime.datetime(2013, 12, 31, 5, 5, 5, 5, timezone.get_current_timezone()) end = datetime.datetime(2014, 1, 1, 0, 0, 0, 0, timezone.get_current_timezone()) actual = Transaction.objects.date_range(start, end).first() self.assertEqual(actual.description, 'Date Range Test') end = datetime.datetime(2013, 12, 31, 12, 12, 12, 12, timezone.get_current_timezone()) actual = Transaction.objects.date_range(start, end).exists() self.assertFalse(actual)