Search code examples
pythondjangodjango-testing

django test / python syntax


I'm new Django and also to modern web-development . i had a doubt the testing of app. The confusion may be because of my less python knowledge . I was a Java programmer so i got a doubt with the code below. Here's my code:

def test_was_published_recently_with_old_poll(self):
    """
    was_published_recently() should return False for polls whose pub_date
    is older than 1 day
    """
    old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
    self.assertEqual(old_poll.was_published_recently(), False)

This my code in test.py of my app. What's actually happening at Poll(pub_date=timezone.now() - datetime.timedelta(days=30))... My question is (Poll is a class defined in models.py) what's actually happening here? Can anyone please explain in details ?

Thanks in advance.


Solution

  • At '$' Poll(pub_date=timezone.now() - datetime.timedelta(days=30)) you create a class with field pub_date set to timezone.now() - datetime.timedelta(days=30).

    For example, now is 2012-07-31 11:19:42.897000+00:00. The Poll constructor will create class with pub_date set to 2012-07-01 11:19:42.897000+00:00