def test_no_pages(self): """Don't pave over current data if WebTrends returns well-formatted data structure with no interesting data in it.""" # Get some JSON that contains no interesting data. no_pages = '{"data": {"12/01/2010-12/07/2010": {"SubRows": {}}}}' counts = WikiDocumentVisits._visit_counts(no_pages) eq_({}, counts) # Make sure nothing interesting is there. # Try to reload visits table from the uninteresting data: d = document() d.save() v = WikiDocumentVisits.objects.create(document=d, visits=12, period=THIS_WEEK) WikiDocumentVisits.reload_period_from_json(THIS_WEEK, no_pages) # Visits table should remain unchanged: eq_(1, WikiDocumentVisits.objects.filter(pk=v.pk).count())
def reload_wiki_traffic_stats(): transaction.enter_transaction_management() transaction.managed(True) for period, _ in PERIODS: try: WikiDocumentVisits.reload_period_from_json( period, WikiDocumentVisits.json_for(period)) except: transaction.rollback() raise else: transaction.commit() # Nice but not necessary when the process is about to exit: transaction.leave_transaction_management()
def reload_wiki_traffic_stats(): transaction.enter_transaction_management() transaction.managed(True) for period, _ in PERIODS: try: WikiDocumentVisits.reload_period_from_json( period, WikiDocumentVisits.json_for(period)) except: transaction.rollback() raise else: transaction.commit() # Nice but not necessary when the process is about to exit: transaction.leave_transaction_management()
def test_no_pages(self): """Don't pave over current data if WebTrends returns well-formatted data structure with no interesting data in it.""" # Get some JSON that contains no interesting data. no_pages = '{"data": {"12/01/2010-12/07/2010": {"SubRows": {}}}}' counts = WikiDocumentVisits._visit_counts(no_pages) eq_({}, counts) # Make sure nothing interesting is there. # Try to reload visits table from the uninteresting data: d = document() d.save() v = WikiDocumentVisits.objects.create(document=d, visits=12, period=THIS_WEEK) WikiDocumentVisits.reload_period_from_json(THIS_WEEK, no_pages) # Visits table should remain unchanged: eq_(1, WikiDocumentVisits.objects.filter(pk=v.pk).count())