Ejemplo n.º 1
0
    def test_if_the_returned_list_are_from_correct_collection(self):
        """
        test if the API is considering the colletion on filter
        """
        collection1 = modelfactories.CollectionFactory()
        collection2 = modelfactories.CollectionFactory()

        journal = modelfactories.JournalFactory.create()
        journal.join(collection1, self.user)

        modelfactories.IssueFactory.create(journal=journal)

        #test if return one issue from collecion1
        response1 = self.app.get(
            '/api/v1/issues/?collection=%s&print_issn=%s' %
            (collection1.name, journal.print_issn),
            extra_environ=self.extra_environ)
        content1 = json.loads(response1.content)

        self.assertEqual(response1.status_code, 200)
        self.assertTrue('objects' in response1.content)

        self.assertEqual(len(content1['objects']), 1)

        #test if return nothing issue from collecion2
        response2 = self.app.get(
            '/api/v1/issues/?collection=%s&print_issn=%s' %
            (collection2.name, journal.print_issn),
            extra_environ=self.extra_environ)
        content2 = json.loads(response2.content)

        self.assertEqual(response2.status_code, 200)
        self.assertTrue('objects' in response2.content)

        self.assertEqual(len(content2['objects']), 0)
Ejemplo n.º 2
0
    def test_journal_getone(self):
        col = modelfactories.CollectionFactory()
        journal = modelfactories.JournalFactory.create()
        journal.join(col, self.user)

        response = self.app.get('/api/v1/journals/%s/' % journal.pk,
                                extra_environ=self.extra_environ)
        self.assertEqual(response.status_code, 200)
        self.assertTrue('title' in response.content)
Ejemplo n.º 3
0
    def test_filter_by_pubstatus_many_values_filtering_by_collection(self):
        col = modelfactories.CollectionFactory()
        col2 = modelfactories.CollectionFactory()

        journal = modelfactories.JournalFactory.create()
        journal.join(col, self.user)
        journal.change_status(col, 'current', 'testing', self.user)

        journal2 = modelfactories.JournalFactory.create()
        journal2.join(col2, self.user)
        journal2.change_status(col2, 'deceased', 'testing', self.user)

        response = self.app.get(
            '/api/v1/journals/?pubstatus=current&pubstatus=deceased&collection=%s'
            % col.name,
            extra_environ=self.extra_environ)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(json.loads(response.content)['objects']), 1)
Ejemplo n.º 4
0
 def test_list_all_by_collection(self):
     collection = modelfactories.CollectionFactory()
     journal = modelfactories.JournalFactory.create()
     journal.join(collection, self.user)
     collection_name = collection.name
     response = self.app.get('/api/v1/journals/?collection=%s' %
                             collection_name,
                             extra_environ=self.extra_environ)
     self.assertEqual(response.status_code, 200)
     self.assertTrue('objects' in response.content)
Ejemplo n.º 5
0
    def test_dehydrate_pub_status_with_one_collections(self):
        col = modelfactories.CollectionFactory()

        col.add_user(self.user)

        journal = modelfactories.JournalFactory.create()
        journal.join(col, self.user)

        response = self.app.get('/api/v1/journals/',
                                extra_environ=self.extra_environ).json

        self.assertEqual(response['objects'][0]['pub_status'], u'inprogress')
Ejemplo n.º 6
0
    def test_without_succeding_title(self):
        col = modelfactories.CollectionFactory()

        col.add_user(self.user)

        journal1 = modelfactories.JournalFactory.create(title='Previous Title')
        journal1.join(col, self.user)

        response = self.app.get('/api/v1/journals/%s/' % journal1.pk,
                                extra_environ=self.extra_environ).json

        self.assertEqual(response['succeeding_title'], None)
Ejemplo n.º 7
0
    def test_dehydrate_pub_status_with_multiple_collections_without_collection_param(
            self):
        col = modelfactories.CollectionFactory()
        col2 = modelfactories.CollectionFactory()

        col.add_user(self.user)
        col2.add_user(self.user)

        col.make_default_to_user(self.user)

        journal = modelfactories.JournalFactory.create()
        journal.join(col, self.user)
        journal.join(
            col2,
            self.user,
        )

        journal.change_status(col, u'current', u'yeah', self.user)

        response = self.app.get('/api/v1/journals/',
                                extra_environ=self.extra_environ,
                                status=400)
        self.assertEqual(response.status_code, 400)
Ejemplo n.º 8
0
    def test_dehydrate_pub_status_with_multiple_collections(self):
        col = modelfactories.CollectionFactory()
        col2 = modelfactories.CollectionFactory()

        col.add_user(self.user)
        col2.add_user(self.user)

        col.make_default_to_user(self.user)

        journal = modelfactories.JournalFactory.create()
        journal.join(col, self.user)
        journal.join(
            col2,
            self.user,
        )

        journal.change_status(col, u'current', u'yeah', self.user)

        response = self.app.get('/api/v1/journals/?collection=%s' %
                                col.name_slug,
                                extra_environ=self.extra_environ).json

        self.assertEqual(response['objects'][0]['pub_status'], u'current')
Ejemplo n.º 9
0
    def test_filter_print_issn(self):
        col = modelfactories.CollectionFactory()
        journal = modelfactories.JournalFactory.create(print_issn='1234-1234')
        journal.join(col, self.user)
        journal2 = modelfactories.JournalFactory.create(print_issn='4321-4321')
        journal2.join(col, self.user)
        response = self.app.get('/api/v1/journals/?print_issn=1234-1234',
                                extra_environ=self.extra_environ)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(json.loads(response.content)['objects']), 1)
        self.assertEqual(
            json.loads(response.content)['objects'][0]['print_issn'],
            '1234-1234')
Ejemplo n.º 10
0
    def test_number_of_itens_when_change_filters(self):
        """
        test if number of itens changes when change params
        """
        collection = modelfactories.CollectionFactory()

        journal = modelfactories.JournalFactory.create()
        journal.join(collection, self.user)

        modelfactories.IssueFactory.create(journal=journal)
        modelfactories.IssueFactory.create(
            journal=journal,
            number='999',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='999',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='999',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='999',
            volume='2',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='999',
            volume='3',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='999',
            volume='5',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='',
            volume='2',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='',
            volume='2',
            type='supplement',
        )
        modelfactories.IssueFactory.create(
            journal=journal,
            number='',
            volume='2',
            type='supplement',
        )

        #test with param number
        response = self.app.get('/api/v1/issues/?suppl_number=999',
                                extra_environ=self.extra_environ)
        content = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertTrue('objects' in response.content)

        self.assertEqual(len(content['objects']), 6)

        #test with param number and suppl_volume
        response = self.app.get('/api/v1/issues/?suppl_volume=2',
                                extra_environ=self.extra_environ)
        content = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertTrue('objects' in response.content)

        self.assertEqual(len(content['objects']), 3)

        #test with param number and suppl_number and suppl_volume, must return empty list
        response = self.app.get(
            '/api/v1/issues/?suppl_volume=2&suppl_number=999',
            extra_environ=self.extra_environ)
        content = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertTrue('objects' in response.content)

        self.assertEqual(len(content['objects']), 0)

        #test with param number and suppl_number and suppl_volume, change sequence of params
        response = self.app.get(
            '/api/v1/issues/?suppl_number=999&suppl_volume=2',
            extra_environ=self.extra_environ)
        content = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertTrue('objects' in response.content)

        self.assertEqual(len(content['objects']), 0)
Ejemplo n.º 11
0
    def test_api_v1_datamodel(self):
        col = modelfactories.CollectionFactory()
        journal = modelfactories.JournalFactory.create()
        journal.join(col, self.user)

        response = self.app.get('/api/v1/journals/%s/' % journal.pk,
                                extra_environ=self.extra_environ)

        expected_keys = [
            u'editor_address',
            u'copyrighter',
            u'editor_address_city',
            u'editor_address_state',
            u'creator',
            u'ctrl_vocabulary',
            u'national_code',
            u'updated',
            u'frequency',
            u'url_journal',
            u'short_title',
            u'final_num',
            u'logo',
            u'publisher_country',
            u'publisher_name',
            u'eletronic_issn',
            u'issues',
            u'url_online_submission',
            u'init_vol',
            u'subject_descriptors',
            u'title',
            u'pub_status_history',
            u'id',
            u'final_year',
            u'editorial_standard',
            u'languages',
            u'scielo_issn',
            u'collections',
            u'index_coverage',
            u'secs_code',
            u'init_year',
            u'sections',
            u'is_indexed_aehci',
            u'use_license',
            u'other_titles',
            u'editor_address_country',
            u'acronym',
            u'publisher_state',
            u'is_indexed_scie',
            u'sponsors',
            u'abstract_keyword_languages',
            u'editor_name',
            u'other_previous_title',
            u'study_areas',
            u'subject_categories',
            u'medline_code',
            u'is_trashed',
            u'init_num',
            u'publication_city',
            u'pub_level',
            u'is_indexed_ssci',
            u'missions',
            u'editor_email',
            u'created',
            u'medline_title',
            u'final_vol',
            u'cover',
            u'editor_phone2',
            u'editor_phone1',
            u'print_issn',
            u'editor_address_zip',
            u'contact',
            u'pub_status',
            u'pub_status_reason',
            u'title_iso',
            u'notes',
            u'resource_uri',
            u'previous_ahead_documents',
            u'current_ahead_documents',
            u'twitter_user',
            u'previous_title',
            u'succeeding_title',
        ]

        json_keys = set(response.json.keys())
        expected_keys = set(expected_keys)

        # looks for unexpected fields
        self.assertFalse(json_keys.difference(expected_keys))

        # make sure all expected fields are present
        for key in expected_keys:
            self.assertEqual(True, key in json_keys)