Skip to content

Commit

Permalink
Fixed unaccent test. Added new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Lewinski committed Apr 25, 2022
1 parent 9f5345d commit c0fe18d
Showing 1 changed file with 245 additions and 13 deletions.
258 changes: 245 additions & 13 deletions tests/filters/test_text_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ def test_text_filter_exact_match(self):
result = jsonloads(response.content)
self.assertEqual(0, len(result['data']))


@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_unaccent_chained_qualifier_match(self):
response = self.client.get('/caretaker/', data={'.name:unaccent': 'Śtefan'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
self.assertEqual(0, len(result['data']))

def test_text_filter_iexact(self):
response = self.client.get('/caretaker/', data={'.name:iexact': 'stefan'})

Expand Down Expand Up @@ -226,3 +213,248 @@ def test_text_filter_iendswith(self):
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

# Unaccent extension tests
@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_exact_match_unaccent(self):
response = self.client.get('/caretaker/', data={'.name:unaccent': 'Śtefan'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get('/caretaker/', data={'.name:unaccent': 'Śtefa'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
self.assertEqual(0, len(result['data']))

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_iexact_unaccent(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:iexact': 'stęfan'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:iexact': 'sTĘfaN'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_contains(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:contains': 'stęf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

response = self.client.get(
'/caretaker/', data={'.name:unaccent:contains': 'Stęf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:contains': 'ę'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(2, len(result['data']))

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_icontains(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:icontains': 'stęfi'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

response = self.client.get(
'/caretaker/', data={'.name:unaccent:icontains': 'sTĘf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:icontains': 'Ę'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(2, len(result['data']))

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_startswith(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:startswith': 'tęf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

response = self.client.get(
'/caretaker/', data={'.name:unaccent:startswith': 'Śtęf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:startswith': 'śtę'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_istartswith(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:istartswith': 'tęf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

response = self.client.get(
'/caretaker/', data={'.name:unaccent:istartswith': 'stęf'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:istartswith': 'sTĘF'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_endswith(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:endswith': 'efą'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

response = self.client.get(
'/caretaker/', data={'.name:unaccent:endswith': 'efań'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:endswith': 'efaŃ'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

@unittest.skipIf(
os.environ.get('BINDER_TEST_MYSQL', '0') != '0',
"Only available with PostgreSQL"
)
def test_text_filter_iendswith(self):
response = self.client.get(
'/caretaker/', data={'.name:unaccent:iendswith': 'ęfa'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(0, len(result['data']))

response = self.client.get(
'/caretaker/', data={'.name:unaccent:iendswith': 'EfĄn'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

response = self.client.get(
'/caretaker/', data={'.name:unaccent:iendswith': 'efąN'})

self.assertEqual(response.status_code, 200)

result = jsonloads(response.content)
print(result)
self.assertEqual(1, len(result['data']))
self.assertEqual('Stefan', result['data'][0]['name'])

0 comments on commit c0fe18d

Please sign in to comment.