0

How do I create a object that I can invoke to mimic the following api call and response. I am aware of the mock library but the use case prohibits me from using it.

response = client.users.create(email='test@gmail.com', phone=123)
outcome = response.ok

My current solution below works however I feel like there is a more pythonic and generic way to do this so I can mimic other calls without having to rewrite different inner classes

class Client:
    ok = True
    class users:
        class create():
            ok = True
            def __init__(self, email, phone):
                pass

Input

client = Client()
response = client.users.create(email='test@gmail.com', phone=123)
response.ok

Output

True
Tamdim
  • 972
  • 2
  • 12
  • 29
  • 1
    You could use a dictionary. See [this thread](https://stackoverflow.com/q/2352181/5987698). – GoodDeeds May 11 '20 at 18:29
  • Interesting, however using dot notation on a dictionary does not work in this case because I need to be able to pass arguments using 'create' ... – Tamdim May 11 '20 at 21:41
  • `create` could be a function stored in the dictionary, with the key "users" then? – GoodDeeds May 11 '20 at 22:01

0 Answers0