title: How would I unit test code like this?
body: <p>I have the following class and am currently testing it via running a file which calls the methods in this file. I then use a mixture of print statements and checking the blog to make sure the code has worked.</p>
  
  <p>I'd really like to write some pytest unit tests for this and automate it all, but how can I do this? Also, if authentication doesn't exist or had become invalid it opens the browser and prompts the user to input the auth code. Later on this will be handled by a gui form. Pytest doesn't take user input, and rightly so; it wouldn't be automated.</p>
  
  <pre><code>class BloggerInterface(object):
      """Connects to blogger api and authorises client."""
  
      def get_credentials(self):
          """Gets google api credentials, or generates new credentials
          if they don't exist or are invalid."""
          scope = 'https://www.googleapis.com/auth/blogger'
  
          flow = oauth2client.client.flow_from_clientsecrets(
                  'client_secret.json', scope,
                  redirect_uri='urn:ietf:wg:oauth:2.0:oob')
  
          storage = oauth2client.file.Storage('credentials.dat')
          credentials = storage.get()
  
          if not credentials or credentials.invalid:
              auth_uri = flow.step1_get_authorize_url()
              webbrowser.open(auth_uri)
  
              auth_code = input('Enter the auth code: ')
              credentials = flow.step2_exchange(auth_code)
  
              storage.put(credentials)
  
          return credentials
  
      def get_service(self):
          """Returns an authorised blogger api service."""
          credentials = self.get_credentials()
          http = httplib2.Http()
          http = credentials.authorize(http)
          service = apiclient.discovery.build('blogger', 'v3', http=http)
  
          return service
  
      def get_blog(self, blog_id):
          """Gets the details ofthe blog withthe id blog_id"""
          BlogDetails = collections.namedtuple('BlogDetails', 'blog_id, name, desc, url')
  
          conn = self.get_service()
          request = conn.blogs().get(blogId=blog_id, view='ADMIN')
          response = request.execute()
  
          name = response.get('name')
          desc = response.get('description')
          url = response.get('url')
  
          blog = BlogDetails(blog_id=blog_id, name=name, desc=desc, url=url)
  
          return blog
  
      def get_posts(self, blog_id, status='live'):
          """Gets all posts from the blog with the id blog_id"""
          posts = []
  
          conn = self.get_service()
          request = conn.posts().list(blogId=blog_id, view='ADMIN',
          status=status)
  
          #Responses are paginated, so a paging loop is required.
          while request:
  
              response = request.execute()
  
              for post in response.get('items', []):
                  post_id = post.get('id')
                  title = post.get('title')
                  url = post.get('url')
                  status = post.get('status')
                  content = post.get('content')
  
                  posts.append({'post_id':post_id, 'title':title, 'url':url,
                      'status':status, 'content':content})
  
              request = conn.posts().list_next(request, response)
  
          return posts
  
      def add_post(self, blog_id, post, is_draft=True):
          """Adds a new post to the blog with the id blog_id"""
          conn = self.get_service()
  
          #post is in the form {title, content, (labels), author_name, author_id.
          title, content, author_name, author_id, labels = post
  
          data = {
                  'kind': 'blogger#post',
                  'title': title,
                  'content': content,
                  'labels': labels,
                  'author': {'displayName':author_name, 'id':author_id}
                  }
  
          request = conn.posts().insert(blogId=blog_id, body=data,
                  isDraft=is_draft)
          response = request.execute()
          post_id = response.get('id')
  
          return post_id
  </code></pre>