Test coverage report: auction.utils.generic

# auction.utils.generic: 31 total statements, 81.5% covered

Generated: Mon 2013-04-29 18:13 CST

Source file: /home/slam/workspace/django-auction/auction/utils/generic.py

Stats: 22 executed, 5 missed, 4 excluded, 16 ignored

1. `from auction.models.bidbasket import BidBasket`
2. `from django.contrib.auth.models import AnonymousUser`
3. ``
4. `def get_bidbasket_from_database(request):`
5. `try:`
6. `return BidBasket.objects.filter(user=request.user)[0]`
7. `except Exception, e:`
8. `return False`
9. ``
10. `def get_or_create_bidbasket(request, save=False):`
11. `"""`
12. `Return bidbasket for current visitor.`
13. ``
14. `Requires a logged in user.`
15. ``
16. `If ``save`` is True, bidbasket object will be explicitly saved.`
17. `"""`
18. `bidbasket = None`
19. `if not hasattr(request, '_bidbasket'):`
20. `bidbasket = None`
21. `is_logged_in = request.user and not isinstance(request.user, AnonymousUser)`
22. ``
23. `if is_logged_in:`
24. `bidbasket = get_bidbasket_from_database(request)`
25. `if bidbasket:`
26. `# and save it to the session`
27. `request.session['bidbasket_id'] = bidbasket.pk`
28. `else:`
29. `bidbasket = BidBasket(user=request.user)`
30. ``
31. `if save and not bidbasket.pk:`
32. `bidbasket.save()`
33. `request.session['bidbasket_id'] = bidbasket.pk`
34. ``
35. `setattr(request, '_bidbasket', bidbasket)`
36. ``
37. `bidbasket = getattr(request, '_bidbasket') # There we *must* have a bidbasket`
38. `return bidbasket`
39. ``
40. `def get_current_time():`
41. `import datetime`
42. `try:`
43. `from django.utils.timezone import utc`
44. `now = datetime.datetime.utcnow().replace(tzinfo=utc)`
45. `except ImportError:`
46. `now = datetime.datetime.utcnow()`
47. `return now`