예제 #1
0
    def test_sum_two(self):
        mock = Transaction()
        mock.amount = Decimal(10)
        mock.description = 'Test'
        mock.user = User.objects.create_user('*****@*****.**')
        mock.save()

        mock2 = Transaction()
        mock2.amount = Decimal(-5)
        mock2.description = 'Test'
        mock2.user = User.objects.create_user('*****@*****.**')
        mock2.save()

        actual = Transaction.objects.total()
        self.assertEqual(actual, to_decimal(5))
예제 #2
0
    def test_sum_two(self):
        mock = Transaction()
        mock.amount = Decimal(10)
        mock.description = 'Test'
        mock.user = User.objects.create_user('*****@*****.**')
        mock.save()

        mock2 = Transaction()
        mock2.amount = Decimal(-5)
        mock2.description = 'Test'
        mock2.user = User.objects.create_user('*****@*****.**')
        mock2.save()

        actual = Transaction.objects.total()
        self.assertEqual(actual, to_decimal(5))
예제 #3
0
 def create_transaction(self, amount = 10, description = "spent dough", user_email="*****@*****.**"):
     transaction = Transaction()
     transaction.amount = Decimal(amount)
     transaction.description = description
     transaction.user = User.objects.create_user(user_email)
     transaction.save()
     return transaction
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
    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)
예제 #9
0
    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)