def test_autosearch(self): record = self.records[0] create_db_entries(record) response = self.client.get('/autosearch/?q=implementation') self.assertContains(response, 'Implementation', count=1) self.assertTemplateNotUsed(response, 'pubmed_search/article_list.html') self.assertTemplateNotUsed(response, 'pubmed_search/article_detail.html') self.assertTemplateNotUsed(response, 'pubmed_search/search.html')
def test_search(self): record = self.records[0] create_db_entries(record) response = self.client.post('/', {'q': 'implementation'}) self.assertTemplateUsed(response, 'pubmed_search/search.html') self.assertContains(response, 'Implementation', count=1) self.assertEqual(1, len(response.context['articles'])) self.assertEqual('implementation', response.context['query_terms'][0]) self.assertEqual(1, response.context['total_documents'])
def test_tfidf(self): record = self.records[0] create_db_entries(record) articles = Article.objects.all() article = articles[0] implementation = Term.objects.get(term='implementation') idf = math.log(1.0/2.0) self.assertEqual(idf, tfidf(implementation, article))
def test_create_db_entries(self): record = self.records[0] create_db_entries(record) articles = Article.objects.all() self.assertEqual(1, articles.count()) article = articles[0] self.assertEqual(record['title'], article.title) self.assertEqual(record['abstract'], article.abstract) self.assertEqual(record['pubmedUrl'], article.pubmed_url) authors = article.authors.all() for author in authors: name = author.__unicode__() self.assertIn(name, record["authors"])
def test_create_term_frequencies(self): record = self.records[0] create_db_entries(record) implementation = Term.objects.get(term='implementation') impl_freq = Frequency.objects.get(term=implementation) self.assertEqual(1, impl_freq.frequency)