Skip to content

Commit e3758d4

Browse files
committed
more tests
1 parent af99f8a commit e3758d4

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

tests/test_commands.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from django.test import TestCase
2+
from django.core.management import call_command
3+
4+
from django.contrib.algoliasearch import AlgoliaIndex
5+
from django.contrib.algoliasearch import register
6+
from django.contrib.algoliasearch import unregister
7+
8+
try:
9+
from StringIO import StringIO
10+
except:
11+
from io import StringIO
12+
13+
from .models import Example
14+
15+
16+
class CommandsTestCase(TestCase):
17+
def setUp(self):
18+
class ExampleIndex(AlgoliaIndex):
19+
field = 'name'
20+
21+
register(Example, ExampleIndex)
22+
self.output = StringIO()
23+
24+
def tearDown(self):
25+
unregister(Example)
26+
27+
def test_reindex(self):
28+
call_command('algolia_reindex', stdout=self.output)
29+
self.output.seek(0)
30+
result = self.output.readlines()
31+
self.assertEqual(len(result), 2)
32+
33+
regex = r'Example --> \d+'
34+
try:
35+
self.assertRegex(result[1], regex)
36+
except AttributeError:
37+
self.assertRegexpMatches(result[1], regex)
38+
39+
def test_clearindex(self):
40+
call_command('algolia_clearindex', stdout=self.output)
41+
self.output.seek(0)
42+
result = self.output.readlines()
43+
self.assertEqual(len(result), 2)
44+
45+
regex = r'Example'
46+
try:
47+
self.assertRegex(result[1], regex)
48+
except AttributeError:
49+
self.assertRegexpMatches(result[1], regex)
50+
51+
def test_applysettings(self):
52+
call_command('algolia_applysettings', stdout=self.output)
53+
self.output.seek(0)
54+
result = self.output.readlines()
55+
self.assertEqual(len(result), 2)
56+
57+
regex = r'Example'
58+
try:
59+
self.assertRegex(result[1], regex)
60+
except AttributeError:
61+
self.assertRegexpMatches(result[1], regex)

tests/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_default_index_name(self):
2323
regex = r'django(\d+.\d+)?_Example_test'
2424
try:
2525
self.assertRegex(index.index_name, regex)
26-
except:
26+
except AttributeError:
2727
self.assertRegexpMatches(index.index_name, regex)
2828

2929
def test_custom_index_name(self):
@@ -34,7 +34,7 @@ class ExampleIndex(AlgoliaIndex):
3434
regex = r'django(\d+.\d+)?_customName_test'
3535
try:
3636
self.assertRegex(index.index_name, regex)
37-
except:
37+
except AttributeError:
3838
self.assertRegexpMatches(index.index_name, regex)
3939

4040
def test_custom_objectID(self):

0 commit comments

Comments
 (0)