Skip to content

Commit

Permalink
Modified project to allow coverage testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jessamynsmith committed May 12, 2015
1 parent f1ac99c commit 614c264
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[run]
source = libs, bingo, socialjusticebingo
source = libs, quotations, socialjusticebingo
branch = 1
omit = *tests*
*/migrations/*
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ Use development settings:
export DJANGO_SETTINGS_MODULE=socialjusticebingo.settings.development

Set up db:

In psql:
CREATE EXTENSION unaccent;
ALTER FUNCTION unaccent(text) IMMUTABLE;

python manage.py syncdb
python manage.py migrate
Expand Down
24 changes: 3 additions & 21 deletions quotations/models.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
from django.core.urlresolvers import reverse
from django.db import models
from djorm_pgfulltext.fields import VectorField
from djorm_pgfulltext.models import SearchManager


class Author(models.Model):

name = models.CharField(max_length=100, unique=True)
date_of_birth = models.DateField()
date_of_death = models.DateField(null=True, blank=True)

search_index = VectorField()

objects = SearchManager(
fields=('name',),
config='pg_catalog.english',
search_field='search_index',
auto_update_search_field=True
)

def __str__(self):
death_year = ''
if self.date_of_death:
Expand All @@ -27,17 +17,9 @@ def __str__(self):


class Quotation(models.Model):
author = models.ForeignKey(Author, related_name='socialjusticebingo')
text = models.CharField(max_length=500, unique=True)

search_index = VectorField()

objects = SearchManager(
fields=('text',),
config='pg_catalog.english',
search_field='search_index',
auto_update_search_field=True
)
author = models.ForeignKey(Author, related_name='underquoted')
text = models.CharField(max_length=500, unique=True)

def __str__(self):
return "%s - %s" % (self.text, self.author.name)
Expand Down
14 changes: 13 additions & 1 deletion quotations/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_get_queryset_search_multiple_terms_matches_quotation(self):
self.assertEqual('Not I, one said', queryset[0].text)

def test_get_queryset_search_multiple_terms_matches_author(self):
self.view_set.request.GET = QueryDict(u'search=Algernon Faith')
self.view_set.request.GET = QueryDict(u'search=Algernon&search=Faith')

queryset = self.view_set.get_queryset()

Expand Down Expand Up @@ -99,6 +99,18 @@ def test_list_quotations_search(self):
self.assertContains(response, 'page=1', count=0)
self.assertContains(response, 'page=2', count=0)

def test_list_quotations_search_multiple_terms(self):
self.request.GET = QueryDict(u'search_text=algernon faith')

response = views.list_quotations(self.request)

self.assertContains(response, '<title>The Underquoted</title>')
self.assertContains(response, '<div>2b or not 2b</div>', count=0)
self.assertContains(response, '<div>Faithful to one</div>', count=0)
self.assertContains(response, '<div>Not I, one said</div>')
self.assertContains(response, 'page=1', count=0)
self.assertContains(response, 'page=2', count=0)

def test_list_quotations_multiple_pages(self):
settings.MAX_PER_PAGE = 2

Expand Down
17 changes: 6 additions & 11 deletions quotations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
from libs import query_set


def _search_terms(queryset, terms):
for term in terms:
queryset = queryset.search(term)
return queryset


def _search_quotations(search_terms):
quotations = quotation_models.Quotation.objects.all()
if search_terms:
quotation_ids = _search_terms(quotations, search_terms).values_list('id', flat=True)
authors = _search_terms(quotation_models.Author.objects.all(), search_terms)
quotations = quotations.filter(Q(id__in=quotation_ids) | Q(author__in=authors))
quotation_query = Q()
author_query = Q()
for search_term in search_terms:
quotation_query = quotation_query & Q(text__icontains=search_term)
author_query = author_query & Q(author__name__icontains=search_term)
quotations = quotation_models.Quotation.objects.filter(quotation_query | author_query)
return quotations


Expand Down
1 change: 0 additions & 1 deletion requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ django-settings-context-processor==0.2
django-sslify==0.2.7
django-tastypie==0.12.1
djangorestframework==3.1.1
djorm-ext-pgfulltext==0.9.3
mimeparse==0.1.3
psycopg2==2.6
python-dateutil==2.4.2
Expand Down
1 change: 0 additions & 1 deletion socialjusticebingo/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'settings_context_processor',
'djorm_pgfulltext',
'rest_framework',
'tastypie',
'quotations',
Expand Down
4 changes: 2 additions & 2 deletions socialjusticebingo/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'socialjusticebingo',
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'socialjusticebingo.db'),
'USER': '',
'PASSWORD': '',
'HOST': '',
Expand Down

0 comments on commit 614c264

Please sign in to comment.