コード例 #1
0
ファイル: test_views.py プロジェクト: darshanman40/osf.io
class TestConfigViews(ZoteroTestCase,
                      views.OAuthCitationAddonConfigViewsTestCaseMixin,
                      OsfTestCase):
    folder = MockFolder()
    Serializer = ZoteroSerializer
    client = Zotero
    citationsProvider = ZoteroCitationsProvider
    foldersApiUrl = None
    documentsApiUrl = None
    mockResponses = mock_responses

    def setUp(self):
        super(TestConfigViews, self).setUp()
        self.foldersApiUrl = urlparse.urljoin(
            API_URL,
            'users/{}/collections'.format(self.external_account.provider_id))
        self.documentsApiUrl = urlparse.urljoin(
            API_URL,
            'users/{}/items'.format(self.external_account.provider_id))
コード例 #2
0
ファイル: utils.py プロジェクト: rdm-dev12/RDM-osf.io
 def set_node_settings(self, settings):
     super(MendeleyTestCase, self).set_node_settings(settings)
     settings.list_id = MockFolder().json['id']
     settings.external_account = self.external_account
     settings.save()
コード例 #3
0
class TestConfigViews(ZoteroTestCase,
                      views.OAuthCitationAddonConfigViewsTestCaseMixin,
                      OsfTestCase):
    folder = MockFolder()
    library = MockLibrary()
    Serializer = ZoteroSerializer
    client = Zotero
    citationsProvider = ZoteroCitationsProvider
    foldersApiUrl = None
    documentsApiUrl = None
    mockResponses = mock_responses
    mockResponsesFiledUnfiled = mock_responses_with_filed_and_unfiled

    def setUp(self):
        super(TestConfigViews, self).setUp()
        self.foldersApiUrl = urljoin(
            API_URL,
            'users/{}/collections'.format(self.external_account.provider_id))
        self.documentsApiUrl = urljoin(
            API_URL,
            'users/{}/items/top'.format(self.external_account.provider_id))

        # Sets library key
        self.citationsProvider().set_config(self.node_settings, self.user,
                                            self.folder.json['id'],
                                            self.folder.name, Auth(self.user),
                                            'personal', 'personal')

    def test_widget_view_incomplete_library_set_only(self):
        # JSON: everything a widget needs
        # When library is set in zotero, folder is cleared.
        self.citationsProvider().set_config(self.node_settings, self.user,
                                            self.folder.json['id'],
                                            self.folder.name, Auth(self.user),
                                            self.library.json['id'],
                                            self.library.name)
        assert_false(self.node_settings.complete)
        assert_equal(self.node_settings.list_id, None)
        assert_equal(self.node_settings.library_id, 'Fake Library Key')
        res = self.citationsProvider().widget(
            self.project.get_addon(self.ADDON_SHORT_NAME))
        assert_false(res['complete'])
        assert_equal(res['list_id'], None)
        assert_equal(res['library_id'], 'Fake Library Key')

    def test_widget_view_complete(self):
        # JSON: everything a widget needs
        # Library must be set, then folder.
        # Sets library key
        self.citationsProvider().set_config(self.node_settings, self.user,
                                            self.folder.json['id'],
                                            self.folder.name, Auth(self.user),
                                            self.library.json['id'],
                                            self.library.name)
        # Sets folder
        self.citationsProvider().set_config(
            self.node_settings,
            self.user,
            self.folder.json['id'],
            self.folder.name,
            Auth(self.user),
        )
        assert_true(self.node_settings.complete)
        assert_equal(self.node_settings.list_id, 'Fake Key')
        assert_equal(self.node_settings.library_id, 'Fake Library Key')
        res = self.citationsProvider().widget(
            self.project.get_addon(self.ADDON_SHORT_NAME))
        assert_true(res['complete'])
        assert_equal(res['list_id'], 'Fake Key')
        assert_equal(res['library_id'], 'Fake Library Key')

    @responses.activate
    def test_citation_list_root_only_unfiled_items_included(self):
        responses.add(
            responses.Response(responses.GET,
                               self.foldersApiUrl,
                               body=self.mockResponsesFiledUnfiled['folders'],
                               content_type='application/json'))

        responses.add(
            responses.Response(
                responses.GET,
                self.documentsApiUrl,
                body=self.mockResponsesFiledUnfiled['documents'],
                content_type='application/json'))

        res = self.app.get(self.project.api_url_for('{0}_citation_list'.format(
            self.ADDON_SHORT_NAME),
                                                    list_id='ROOT'),
                           auth=self.user.auth)

        children = res.json['contents']
        # There are three items, one folder and two files, but one of the files gets pulled out because it
        # belongs to a collection
        assert_equal(len(children), 2)
        assert_equal(children[0]['kind'], 'folder')
        assert_equal(children[1]['kind'], 'file')
        assert_true(children[1].get('csl') is not None)
コード例 #4
0
class TestConfigViews(ZoteroTestCase, views.OAuthCitationAddonConfigViewsTestCaseMixin, OsfTestCase):
    folder = MockFolder()
    library = MockLibrary()
    Serializer = ZoteroSerializer
    client = Zotero
    citationsProvider = ZoteroCitationsProvider
    foldersApiUrl = None
    documentsApiUrl = None
    mockResponses = mock_responses

    def setUp(self):
        super(TestConfigViews, self).setUp()
        self.foldersApiUrl = urlparse.urljoin(API_URL, 'users/{}/collections'
            .format(self.external_account.provider_id))
        self.documentsApiUrl = urlparse.urljoin(API_URL, 'users/{}/items'
            .format(self.external_account.provider_id))

    def test_widget_view_incomplete_library_set_only(self):
        # JSON: everything a widget needs
        # When library is set in zotero, folder is cleared.
        self.citationsProvider().set_config(
            self.node_settings,
            self.user,
            self.folder.json['id'],
            self.folder.name,
            Auth(self.user),
            self.library.json['id'],
            self.library.name
        )
        assert_false(self.node_settings.complete)
        assert_equal(self.node_settings.list_id, None)
        assert_equal(self.node_settings.library_id, 'Fake Library Key')
        res = self.citationsProvider().widget(self.project.get_addon(self.ADDON_SHORT_NAME))
        assert_false(res['complete'])
        assert_equal(res['list_id'], None)
        assert_equal(res['library_id'], 'Fake Library Key')

    def test_widget_view_complete(self):
        # JSON: everything a widget needs
        # Library must be set, then folder.
        # Sets library key
        self.citationsProvider().set_config(
            self.node_settings,
            self.user,
            self.folder.json['id'],
            self.folder.name,
            Auth(self.user),
            self.library.json['id'],
            self.library.name
        )
        # Sets folder
        self.citationsProvider().set_config(
            self.node_settings,
            self.user,
            self.folder.json['id'],
            self.folder.name,
            Auth(self.user),
        )
        assert_true(self.node_settings.complete)
        assert_equal(self.node_settings.list_id, 'Fake Key')
        assert_equal(self.node_settings.library_id, 'Fake Library Key')
        res = self.citationsProvider().widget(self.project.get_addon(self.ADDON_SHORT_NAME))
        assert_true(res['complete'])
        assert_equal(res['list_id'], 'Fake Key')
        assert_equal(res['library_id'], 'Fake Library Key')