Exemplo n.º 1
0
    def test_set_auth_wrong_user(self):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        self.user.save()

        with assert_raises(PermissionsError):
            self.node_settings.set_auth(external_account=external_account,
                                        user=UserFactory())
Exemplo n.º 2
0
    def _prep_oauth_case(self):
        self.node = ProjectFactory()
        self.user = self.node.creator

        self.external_account = ExternalAccountFactory()

        self.user.external_accounts.append(self.external_account)
        self.user.save()

        self.user_settings = self.user.get_or_add_addon('mendeley')
Exemplo n.º 3
0
    def test_fork_by_authorizer(self, mock_push_status):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        self.node_settings.set_auth(external_account, self.user)

        fork = self.node.fork_node(auth=Auth(user=self.node.creator))

        assert_true(fork.get_addon('mendeley').has_auth)
        assert_true(
            self.user_settings.verify_oauth_access(fork, external_account))
Exemplo n.º 4
0
    def test_clear_auth(self):
        self.node_settings.external_account = ExternalAccountFactory()
        self.node_settings.mendeley_list_id = 'something'
        self.node_settings.user_settings = self.user_settings
        self.node_settings.save()

        self.node_settings.clear_auth()

        assert_is_none(self.node_settings.external_account)
        assert_is_none(self.node_settings.mendeley_list_id)
        assert_is_none(self.node_settings.user_settings)
Exemplo n.º 5
0
    def test_has_auth_true(self):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)

        self.node_settings.set_auth(external_account, self.user)

        # mendeley_list_id should have no effect
        self.node_settings.mendeley_list_id = None
        assert_true(self.node_settings.has_auth)

        # mendeley_list_id should have no effect
        self.node_settings.mendeley_list_id = 'totally fake ID'
        assert_true(self.node_settings.has_auth)
Exemplo n.º 6
0
    def test_remove_contributor_not_authorizer(self):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        self.node_settings.set_auth(external_account, self.user)

        contributor = UserFactory()
        self.node.add_contributor(contributor)
        self.node.remove_contributor(contributor,
                                     auth=Auth(user=self.node.creator))

        assert_true(self.node_settings.has_auth)
        assert_true(
            self.user_settings.verify_oauth_access(self.node,
                                                   external_account))
Exemplo n.º 7
0
    def test_remove_contributor_authorizer(self, mock_push_status):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        self.node_settings.set_auth(external_account, self.user)

        contributor = UserFactory()
        self.node.add_contributor(contributor,
                                  permissions=['read', 'write', 'admin'])
        self.node.remove_contributor(self.node.creator,
                                     auth=Auth(user=contributor))

        assert_false(self.node_settings.has_auth)
        assert_false(
            self.user_settings.verify_oauth_access(self.node,
                                                   external_account))
Exemplo n.º 8
0
    def test_verify_oauth_access_no_metadata(self):
        self._prep_oauth_case()

        self.user_settings.grant_oauth_access(
            node=self.node,
            external_account=self.external_account,
        )
        self.user_settings.save()

        assert_true(
            self.user_settings.verify_oauth_access(
                node=self.node, external_account=self.external_account))

        assert_false(
            self.user_settings.verify_oauth_access(
                node=self.node, external_account=ExternalAccountFactory()))
Exemplo n.º 9
0
    def test_has_auth_false(self):
        external_account = ExternalAccountFactory()

        assert_false(self.node_settings.has_auth)

        # both external_account and user_settings must be set to have auth
        self.node_settings.external_account = external_account
        assert_false(self.node_settings.has_auth)

        self.node_settings.external_account = None
        self.node_settings.user_settings = self.user_settings
        assert_false(self.node_settings.has_auth)

        # set_auth must be called to have auth
        self.node_settings.external_account = external_account
        self.node_settings.user_settings = self.user_settings
        assert_false(self.node_settings.has_auth)
Exemplo n.º 10
0
    def test_deauthorize(self):
        self.node_settings.external_account = ExternalAccountFactory()
        self.node_settings.mendeley_list_id = 'something'
        self.node_settings.user_settings = self.user_settings
        self.node_settings.save()

        assert_true(self.node_settings.mendeley_list_id)
        self.node_settings.deauthorize(auth=Auth(self.user))
        self.node_settings.save()
        assert_is(self.node_settings.user_settings, None)
        assert_is(self.node_settings.mendeley_list_id, None)

        last_log = self.node.logs[-1]
        assert_equal(last_log.action, 'mendeley_node_deauthorized')
        params = last_log.params
        assert_in('node', params)
        assert_in('project', params)
Exemplo n.º 11
0
    def test_set_target_folder(self):
        folder_id = 'fake-folder-id'
        folder_name = 'fake-folder-name'

        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        self.user.save()

        self.node_settings.set_auth(
            external_account=external_account,
            user=self.user,
        )

        assert_is_none(self.node_settings.mendeley_list_id)

        self.node_settings.set_target_folder(
            folder_id,
            folder_name,
            auth=Auth(user=self.user),
        )

        # instance was updated
        assert_equal(
            self.node_settings.mendeley_list_id,
            'fake-folder-id',
        )

        # user_settings was updated
        # TODO: the call to grant_oauth_access should be mocked
        assert_true(
            self.user_settings.verify_oauth_access(
                node=self.node,
                external_account=external_account,
                metadata={'folder': 'fake-folder-id'}))

        log = self.node.logs[-1]
        assert_equal(log.action, 'mendeley_folder_selected')
        assert_equal(log.params['folder_id'], folder_id)
        assert_equal(log.params['folder_name'], folder_name)
Exemplo n.º 12
0
    def test_set_auth(self):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        self.user.save()

        # this should be reset after the call
        self.node_settings.mendeley_list_id = 'anything'

        self.node_settings.set_auth(external_account=external_account,
                                    user=self.user)

        # this instance is updated
        assert_equal(self.node_settings.external_account, external_account)
        assert_equal(self.node_settings.user_settings, self.user_settings)
        assert_is_none(self.node_settings.mendeley_list_id)

        # user_settings was updated
        # TODO: The call to grant_oauth_access in set_auth should be mocked
        assert_true(
            self.user_settings.verify_oauth_access(
                node=self.node,
                external_account=external_account,
            ))