Ejemplo n.º 1
0
    def test_tweets_invalid_user(self):
        from .modelfactories import JournalFactory
        from catalog import mongomodels
        from twitter import TwitterError

        mock_twitter = self.mocker.mock()

        twitter_user = {
            "twitter_user": "******"
            }

        mock_twitter.GetUserTimeline(ANY, page=0, count=3)
        self.mocker.throw(TwitterError)

        self.mocker.replay()

        # Testing valid twitter user
        journal = JournalFactory.build(**twitter_user)

        # monkeypatch a class attribute
        mongomodels.Journal._twitter_api = mock_twitter

        # Testing invalid twitter user
        tweets = journal.tweets

        self.assertEqual(tweets, [])
Ejemplo n.º 2
0
    def test_address(self):
        from .modelfactories import JournalFactory

        journal = JournalFactory.build()
        address = journal.address

        self.assertEqual(address, "Viale Regina Elena 299, Rome, Rome, Italy")
Ejemplo n.º 3
0
    def test_tweets_valid_user(self):
        from .modelfactories import JournalFactory
        from catalog import mongomodels

        mock_twitter = self.mocker.mock()
        mock_tweet = self.mocker.mock()

        twitter_user = {
            "twitter_user": "******"
            }

        mock_twitter.GetUserTimeline(ANY, page=0, count=3)
        self.mocker.result([mock_tweet])

        mock_tweet.text
        self.mocker.result(u'Novo peri\xf3dico na Cole\xe7\xe3o SciELO Brasil!')

        mock_tweet.created_at
        self.mocker.result(u'Mon Feb 04 13:41:19 +0000 2013')

        self.mocker.replay()

        # Testing valid twitter user
        journal = JournalFactory.build(**twitter_user)

        # monkeypatch a class attribute
        mongomodels.Journal._twitter_api = mock_twitter

        tweets = journal.tweets

        self.assertEqual(tweets[0]['text'],
                        u'Novo peri\xf3dico na Cole\xe7\xe3o SciELO Brasil!')
        self.assertEqual(tweets[0]['created_at'],
                        u'Mon Feb 04 13:41:19 +0000 2013')
Ejemplo n.º 4
0
    def test_empty_latter_journal(self):
        from .modelfactories import JournalFactory

        journal = JournalFactory.build()

        journal = journal.latter_journal

        self.assertIsNone(journal)
Ejemplo n.º 5
0
    def test_history_without_status(self):
        from .modelfactories import JournalFactory

        pub_status_history_data = {
            'pub_status_history': []}

        journal = JournalFactory.build(**pub_status_history_data)
        history = journal.history

        self.assertEqual(history, [])
Ejemplo n.º 6
0
    def test_last_date_history_without_status(self):
        from .modelfactories import JournalFactory

        pub_status_history_data = {
            'pub_status_history': []}

        journal = JournalFactory.build(**pub_status_history_data)
        last_date = journal.last_date_history

        self.assertEqual(last_date, None)
Ejemplo n.º 7
0
    def test_phones_with_one_entry(self):
        from .modelfactories import JournalFactory

        phone_data = {
            "editor_phone1": "",
            "editor_phone2": "0039 06 4990 2253",
            }

        journal = JournalFactory.build(**phone_data)
        phones = journal.phones

        self.assertEqual(phones, ['0039 06 4990 2253'])
Ejemplo n.º 8
0
    def test_phones_with_none_value(self):
        from .modelfactories import JournalFactory

        phone_data = {
            "editor_phone1": None,
            "editor_phone2": "",
            }

        journal = JournalFactory.build(**phone_data)
        phones = journal.phones

        self.assertEqual(phones, [])
Ejemplo n.º 9
0
    def test_empty_former_journal(self):
        from .modelfactories import JournalFactory

        former_data = {
            "previous_title": "",
            }

        journal = JournalFactory.build(**former_data)

        journal = journal.former_journal

        self.assertIsNone(journal)
Ejemplo n.º 10
0
    def test_scielo_issn_electronic_version(self):
        from .modelfactories import JournalFactory

        electronic_issn = {
            "scielo_issn": "electronic",
            "print_issn": "AAAA-AAAA",
            "eletronic_issn": "XXXX-XXXX"
            }

        journal = JournalFactory.build(**electronic_issn)
        issn = journal.issn

        self.assertEqual(issn, 'XXXX-XXXX')
Ejemplo n.º 11
0
    def test_phones_with_zero_entries(self):
        from .modelfactories import JournalFactory

        phone_data = {
            "title": "AAA",
            "editor_phone1": "",
            "editor_phone2": "",
        }

        journal = JournalFactory.build(**phone_data)
        phones = journal.phones

        self.assertEqual(phones, [])
Ejemplo n.º 12
0
    def test_address_with_missing_data(self):
        from .modelfactories import JournalFactory

        address_data = {
            "editor_address": "",
            "editor_address_city": None,
            "editor_address_country": "",
            "editor_address_state": "",
            }

        journal = JournalFactory.build(**address_data)
        address = journal.address

        self.assertEqual(address, None)
Ejemplo n.º 13
0
    def test_history(self):
        from .modelfactories import JournalFactory

        pub_status_history_data = {
            'pub_status_history': [{
                "date": "2010-04-01T00:00:00",
                "status": "current",
            },
            {
                "date": "1995-12-01T00:00:00",
                "status": "Deceased",
            }]}

        journal = JournalFactory.build(**pub_status_history_data)
        history = journal.history

        self.assertEqual(history, [
            {'history_date': datetime.datetime(2010, 4, 1, 0, 0), 'reason': 'current'},
            {'history_date': datetime.datetime(1995, 12, 1, 0, 0), 'reason': 'Deceased'}
            ])
Ejemplo n.º 14
0
    def test_former_journal(self):
        from .modelfactories import JournalFactory
        from catalog import mongomodels

        mock_objects = self.mocker.mock()

        journal_microdata = {
                  "id": 2,
                  "other_previous_title": None,
                  "previous_ahead_documents": 0,
                  "print_issn": "0021-2571",
                  "pub_status": "current",
                  "publication_city": "Roma",
                  "publisher_country": "IT",
                  "publisher_name": "Istituto Superiore di Sanità",
                  "publisher_state": None,
                  "resource_uri": "/api/v1/journals/1/",
                  "scielo_issn": "print",
                  "short_title": "Ann. Ist. Super. Sanità",
                  "title": "Annali dell'Istituto Superiore di Sanità",
                  "title_iso": "Ann. Ist. Super. Sanità",
                  "url_journal": None,
                  "url_online_submission": None,
                }

        mock_objects.find_one({'id': 2})
        self.mocker.result(journal_microdata)

        self.mocker.replay()

        former_data = {
            "previous_title": "/api/v1/journals/2/",
            }

        journal = JournalFactory.build(**former_data)

        mongomodels.Journal.objects = mock_objects

        journal = journal.former_journal

        self.assertIsInstance(journal, Journal)
Ejemplo n.º 15
0
    def test_last_date_history(self):
        from .modelfactories import JournalFactory

        pub_status_history_data = {
            'pub_status_history': [
            {
                "date": "2010-04-01T00:00:00",
                "status": "current"
            },
            {
                "date": "1968-04-01T00:00:00",
                "status": "deceased"
            },
            {
                "date": "2013-04-01T00:00:00",
                "status": "suspened"
            },
            ]}

        journal = JournalFactory.build(**pub_status_history_data)
        last_date = journal.last_date_history

        self.assertEqual(last_date, datetime.datetime(2013, 4, 1, 0, 0))
Ejemplo n.º 16
0
    def test_latter_journal(self):
        from .modelfactories import JournalFactory
        from catalog import mongomodels

        mock_objects = self.mocker.mock()

        journal_microdata = {
                  "previous_title": "/api/v1/journals/1/",
                  "title": "Annali dell'Istituto Superiore di Sanità",
                }

        mock_objects.find_one({'previous_title': {'$regex': '/*/*/*/1/'}})
        self.mocker.result(journal_microdata)

        self.mocker.replay()

        journal = JournalFactory.build()

        mongomodels.Journal.objects = mock_objects

        journal = journal.latter_journal

        self.assertIsInstance(journal, Journal)
Ejemplo n.º 17
0
    def test_list_issues_must_return_a_reverse_list_order_by_year(self):
        from modelfactories import JournalFactory

        journal_microdata = [
                    {
                        "id": 1,
                        "data": {
                            "id": 1,
                            "label": "45 (4)",
                            "number": "4",
                            "publication_year": 2009,
                            "volume": "45",
                            "order": 1
                        }
                    },
                    {
                        "id": 2,
                        "data": {
                            "id": 2,
                            "label": "45 (5)",
                            "number": "5",
                            "publication_year": 2009,
                            "volume": "45",
                            "order": 2
                        }
                    },
                    {
                        "id": 4,
                        "data": {
                            "id": 4,
                            "label": "47 (1)",
                            "number": "1",
                            "publication_year": 2009,
                            "volume": "47",
                            "order": 3
                        }
                    },
                    {
                        "id": 3,
                        "data": {
                            "id": 3,
                            "label": "46 (1)",
                            "number": "1",
                            "publication_year": 2010,
                            "volume": "46",
                            "order": 4
                        }
                    },
                    {
                        "id": 5,
                        "data": {
                            "id": 5,
                            "label": "45 (10)",
                            "number": "10",
                            "publication_year": 2009,
                            "volume": "45",
                            "order": 5
                        }
                    },
                    {
                        "id": 6,
                        "data": {
                            "id": 6,
                            "label": "45 (3)",
                            "number": "3",
                            "publication_year": 2010,
                            "volume": "45",
                            "order": 6
                        }
                    },
                ]

        journal = JournalFactory.build(issues=journal_microdata)

        previous_year = 9999
        for issue in journal.list_issues():
            self.assertLessEqual(issue.publication_year, previous_year)
            previous_year = issue.publication_year
Ejemplo n.º 18
0
    def test_list_issue_by_year_must_return_a_lazy_object(self):
        from modelfactories import JournalFactory

        journal_microdata = [
                    {
                        "id": 1,
                        "data": {
                            "id": 1,
                            "label": "45 (4)",
                            "number": "4",
                            "publication_year": 2009,
                            "volume": "45",
                            "order": 1
                        }
                    },
                    {
                        "id": 2,
                        "data": {
                            "id": 2,
                            "label": "45 (5)",
                            "number": "5",
                            "publication_year": 2009,
                            "volume": "45",
                            "order": 2
                        }
                    },
                    {
                        "id": 4,
                        "data": {
                            "id": 4,
                            "label": "47 (1)",
                            "number": "1",
                            "publication_year": 2009,
                            "volume": "47",
                            "order": 3
                        }
                    },
                    {
                        "id": 3,
                        "data": {
                            "id": 3,
                            "label": "46 (1)",
                            "number": "1",
                            "publication_year": 2010,
                            "volume": "46",
                            "order": 4
                        }
                    },
                    {
                        "id": 5,
                        "data": {
                            "id": 5,
                            "label": "45 (10)",
                            "number": "10",
                            "publication_year": 2009,
                            "volume": "45",
                            "order": 5
                        }
                    },
                    {
                        "id": 6,
                        "data": {
                            "id": 6,
                            "label": "45 (3)",
                            "number": "3",
                            "publication_year": 2010,
                            "volume": "45",
                            "order": 6
                        }
                    },
                ]

        journal = JournalFactory.build(issues=journal_microdata)

        issues = journal.list_issues_as_grid()

        self.assertIn(2010, issues)
        self.assertTrue(len(issues) == 2)