Files
2012-02-21 01:15:00 -05:00

1 line
2.6 KiB
JSON

[{"user_id": 11405, "stars": [], "topic_id": 14041, "date_created": 1300605263.1323371, "message": "Currently I am doing TDD on a reusable Django app. One test should make sure that my view only returns articles that have a publish-date that is in the past. I am quite new to testing in Django. So far I have learned how to use .json files as fixtures for my test classes. However for this test I do not want to insert publish dates that are 1000 years in the future. After all another species might discover our ancient internet, check out my source and wonder why my test fails :) What other approaches are there solve this problem? Static .json files seem to be a bit hard to maintain as well as the application grows...", "group_id": 81, "id": 391005}, {"user_id": 3965, "stars": [], "topic_id": 14041, "date_created": 1300613740.2899661, "message": "By doing it in code at runtime you can do things like datetime.now() +/- timedelta() to get exact relative dates", "group_id": 81, "id": 391592}, {"user_id": 3965, "stars": [], "topic_id": 14041, "date_created": 1300613703.2989621, "message": "I'm a big fan of setting up the data you need for the tests in a helper method on your TestCase subclass or in the start of your test_ method itself (depending on how common a need for the data is).", "group_id": 81, "id": 391588}, {"user_id": 22991, "stars": [], "topic_id": 14041, "date_created": 1300634472.539309, "message": "The sample chapter from my book has a discussion on this topic, see page 36 in https://www.packtpub.com/sites/default/files/7566_Django%201.1%20Testing%20and%20Debugging_SampleChapter_1.pdf?utm_source=packtpub&utm_medium=free&utm_campaign=pdf", "group_id": 81, "id": 392219}, {"user_id": 11405, "stars": [], "topic_id": 14041, "date_created": 1300635512.567086, "message": "LOL I have that book but never had time look into it... :) Reading your link now...", "group_id": 81, "id": 392251}, {"user_id": 3580, "stars": [], "topic_id": 14041, "date_created": 1300642426.034658, "message": "+1 to setting up the data at runtime. I think static fixtures make a lot sense for certain kinds of tests, but runtime lets you solve problems like this very easily. I also like to get in the habit of not calling things like datetime.now() directly.. If you call a utility method for getting 'now' instead, it's easier to mock time in unit tests.", "group_id": 81, "id": 392877}, {"user_id": 3580, "stars": [], "topic_id": 14041, "date_created": 1300642451.6480341, "message": "can be a leaky abstraction.. but works for doing certain kinds of scheduling tests that would otherwise be painful", "group_id": 81, "id": 392878}]