"""Tests for Dropbox for Business access."""

import argparse
import json
from pprint import pprint
import requests


def parse_args():
    """Get Dropbox authorisation token from command line."""
    parser = argparse.ArgumentParser(description=__doc__)

    parser.add_argument('--member_id', help='List files for given member')
    parser.add_argument('--file', help='Download the given file')
    parser.add_argument('token', help='Dropbox for Business access token')

    return parser.parse_args()


def post(headers, url, data='{}'):
    print('Requesting', url, data)
    r = requests.post(url, headers=headers, data=data)
    r.raise_for_status()
    return r.json()


def main():
    args = parse_args()
    headers = {'Content-Type': 'application/json',
               'Authorization': 'Bearer ' + args.token}

    if not args.member_id and not args.file:
        pprint(post(headers, 'https://api.dropbox.com/1/team/get_info'))
        pprint(post(headers, 'https://api.dropbox.com/1/team/members/list'))

    if args.member_id:
        headers['X-Dropbox-Perform-As-Team-Member'] = args.member_id
        pprint(post(headers, 'https://api.dropbox.com/1/account/info'))

        has_more = True
        data = '{}'

        while has_more:
            response = post(headers, 'https://api.dropbox.com/1/delta', data)
            pprint(response)
            has_more = response['has_more']
            data = json.dumps({'cursor': response['cursor']})


if __name__ == '__main__':
    main()

@@ -59,20 +59,8 @@
 rse%0A
-import json%0A
 from
@@ -522,16 +522,254 @@
 ='%7B%7D'):%0A
+    %22%22%22Post request to Dropbox.%0A%0A    Args:%0A        headers (dict): HTTP headers for request%0A        url (str): url to request%0A        data (dict): metadata attached to request%0A%0A    Returns:%0A        dict: response body (from JSON)%0A    %22%22%22%0A
     prin
@@ -905,24 +905,48 @@
 def main():%0A
+    %22%22%22Main program.%22%22%22%0A
     args = p
@@ -1666,31 +1666,17 @@
 data
- = json.dumps(%7B
+%5B
 'cursor'
 : re
@@ -1671,17 +1671,19 @@
 'cursor'
-:
+%5D =
  respons
@@ -1697,10 +1697,8 @@
 or'%5D
-%7D)
 %0A%0A%0Ai

Tidy test_dropbox.py