Ejemplo n.º 1
0
    def test_get_issue_passing_journal_id_and_issue_id(self):
        from catalog.mongomodels import Issue
        mock_objects = self.mocker.mock()

        issue_microdata = {
            "issues": [
                {
                    "id": 1,
                    "data": {
                        "cover": None,
                        "created": "2010-04-01T01:01:01",
                        "ctrl_vocabulary": "nd",
                        "editorial_standard": "vancouv",
                        "id": 1,
                        "is_marked_up": False,
                        "is_press_release": False,
                        "is_trashed": False,
                        "label": "45 (4)",
                        "number": "4",
                        "order": 4,
                        "publication_end_month": 12,
                        "publication_start_month": 10,
                        "publication_year": 2009,
                        "resource_uri": "/api/v1/issues/1/",
                        "sections": [
                        {
                          "id": 514,
                          "articles": [
                            "AISS-JHjashA",
                          ]
                        }
                        ],
                        "suppl_number": None,
                        "suppl_volume": None,
                        "total_documents": 17,
                        "updated": "2012-11-08T10:35:37.193612",
                        "volume": "45"
                    }
                }
            ]
        }

        mock_objects.find_one({'acronym': 'foo'}, {'issues': {'$elemMatch': {'id': 1}}})
        self.mocker.result(issue_microdata)

        self.mocker.replay()

        Issue.objects = mock_objects

        issue = Issue.get_issue(journal_id='foo', issue_id=1)

        self.assertIsInstance(issue, Issue)
        self.assertEqual(issue.total_documents, 17)
        self.assertEqual(issue.id, 1)
Ejemplo n.º 2
0
    def test_list_sections_from_issue_must_return_a_lazy_object(self):
        from catalog.mongomodels import Issue
        from catalog.mongomodels import Section
        from catalog.mongomodels import Article

        issue_mock_objects = self.mocker.mock()
        section_mock_objects = self.mocker.mock()
        article_mock_objects = self.mocker.mock()

        issue_section_microdata = {
            "acronym": "foo",
            "issues": [
                {
                    "id": 1,
                    "data": {
                        "cover": None,
                        "created": "2010-04-01T01:01:01",
                        "ctrl_vocabulary": "nd",
                        "editorial_standard": "vancouv",
                        "id": 1,
                        "is_marked_up": False,
                        "is_press_release": False,
                        "is_trashed": False,
                        "label": "45 (4)",
                        "number": "4",
                        "order": 4,
                        "publication_end_month": 12,
                        "publication_start_month": 10,
                        "publication_year": 2009,
                        "resource_uri": "/api/v1/issues/1/",
                        "sections": [
                        {
                          "id": 514,
                          "articles": [
                            "AISS-JHjashA",
                          ]
                        }
                        ],
                        "suppl_number": None,
                        "suppl_volume": None,
                        "total_documents": 17,
                        "updated": "2012-11-08T10:35:37.193612",
                        "volume": "45"
                    }
                }
            ],
            "sections": [
              {
                "id": 514,
                "data": {
                    "id": 514,
                    "resource_uri": "/api/v1/sections/514/",
                    "titles": [
                      {"en": "WHO Publications"}
                    ]
                }
              }
            ]
        }

        section_microdata = {
            "sections": [
                {
                  "id": 514,
                  "data": {
                      "id": 514,
                      "resource_uri": "/api/v1/sections/514/",
                      "titles": {
                        "en": "WHO Publications"
                      }
                  }
                }
            ]
        }

        article_microdata = {
            'id': 'AISS-JHjashA',
            'title': 'Micronucleated lymphocytes in parents of lalala children'
        }

        issue_mock_objects.find_one({'acronym': 'foo'}, {'issues': {'$elemMatch': {'id': 1}}})
        self.mocker.result(issue_section_microdata)

        section_mock_objects.find_one({'acronym': 'foo'}, {'sections': {'$elemMatch': {'id': 514}}})
        self.mocker.result(section_microdata)

        article_mock_objects.find_one({'id': 'AISS-JHjashA'})
        self.mocker.result(article_microdata)

        self.mocker.replay()

        Issue.objects = issue_mock_objects
        Section.objects = section_mock_objects
        Article.objects = article_mock_objects

        issue = Issue.get_issue(journal_id='foo', issue_id=1)

        sections = issue.list_sections()

        self.assertTrue(hasattr(sections, 'next'))
        section = sections.next()
        self.assertEqual(section.id, 514)
        self.assertIsInstance(section.articles, list)
        self.assertIsInstance(section.articles[0], Article)
    def test_list_articles_by_section(self):
        from catalog.templatetags import catalogtags
        from catalog.mongomodels import Issue
        from catalog.mongomodels import Section
        from catalog.mongomodels import Article

        issue_mock_objects = self.mocker.mock()
        section_mock_objects = self.mocker.mock()
        article_mock_objects = self.mocker.mock()

        issue_section_microdata = {
            "issues": [
                {
                    "id": 1,
                    "data": {
                        "cover": None,
                        "created": "2010-04-01T01:01:01",
                        "ctrl_vocabulary": "nd",
                        "editorial_standard": "vancouv",
                        "id": 1,
                        "is_marked_up": False,
                        "is_press_release": False,
                        "is_trashed": False,
                        "label": "45 (4)",
                        "number": "4",
                        "order": 4,
                        "publication_end_month": 12,
                        "publication_start_month": 10,
                        "publication_year": 2009,
                        "resource_uri": "/api/v1/issues/1/",
                        "sections": [
                        {
                          "id": 514,
                          "articles": [
                            "AISS-JHjashA",
                          ]
                        }
                        ],
                        "suppl_number": None,
                        "suppl_volume": None,
                        "total_documents": 17,
                        "updated": "2012-11-08T10:35:37.193612",
                        "volume": "45"
                    }
                }
            ],
            "sections": [
              {
                "id": 514,
                "data": {
                    "id": 514,
                    "resource_uri": "/api/v1/sections/514/",
                    "titles": [
                      {"en": "WHO Publications"}
                    ]
                }
              }
            ]
        }

        section_microdata = {
            "sections": [
                {
                  "id": 514,
                  "data": {
                      "id": 514,
                      "resource_uri": "/api/v1/sections/514/",
                      "titles": {
                        "en": "WHO Publications"
                      }
                  }
                }
            ]
        }

        article_microdata = {
            'id': 'AISS-JHjashA',
            'abstract': {
                'en': "<p>Trout farming, that represents the most important sector for aquaculture inland production in Italy, ...",
                'it': "<p>La troticoltura rappresenta il settore più importante per la produzione ittica in Italia ed è in grado ..."
              },
            'title': 'Micronucleated lymphocytes in parents of lalala children',
            'title_group': {
                'en': 'Management of health-care waste in Izmir, Turkey',
            'it': 'Gestione dei rifiuti sanitari in Izmir, Turchia'
            },
            'default_language': 'en',
            'contrib_group': {
                'author': [
                    {
                        'role': 'ND',
                        'given_names': 'Ahmet',
                        'surname': 'Soysal',
                        'affiliations': [
                        'A01'
                        ]
                    }]
            },
        }

        issue_mock_objects.find_one({'acronym': 1}, {'issues': {'$elemMatch': {'id': 1}}})
        self.mocker.result(issue_section_microdata)

        section_mock_objects.find_one({'acronym': 1}, {'sections': {'$elemMatch': {'id': 514}}})
        self.mocker.result(section_microdata)

        article_mock_objects.find_one({'id': 'AISS-JHjashA'})
        self.mocker.result(article_microdata)

        self.mocker.replay()

        Issue.objects = issue_mock_objects
        Section.objects = section_mock_objects
        Article.objects = article_mock_objects

        issue = Issue.get_issue(journal_id=1, issue_id=1)

        sections = issue.list_sections()

        self.assertEqual(catalogtags.list_articles_by_section(sections, 'en'), u'<dl class="issue_toc"><dt><i class="icon-chevron-right"></i> WHO Publications</dt><dd><ul class="unstyled toc_article"><li>Management of health-care waste in Izmir, Turkey<ul class="inline toc_article_authors"><li><a href="#">Soysal, Ahmet</a>;</li></ul><ul class="inline toc_article_links"><li>abstract: <a href="#">en</a> | <a href="#">it</a></li><li>full text: <a href="/article/AISS-JHjashA/">en</a></li><li>pdf: <a href="#">en</a></li></ul></li></dd></dl>')