-
Notifications
You must be signed in to change notification settings - Fork 84
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
@@ -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", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: