def test_get_invalid_id(self): dss = self.mox.CreateMockAnything() dss.find_similar('foo', max_results=10, min_score=0.8).AndRaise(ValueError) views.dss().AndReturn(dss) self.mox.ReplayAll() response = self.client.get( reverse('find-similar'), {'id': 'foo'}) self.mox.VerifyAll() self.assertEqual(response.status_code, 400)
def test_get_invalid_id(self): dss = self.mox.CreateMockAnything() dss.find_similar('foo', max_results=10, min_score=0.8).AndRaise(ValueError) views.dss().AndReturn(dss) self.mox.ReplayAll() response = self.client.get(reverse('find-similar'), {'id': 'foo'}) self.mox.VerifyAll() self.assertEqual(response.status_code, 400)
def test_index(self): self.mox.StubOutWithMock(views, 'dss') dss = self.mox.CreateMockAnything() dss.server = self.mox.CreateMockAnything() dss.server.index([{'tokens': ['test'], 'id': 'test_document:4'}]) views.dss().AndReturn(dss) self.mox.ReplayAll() post = {'id': 'test_document:4', 'text': 'test', 'index': True} self.assertFalse(Document.objects.exists()) response = self.client.post(reverse('add_or_update'), post) self.mox.VerifyAll() self.assertEqual(response.status_code, 202) doc = Document.objects.get() self.assertEqual(doc.id, str(post['id'])) self.assertEqual(doc.text, post['text'])
def test_index(self): self.mox.StubOutWithMock(views, 'dss') dss = self.mox.CreateMockAnything() dss.server = self.mox.CreateMockAnything() dss.server.index( [{'tokens': ['test'], 'id': 'test_document:4'}]) views.dss().AndReturn(dss) self.mox.ReplayAll() post = {'id': 'test_document:4', 'text': 'test', 'index': True} self.assertFalse(Document.objects.exists()) response = self.client.post(reverse('add_or_update'), post) self.mox.VerifyAll() self.assertEqual(response.status_code, 202) doc = Document.objects.get() self.assertEqual(doc.id, str(post['id'])) self.assertEqual(doc.text, post['text'])
def test_text(self): dss = self.mox.CreateMockAnything() views.dss().AndReturn(dss) dss.find_similar( {'tokens': ['test']}, max_results=10, min_score=0.8).AndReturn( [("test_document:1", 0.8776240944862366, None), ("test_document:2", 0.8762409448623661, None), ("test_document:3", 0.7762409448623668, None)]) self.mox.ReplayAll() response = self.client.post(reverse('find-similar'), {'text': 'test'}) self.mox.VerifyAll() self.assertEqual( response.content, '[["test_document:1",0.87762,null],' '["test_document:2",0.87624,null],' '["test_document:3",0.77624,null]]')
def test_text(self): dss = self.mox.CreateMockAnything() views.dss().AndReturn(dss) dss.find_similar({ 'tokens': ['test'] }, max_results=10, min_score=0.8).AndReturn([ ("test_document:1", 0.8776240944862366, None), ("test_document:2", 0.8762409448623661, None), ("test_document:3", 0.7762409448623668, None) ]) self.mox.ReplayAll() response = self.client.post(reverse('find-similar'), {'text': 'test'}) self.mox.VerifyAll() self.assertEqual( response.content, '[["test_document:1",0.87762,null],' '["test_document:2",0.87624,null],' '["test_document:3",0.77624,null]]')