def test_relationship_data2(self): "we expect to see the article snippet of the relationed article and external citations" create_relationships = [ (self.msid1, [self.msid2]), # 1 => 2 ] relation_logic._relate_using_msids(create_relationships) av1 = self.av av2 = models.ArticleVersion.objects.get( article__manuscript_id=self.msid2) external_relation = { 'type': 'external-article', 'articleTitle': u'Tumour micro-environment elicits innate resistance to RAF inhibitors through HGF secretion', 'journal': 'Nature', 'authorLine': '- R Straussman\n- T Morikawa\n- K Shee\n- M Barzily-Rokni\n- ZR Qian\n- J Du\n- A Davis\n- MM Mongare\n- J Gould\n- DT Frederick\n- ZA Cooper\n- PB Chapman\n- DB Solit\n- A Ribas\n- RS Lo\n- KT Flaherty\n- S Ogino\n- JA Wargo\n- TR Golub', 'uri': 'https://doi.org/10.1038/nature11183', } relation_logic.relate_using_citation_list(av1, [external_relation]) relation_logic.relate_using_citation_list(av2, [external_relation]) # forwards expected = [external_relation, logic.article_snippet_json(av2)] self.assertEqual(expected, logic.relationships(self.msid1)) # backwards expected = [external_relation, logic.article_snippet_json(av1)] self.assertEqual(expected, logic.relationships(self.msid2))
def test_relations_found_for_article(self): create_relationships = [ (self.msid1, [self.msid2]), # 1 => 2 (self.msid2, [self.msid3]), # 2 => 3 (self.msid3, [self.msid1]), # 3 => 1 ] relation_logic._relate_using_msids(create_relationships) expected_relationships = [ (self.msid1, [self.msid2, self.msid3]), # 1 => [2, 3] (self.msid2, [self.msid3, self.msid1]), # 2 => [3, 1] (self.msid3, [self.msid1, self.msid2]), # 3 => [1, 2] ] relation_logic._print_relations() for msid, expected_relations in expected_relationships: av = models.Article.objects.get(manuscript_id=msid).latest_version actual_relationships = relation_logic.internal_relationships_for_article_version( av) self.assertCountEqual( expected_relations, [r.manuscript_id for r in actual_relationships], "for %r I expected relations to %r" % (msid, expected_relations))
def test_relationship_data(self): "we expect to see the article snippet of the related article" create_relationships = [ (self.msid1, [self.msid2]), # 1 => 2 ] relation_logic._relate_using_msids(create_relationships) av1 = self.av av2 = models.ArticleVersion.objects.get( article__manuscript_id=self.msid2) # forwards self.assertEqual([logic.article_snippet_json(av2)], logic.relationships(self.msid1)) # backwards self.assertEqual([logic.article_snippet_json(av1)], logic.relationships(self.msid2))
def test_related_article_with_stub_article(self): # create a relationship between 1 and 2 relation_logic._relate_using_msids([(self.msid1, [self.msid2])]) # delete all ArticleVersions leaving just an Article (stub) models.ArticleVersion.objects.filter( article__manuscript_id=self.msid2).delete() # no auth expected = [] # empty response resp = self.c.get( reverse('v2:article-relations', kwargs={'id': self.msid1})) data = utils.json_loads(resp.content) self.assertEqual(data, expected) # auth expected = [] # also an empty response (nothing to serve up) resp = self.ac.get( reverse('v2:article-relations', kwargs={'id': self.msid1})) data = utils.json_loads(resp.content) self.assertEqual(data, expected)
def test_relation_data(self): "we expect to see the article object of the related article" create_relationships = [ (self.msid1, [self.msid2]), # 1 => 2 ] relation_logic._relate_using_msids(create_relationships) av1 = self.av av2 = models.ArticleVersion.objects.get( article__manuscript_id=self.msid2) a1 = self.av.article a2 = models.Article.objects.get(manuscript_id=self.msid2) # forwards self.assertEqual( [a2], relation_logic.internal_relationships_for_article_version(av1)) # backwards self.assertEqual( [a1], relation_logic.internal_relationships_for_article_version(av2))
def test_related_article_with_unpublished_article(self): # create a relationship between 1 and 2 relation_logic._relate_using_msids([(self.msid1, [self.msid2])]) # unpublish v2 self.unpublish(self.msid2) # no auth expected = [] # empty response resp = self.c.get( reverse('v2:article-relations', kwargs={'id': self.msid1})) data = utils.json_loads(resp.content) self.assertEqual(data, expected) # auth expected = [ logic.article_snippet_json( logic.most_recent_article_version(self.msid2, only_published=False)) ] resp = self.ac.get( reverse('v2:article-relations', kwargs={'id': self.msid1})) data = utils.json_loads(resp.content) self.assertEqual(data, expected)
def test_relations_found_for_article2(self): "no duplicates should exist when reverse relationships are made explicit" create_relationships = [ (self.msid1, [self.msid2, self.msid3]), # 1 => 2, 3 (self.msid2, [self.msid3, self.msid1]), # 2 => 3, 1 (self.msid3, [self.msid1, self.msid2]), # 3 => 1, 2 ] relation_logic._relate_using_msids(create_relationships) expected_relationships = [ (self.msid1, [self.msid2, self.msid3]), # 1 => [2, 3] (self.msid2, [self.msid3, self.msid1]), # 2 => [3, 1] (self.msid3, [self.msid1, self.msid2]), # 3 => [1, 2] ] for msid, expected_relations in expected_relationships: av = models.Article.objects.get(manuscript_id=msid).latest_version actual_relationships = relation_logic.internal_relationships_for_article_version( av) self.assertCountEqual( expected_relations, [r.manuscript_id for r in actual_relationships], "for %r I expected relations to %r" % (msid, expected_relations))