kopia lustrzana https://github.com/ihabunek/toot
				
				
				
			Add --json option to whoami command
							rodzic
							
								
									6cdba16fcf
								
							
						
					
					
						commit
						2c4f7e17c9
					
				| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
import json
 | 
			
		||||
 | 
			
		||||
from toot.entities import Account, from_dict
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_whoami(user, run):
 | 
			
		||||
| 
						 | 
				
			
			@ -6,6 +9,12 @@ def test_whoami(user, run):
 | 
			
		|||
    assert f"@{user.username}" in out
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_whoami_json(user, run):
 | 
			
		||||
    out = run("whoami", "--json")
 | 
			
		||||
    account = from_dict(Account, json.loads(out))
 | 
			
		||||
    assert account.username == user.username
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_whois(app, friend, run):
 | 
			
		||||
    variants = [
 | 
			
		||||
        friend.username,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -516,8 +516,12 @@ def blocked(app, user, args):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def whoami(app, user, args):
 | 
			
		||||
    account = api.verify_credentials(app, user).json()
 | 
			
		||||
    print_account(account)
 | 
			
		||||
    response = api.verify_credentials(app, user)
 | 
			
		||||
    if args.json:
 | 
			
		||||
        print(response.text)
 | 
			
		||||
    else:
 | 
			
		||||
        account = response.json()
 | 
			
		||||
        print_account(account)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def whois(app, user, args):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -232,6 +232,12 @@ tag_arg = (["tag_name"], {
 | 
			
		|||
    "help": "tag name, e.g. Caturday, or \"#Caturday\"",
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
json_arg = (["--json"], {
 | 
			
		||||
    "action": "store_true",
 | 
			
		||||
    "default": False,
 | 
			
		||||
    "help": "print json instead of plaintext",
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
# Arguments for selecting a timeline (see `toot.commands.get_timeline_generator`)
 | 
			
		||||
common_timeline_args = [
 | 
			
		||||
    (["-p", "--public"], {
 | 
			
		||||
| 
						 | 
				
			
			@ -388,7 +394,7 @@ READ_COMMANDS = [
 | 
			
		|||
    Command(
 | 
			
		||||
        name="whoami",
 | 
			
		||||
        description="Display logged in user details",
 | 
			
		||||
        arguments=[],
 | 
			
		||||
        arguments=[json_arg],
 | 
			
		||||
        require_auth=True,
 | 
			
		||||
    ),
 | 
			
		||||
    Command(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue