123456789101112131415161718192021222324252627282930313233343536373839 |
- from datetime import datetime, timedelta, date
- from django.test import TestCase
- from django.utils import timezone
- from coin.members.models import Member
- from .models import Item, ItemType, Loan
- def localize(naive_dt):
- if not timezone.is_naive(naive_dt):
- raise ValueError('Expecting a naive datetime')
- else:
- return timezone.make_aware(naive_dt, timezone.get_current_timezone())
- class HardwareLoaningTestCase(TestCase):
- def setUp(self):
- self.member = Member.objects.create(
- first_name='John',
- last_name='Doe',
- username='jdoe')
- self.item_type = ItemType.objects.create(name='Foos')
- self.item = Item.objects.create(
- type=self.item_type,
- designation='Bar Wheel',
- buy_date=date(2012,12,5))
- def test_running_(self):
- loan_start_date = localize(datetime(2011,1,14,12,0,0))
- loan = Loan.objects.create(
- item=self.item, user=self.member,
- loan_date=loan_start_date)
- self.assertEqual(Loan.objects.running().count(), 1)
- self.assertEqual(Loan.objects.finished().count(), 0)
- loan.item.give_back()
- self.assertEqual(Loan.objects.running().count(), 0)
- self.assertEqual(Loan.objects.finished().count(), 1)
|