Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Travis-CI to repo + Update tox to run tests #56

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: python
# command to install dependencies
install: "pip install tox"
# command to run tests
script: tox -r
env:
- TOXENV=flake8
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34
addons:
postgresql: "9.3"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version bump to latest version of postgres:

postgresql: "9.4"

4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
djorm-ext-pgfulltext
====================

.. image:: https://travis-ci.org/linuxlewis/djorm-ext-pgfulltext.svg

Pgfulltext module of django orm extensions package (collection of third party plugins build in one unified package).

- Now compatible with python2 and python3 with same code base.
- Ready for django 1.3, 1.4, 1.5 and 1.6
- Ready for django 1.3, 1.4, 1.5, 1.6, 1.7, 1.8


Introduction
Expand Down
162 changes: 0 additions & 162 deletions djorm_pgfulltext/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,162 +0,0 @@
# -*- coding: utf-8 -*-

import django
from django.db import connection
from django.db import transaction
from django.utils import unittest
from django.utils.unittest import TestCase

from .models import Book
from .models import Person
from .models import Person2
from .models import Person3


class FtsSetUpMixin:
def setUp(self):
Person.objects.all().delete()

self.p1 = Person.objects.create(
name=u'Andréi',
description=u"Python programmer",
)
self.p2 = Person.objects.create(
name=u'Pèpâ',
description=u"Is a housewife",
)


class TestFts(FtsSetUpMixin, TestCase):
def test_self_update_index(self):
obj = Person2.objects.create(
name=u'Pepa',
description=u"Is a housewife",
)
obj.update_search_field(using='default')

qs = Person2.objects.search(query="Pepa")
self.assertEqual(qs.count(), 1)

def test_self_automatic_update_index(self):
obj = Person3(
name=u'Pèpâ',
description=u"Is a housewife",
)

obj.save()

qs = Person3.objects.search(query="Pepa")
self.assertEqual(qs.count(), 1)

obj.name = 'Andrei'
obj.save()

qs = Person3.objects.search(query="Pepa")
self.assertEqual(qs.count(), 0)

def test_search_and(self):
qs1 = Person.objects.search(query="programmer", raw=True)
qs2 = Person.objects.search(query="Andrei", raw=True)

self.assertEqual(qs1.count(), 1)
self.assertEqual(qs2.count(), 1)

def test_search_and_2(self):
qs1 = Person.objects.search(query="Andrei & programmer", raw=True)
qs2 = Person.objects.search(query="Pepa & housewife", raw=True)
qs3 = Person.objects.search(query="Pepa & programmer", raw=True)

self.assertEqual(qs1.count(), 1)
self.assertEqual(qs2.count(), 1)
self.assertEqual(qs3.count(), 0)

def test_search_with_fields_params(self):
qs1 = Person.objects.search(query="Andrei & programmer", raw=True, fields=['name'])
qs2 = Person.objects.search(query="Andrei & programmer", raw=True, fields=['name', 'description'])

self.assertEqual(qs1.count(), 0)
self.assertEqual(qs2.count(), 1)

def test_search_or(self):
qs1 = Person.objects.search(query="Andrei | Pepa", raw=True)
qs2 = Person.objects.search(query="Andrei | Pepo", raw=True)
qs3 = Person.objects.search(query="Pèpâ | Andrei", raw=True)
qs4 = Person.objects.search(query="Pepo | Francisco", raw=True)

self.assertEqual(qs1.count(), 2)
self.assertEqual(qs2.count(), 1)
self.assertEqual(qs3.count(), 2)
self.assertEqual(qs4.count(), 0)

def test_update_indexes(self):
self.p1.name = 'Francisco'
self.p1.save()

qs = Person.objects.search(query="Pepo | Francisco", raw=True)
self.assertEqual(qs.count(), 1)

def test_transaction_test(self):
if not hasattr(transaction, "atomic"):
return

with transaction.atomic():
obj = Person2.objects.create(
name=u'Pepa',
description=u"Is a housewife",
)

obj.update_search_field(using='default')

qs = Person2.objects.search(query="Pepa")
self.assertEqual(qs.count(), 2)

def test_ranking_with_join(self):
book = Book.objects.create(name='Learning Python', author=self.p1)

qs = Book.objects.search(query='Learning Python', rank_field='rank').select_related('author')

self.assertEqual(qs[0].author, self.p1)

def test_headline(self):
book = Book.objects.create(name='Learning Python', author=self.p1)

qs = Book.objects.search(query='Python', headline_field='headline', headline_document='name')

self.assertEqual(qs[0].headline, 'Learning <b>Python</b>')


class TestFullTextLookups(FtsSetUpMixin, TestCase):

def skipUnlessDjango17(self):
if django.VERSION[:2] < (1, 7):
self.skipTest("Requires Django>=1.7")

def setUp(self):
self.skipUnlessDjango17()
super(TestFullTextLookups, self).setUp()

def test_full_text_lookups(self):
self.assertEquals(
self.p1.pk,
Person.objects.filter(search_index__ft_startswith='programmer')[0].pk)

def test_user_input(self):
for test_str in ["())(#*&|||)()( )( ) )( )(|| | | |&",
"test test", "test !test", "test & test",
"test | test", "test (test)", "test(",
"test &&&& test", "\\'test"]:
list(Person.objects.filter(search_index__ft_startswith=test_str))

@unittest.skip("Needs some love. Raises UnicodeEncodeError.")
def test_user_input_utf8(self):
for test_str in ["łódź"]:
list(Person.objects.filter(search_index__ft_startswith=test_str))

def test_alternative_config(self):
from djorm_pgfulltext.fields import TSConfig

p = Person.objects.filter(
search_index__ft_startswith=[
TSConfig('names'), 'progra'])[0]

self.assertEquals(p.pk, self.p1.pk)
162 changes: 162 additions & 0 deletions djorm_pgfulltext/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*-

import django
from django.db import connection
from django.db import transaction
from django.utils import unittest
from django.utils.unittest import TestCase

from .models import Book
from .models import Person
from .models import Person2
from .models import Person3


class FtsSetUpMixin:
def setUp(self):
Person.objects.all().delete()

self.p1 = Person.objects.create(
name=u'Andréi',
description=u"Python programmer",
)
self.p2 = Person.objects.create(
name=u'Pèpâ',
description=u"Is a housewife",
)


class TestFts(FtsSetUpMixin, TestCase):
def test_self_update_index(self):
obj = Person2.objects.create(
name=u'Pepa',
description=u"Is a housewife",
)
obj.update_search_field(using='default')

qs = Person2.objects.search(query="Pepa")
self.assertEqual(qs.count(), 1)

def test_self_automatic_update_index(self):
obj = Person3(
name=u'Pèpâ',
description=u"Is a housewife",
)

obj.save()

qs = Person3.objects.search(query="Pepa")
self.assertEqual(qs.count(), 1)

obj.name = 'Andrei'
obj.save()

qs = Person3.objects.search(query="Pepa")
self.assertEqual(qs.count(), 0)

def test_search_and(self):
qs1 = Person.objects.search(query="programmer", raw=True)
qs2 = Person.objects.search(query="Andrei", raw=True)

self.assertEqual(qs1.count(), 1)
self.assertEqual(qs2.count(), 1)

def test_search_and_2(self):
qs1 = Person.objects.search(query="Andrei & programmer", raw=True)
qs2 = Person.objects.search(query="Pepa & housewife", raw=True)
qs3 = Person.objects.search(query="Pepa & programmer", raw=True)

self.assertEqual(qs1.count(), 1)
self.assertEqual(qs2.count(), 1)
self.assertEqual(qs3.count(), 0)

def test_search_with_fields_params(self):
qs1 = Person.objects.search(query="Andrei & programmer", raw=True, fields=['name'])
qs2 = Person.objects.search(query="Andrei & programmer", raw=True, fields=['name', 'description'])

self.assertEqual(qs1.count(), 0)
self.assertEqual(qs2.count(), 1)

def test_search_or(self):
qs1 = Person.objects.search(query="Andrei | Pepa", raw=True)
qs2 = Person.objects.search(query="Andrei | Pepo", raw=True)
qs3 = Person.objects.search(query="Pèpâ | Andrei", raw=True)
qs4 = Person.objects.search(query="Pepo | Francisco", raw=True)

self.assertEqual(qs1.count(), 2)
self.assertEqual(qs2.count(), 1)
self.assertEqual(qs3.count(), 2)
self.assertEqual(qs4.count(), 0)

def test_update_indexes(self):
self.p1.name = 'Francisco'
self.p1.save()

qs = Person.objects.search(query="Pepo | Francisco", raw=True)
self.assertEqual(qs.count(), 1)

def test_transaction_test(self):
if not hasattr(transaction, "atomic"):
return

with transaction.atomic():
obj = Person2.objects.create(
name=u'Pepa',
description=u"Is a housewife",
)

obj.update_search_field(using='default')

qs = Person2.objects.search(query="Pepa")
self.assertEqual(qs.count(), 2)

def test_ranking_with_join(self):
book = Book.objects.create(name='Learning Python', author=self.p1)

qs = Book.objects.search(query='Learning Python', rank_field='rank').select_related('author')

self.assertEqual(qs[0].author, self.p1)

def test_headline(self):
book = Book.objects.create(name='Learning Python', author=self.p1)

qs = Book.objects.search(query='Python', headline_field='headline', headline_document='name')

self.assertEqual(qs[0].headline, 'Learning <b>Python</b>')


class TestFullTextLookups(FtsSetUpMixin, TestCase):

def skipUnlessDjango17(self):
if django.VERSION[:2] < (1, 7):
self.skipTest("Requires Django>=1.7")

def setUp(self):
self.skipUnlessDjango17()
super(TestFullTextLookups, self).setUp()

def test_full_text_lookups(self):
self.assertEquals(
self.p1.pk,
Person.objects.filter(search_index__ft_startswith='programmer')[0].pk)

def test_user_input(self):
for test_str in ["())(#*&|||)()( )( ) )( )(|| | | |&",
"test test", "test !test", "test & test",
"test | test", "test (test)", "test(",
"test &&&& test", "\\'test"]:
list(Person.objects.filter(search_index__ft_startswith=test_str))

@unittest.skip("Needs some love. Raises UnicodeEncodeError.")
def test_user_input_utf8(self):
for test_str in ["łódź"]:
list(Person.objects.filter(search_index__ft_startswith=test_str))

def test_alternative_config(self):
from djorm_pgfulltext.fields import TSConfig

p = Person.objects.filter(
search_index__ft_startswith=[
TSConfig('names'), 'progra'])[0]

self.assertEquals(p.pk, self.p1.pk)
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = djorm-ext-pgfulltext
version = 0.9.3
version = 0.9.4
author = Lovely Team
author-email = [email protected]
summary = PostgreSQL Full Text Search integration with django orm.
Expand All @@ -18,8 +18,6 @@ classifier =
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Software Development :: Libraries",
Expand Down
7 changes: 6 additions & 1 deletion testing/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import django


sys.path.insert(0, '..')
Expand Down Expand Up @@ -30,4 +31,8 @@
'djorm_pgfulltext.tests',
)

TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'

if django.VERSION[:2] >= (1, 5):
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
else:
TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
Loading