fix bug in tickets search api and add tests
This commit is contained in:
parent
5f0d9b8626
commit
ebb13b2a85
3 changed files with 104 additions and 7 deletions
|
@ -383,15 +383,85 @@ class IssueSearchTest(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.event = Event.objects.create(slug='EVENT', name='Event')
|
||||
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
||||
self.user.user_permissions.add(*Permission.objects.all())
|
||||
self.user.save()
|
||||
self.event = Event.objects.create(slug='EVENT', name='Event')
|
||||
self.box = Container.objects.create(name='box1')
|
||||
self.item = Item.objects.create(container=self.box, description="foo", event=self.event)
|
||||
self.token = AuthToken.objects.create(user=self.user)
|
||||
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
||||
|
||||
def test_search(self):
|
||||
def test_search_empty_result(self):
|
||||
search_query = b64encode(b'abc').decode('utf-8')
|
||||
response = self.client.get(f'/api/2/{self.event.slug}/tickets/{search_query}/')
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual([], response.json())
|
||||
|
||||
def test_search(self):
|
||||
now = datetime.now()
|
||||
issue = IssueThread.objects.create(
|
||||
name="test issue Abc",
|
||||
event=self.event,
|
||||
)
|
||||
mail1 = Email.objects.create(
|
||||
subject='test',
|
||||
body='test aBc',
|
||||
sender='test',
|
||||
recipient='test',
|
||||
issue_thread=issue,
|
||||
timestamp=now,
|
||||
)
|
||||
mail2 = Email.objects.create(
|
||||
subject='test',
|
||||
body='test',
|
||||
sender='test',
|
||||
recipient='test',
|
||||
issue_thread=issue,
|
||||
in_reply_to=mail1.reference,
|
||||
timestamp=now + timedelta(seconds=2),
|
||||
)
|
||||
assignment = Assignment.objects.create(
|
||||
issue_thread=issue,
|
||||
assigned_to=self.user,
|
||||
timestamp=now + timedelta(seconds=3),
|
||||
)
|
||||
comment = Comment.objects.create(
|
||||
issue_thread=issue,
|
||||
comment="test deF",
|
||||
timestamp=now + timedelta(seconds=4),
|
||||
)
|
||||
match = ItemRelation.objects.create(
|
||||
issue_thread=issue,
|
||||
item=self.item,
|
||||
timestamp=now + timedelta(seconds=5),
|
||||
)
|
||||
search_query = b64encode(b'abC').decode('utf-8')
|
||||
response = self.client.get(f'/api/2/{self.event.slug}/tickets/{search_query}/')
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual(1, len(response.json()))
|
||||
self.assertEqual(issue.id, response.json()[0]['id'])
|
||||
score2 = response.json()[0]['search_score']
|
||||
|
||||
search_query = b64encode(b'dEf').decode('utf-8')
|
||||
response = self.client.get(f'/api/2/{self.event.slug}/tickets/{search_query}/')
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual(1, len(response.json()))
|
||||
self.assertEqual(issue.id, response.json()[0]['id'])
|
||||
score1 = response.json()[0]['search_score']
|
||||
|
||||
search_query = b64encode(b'ghi').decode('utf-8')
|
||||
response = self.client.get(f'/api/2/{self.event.slug}/tickets/{search_query}/')
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual(0, len(response.json()))
|
||||
|
||||
search_query = b64encode(b'Abc def').decode('utf-8')
|
||||
response = self.client.get(f'/api/2/{self.event.slug}/tickets/{search_query}/')
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual(1, len(response.json()))
|
||||
self.assertEqual(issue.id, response.json()[0]['id'])
|
||||
score3 = response.json()[0]['search_score']
|
||||
|
||||
self.assertGreater(score3, score2)
|
||||
self.assertGreater(score2, score1)
|
||||
self.assertGreater(score1, 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue