Skip to content

Commit

Permalink
Added tests for reporting functions
Browse files Browse the repository at this point in the history
Simple tests added to add some coverage to the reporting
functions
  • Loading branch information
AlexRRR committed May 10, 2012
1 parent 904e594 commit 8ad2502
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
42 changes: 30 additions & 12 deletions reports/tests.py
@@ -1,16 +1,34 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
from django.test import TestCase
from django.test.client import Client
from django.core.exceptions import ObjectDoesNotExist
from content.models import SMS
from content.models import Contenido
from content.models import Dynpath
from content.views import keyword_matches
from content.views import create_dynpath
from reports.views import *
from datetime import date,timedelta

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase


class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
class EntryViewTestCase(TestCase):

fixtures = ['reports.json']

def setUp(self):
self.expected_month_first_last_empty=[{'date_created': '2012-03-01', 'created_count': 0}, {'date_created': u'2012-04-01', 'created_count': 2}, {'date_created': u'2012-05-01', 'created_count': 1}, {'date_created': '2012-06-01', 'created_count': 0}, {'date_created': '2012-07-01', 'created_count': 0}]
self.expected_month_first_last_match=[{'date_created': u'2012-04-01', 'created_count': 2}, {'date_created': u'2012-05-01', 'created_count': 1}]
self.expected_date = [{'date_created': '2012-04-22', 'created_count': 0}, {'date_created': u'2012-04-23', 'created_count': 2}, {'date_created': '2012-04-24', 'created_count': 0}, {'date_created': '2012-04-25', 'created_count': 0}, {'date_created': '2012-04-26', 'created_count': 0}, {'date_created': '2012-04-27', 'created_count': 0}, {'date_created': '2012-04-28', 'created_count': 0}, {'date_created': '2012-04-29', 'created_count': 0}, {'date_created': '2012-04-30', 'created_count': 0}, {'date_created': '2012-05-01', 'created_count': 0}, {'date_created': '2012-05-02', 'created_count': 0}, {'date_created': '2012-05-03', 'created_count': 0}, {'date_created': '2012-05-04', 'created_count': 0}, {'date_created': '2012-05-05', 'created_count': 0}, {'date_created': '2012-05-06', 'created_count': 0}, {'date_created': '2012-05-07', 'created_count': 0}, {'date_created': '2012-05-08', 'created_count': 0}, {'date_created': '2012-05-09', 'created_count': 0}, {'date_created': '2012-05-10', 'created_count': 0}, {'date_created': u'2012-05-11', 'created_count': 1}, {'date_created': '2012-05-12', 'created_count': 0}]

def test_report_date_list(self):
self.assertEquals(report_by_month("2012-03-01","2012-07-21"),self.expected_month_first_last_empty)
self.assertEquals(report_by_month("2012-04-01","2012-05-21"),self.expected_month_first_last_match)


def test_report_day_list(self):
self.assertEquals(report_by_date("2012-04-22","2012-05-12"),self.expected_date)




8 changes: 5 additions & 3 deletions reports/views.py
Expand Up @@ -6,10 +6,11 @@
from django.http import HttpResponse
from contman.settings import LOG_FILE
from datetime import datetime,date
from reports.forms import SearchForm
import pdb
# Create your views here.

def show_log(request,rtype):
def show_log(request):
log_data = tail(LOG_FILE)

return render_to_response('log_report.html', {'log_entries':log_data})
Expand Down Expand Up @@ -126,7 +127,6 @@ def report_by_date(start_d,end_d):
start_date = datetime.strptime(start_d,'%Y-%m-%d').date()
end_date = datetime.strptime(end_d,'%Y-%m-%d').date()
query_results = SMS.objects.filter(received__range=[start_date,end_date]).extra({'date_created' : "date(received)"}).values('date_created').annotate(created_count=Count('id'))
pdb.set_trace()
return fill_gaps(query_results,'by_day',start_d, end_d)


Expand All @@ -149,7 +149,9 @@ def report_by_month(start_d,end_d):

query_results = SMS.objects.filter(received__range=[start_date,end_date]).extra(select={'date_created': connections[SMS.objects.db].ops.date_trunc_sql('month', 'received')}).values('date_created').annotate(created_count=Count('received'))
results = remove_time(query_results)
pdb.set_trace()
return fill_gaps(results,'by_month',start_d, end_d)


def search(request):
form = SearchForm()
return render_to_response('sms_report.html', {'form': form})

0 comments on commit 8ad2502

Please sign in to comment.