예제 #1
0
def dataverse_get_config(node_addon, auth, **kwargs):
    """API that returns the serialized node settings."""
    result = DataverseSerializer(
        user_settings=auth.user.get_addon('dataverse'),
        node_settings=node_addon,
    ).serialized_node_settings
    return {'result': result}, http.OK
예제 #2
0
    def setUp(self):
        super(TestDataverseSerializerConfig, self).setUp()

        self.host = 'my.host.name'
        self.external_account = create_external_account(self.host)
        self.user.external_accounts.append(self.external_account)
        self.node_settings.set_auth(self.external_account, self.user)
        self.serializer = DataverseSerializer(
            user_settings=self.user_settings,
            node_settings=self.node_settings,
        )
예제 #3
0
    def test_user_is_owner(self):

        # No user is not owner
        serializer = DataverseSerializer(node_settings=self.node_settings)
        assert_false(serializer.user_is_owner)

        # Different user is not owner
        serializer.user_settings = AuthUserFactory()
        assert_false(serializer.user_is_owner)

        # Owner is owner
        serializer.user_settings = self.user_settings
        assert_true(serializer.user_is_owner)
예제 #4
0
    def test_dataverse_get_user_accounts(self):
        external_account = create_external_account()
        self.user.external_accounts.append(external_account)
        self.user.external_accounts.append(create_external_account())
        self.user.save()

        url = api_url_for('dataverse_get_user_accounts')
        res = self.app.get(url, auth=self.user.auth)
        accounts = res.json['accounts']

        assert_equal(len(accounts), 2)
        serializer = DataverseSerializer(user_settings=self.user_settings)
        assert_equal(
            accounts[0],
            serializer.serialize_account(external_account),
        )
예제 #5
0
    def test_serialize_settings_helper_non_owner(self, mock_connection):
        mock_connection.return_value = create_mock_connection()

        # Non-owner user without add-on
        serializer = DataverseSerializer(node_settings=self.node_settings)
        result = serializer.serialized_node_settings
        assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
        assert_false(result['userHasAuth'])
        assert_false(result['userIsOwner'])

        # Non-owner user with add-on
        stranger = AuthUserFactory()
        stranger.add_addon('dataverse')
        stranger.external_accounts.append(create_external_account())
        serializer.user_settings = stranger.get_addon('dataverse')
        result = serializer.serialized_node_settings
        assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
        assert_true(result['userHasAuth'])
        assert_false(result['userIsOwner'])
예제 #6
0
def dataverse_get_user_accounts(auth):
    """ Returns the list of all of the current user's authorized Dataverse accounts """

    return DataverseSerializer(
        user_settings=auth.user.get_addon('dataverse')
    ).serialized_user_settings