Write test to make sure login_if_needed sets api key. Allow cli/main.py to be called as a main program.