def setUpClass(cls):
        super(TestTeamSite, cls).setUpClass()

        user_credentials = UserCredential(settings['user_credentials']['username'],
                                          settings['user_credentials']['password'])
        cls.client = ClientContext(settings['url']).with_credentials(user_credentials)
        cls.site_manager = GroupSiteManager(cls.client)
 def setUpClass(cls):
     super(TestSearch, cls).setUpClass()
     user_credentials = UserCredential(
         settings['user_credentials']['username'],
         settings['user_credentials']['password'])
     cls.client = ClientContext(
         settings['url']).with_credentials(user_credentials)
     cls.search = SearchService(cls.client)
    def setUpClass(cls):
        tenant = os.environ.get('office365_python_sdk_tenant', 'mediadev8')
        admin_site_url = "https://{0}-admin.sharepoint.com/".format(tenant)
        credentials = UserCredential(settings['user_credentials']['username'],
                                     settings['user_credentials']['password'])

        cls.client = ClientContext(admin_site_url).with_credentials(credentials)
        cls.tenant = Tenant(cls.client)
示例#4
0
    def setUpClass(cls):
        credentials = UserCredential(
            user_name=settings['user_credentials']['username'],
            password=settings['user_credentials']['password'])
        cls.client = ClientContext(
            settings['url']).with_credentials(credentials)

        current_user = cls.client.web.currentUser
        cls.client.load(current_user)
        cls.client.execute_query()
        cls.target_user = current_user
示例#5
0
    def acquire_token_password_grant(self, client_id, username, password,
                                     resource, scope):
        """
        Acquire token via resource owner password credential (ROPC) grant

        :param str resource: A URI that identifies the resource for which the token is valid.
        :param str username: : The username of the user on behalf this application is authenticating.
        :param str password: The password of the user named in the username parameter.
        :param str client_id: str The OAuth client id of the calling application.
        :param list[str] scope:
        """
        self.provider = OAuthTokenProvider(self.url)
        return self.provider.acquire_token_password_type(
            resource=resource,
            client_id=client_id,
            user_credentials=UserCredential(username, password),
            scope=scope)
import os
import tempfile

from office365.runtime.auth.userCredential import UserCredential
from office365.sharepoint.files.file import File
from settings import settings

abs_file_url = "{site_url}sites/team/Shared Documents/sample.docx".format(
    site_url=settings.get('url'))
user_credentials = UserCredential(
    settings.get('user_credentials').get('username'),
    settings.get('user_credentials').get('password'))

file_name = os.path.basename(abs_file_url)
with tempfile.TemporaryDirectory() as local_path:
    with open(os.path.join(local_path, file_name), 'wb') as local_file:
        file = File.from_url(abs_file_url).with_credentials(
            user_credentials).download(local_file).execute_query()
    print("'{0}' file has been downloaded into {1}".format(
        file.serverRelativeUrl, local_file.name))
from office365.runtime.auth.userCredential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.search.searchRequest import SearchRequest
from office365.sharepoint.search.searchService import SearchService
from settings import settings

ctx = ClientContext.connect_with_credentials(settings['url'],
                                             UserCredential(settings['user_credentials']['username'],
                                                            settings['user_credentials']['password']))

search = SearchService(ctx)
request = SearchRequest("IsDocument:1")
result = search.post_query(request)
ctx.execute_query()
relevant_results = result.PrimaryQueryResult.RelevantResults
for i in relevant_results['Table']['Rows']:
    cells = relevant_results['Table']['Rows'][i]['Cells']
    print(cells[6]['Value'])