def test_get_section_title_by_language(self): from catalog.mongomodels import Section mock_objects = self.mocker.mock() section_microdata = { "sections": [ { "id": 514, "data": { "id": 514, "resource_uri": "/api/v1/sections/514/", "titles": { "en": "WHO Publications" } } } ] } mock_objects.find_one({'acronym': 1}, {'sections': {'$elemMatch': {'id': 514}}}) self.mocker.result(section_microdata) self.mocker.replay() Section.objects = mock_objects section = Section.get_section(journal_id=1, section_id=514) section_title = section.titles['en'] self.assertEqual(section_title, 'WHO Publications')
def test_get_section_passing_journal_id_and_section_id(self): from catalog.mongomodels import Section mock_objects = self.mocker.mock() section_microdata = { "sections": [ { "id": 514, "data": { "id": 514, "resource_uri": "/api/v1/sections/514/", "titles": { "en": "WHO Publications" } } } ] } mock_objects.find_one({'id': 1}, {'sections': {'$elemMatch': {'id': 514}}}) self.mocker.result(section_microdata) self.mocker.replay() Section.objects = mock_objects section = Section.get_section(journal_id=1, section_id=514) self.assertIsInstance(section, Section) self.assertEqual(section.resource_uri, '/api/v1/sections/514/')