def testMainTokenFile(self):
    """Verify that running main with token file follows flow."""
    csv = 'any.csv'
    token_file = self.tempfile
    creds_file = 'non-existing-file'

    mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
    mocked_creds.auth_token_loaded = True

    self.mox.StubOutWithMock(ups, 'PrepareCreds')
    self.mox.StubOutWithMock(ups, 'LoadTable')
    self.mox.StubOutWithMock(mps, 'FinalizeTable')
    self.mox.StubOutWithMock(ups.Uploader, 'Upload')

    ups.PrepareCreds(creds_file, token_file, None, None).AndReturn(mocked_creds)
    ups.LoadTable(csv).AndReturn('csv_table')
    mps.FinalizeTable('csv_table')
    ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.PKGS_WS_NAME)
    ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.DEPS_WS_NAME)
    mocked_creds.StoreCredsIfNeeded(creds_file)
    mocked_creds.StoreAuthTokenIfNeeded(token_file)
    self.mox.ReplayAll()

    ups.main(['--cred-file=%s' % creds_file,
              '--auth-token-file=%s' % token_file,
              csv])

    self.mox.VerifyAll()
    def testMainTokenFile(self):
        """Verify that running main with token file follows flow."""
        csv = 'any.csv'
        token_file = self.tempfile
        creds_file = 'non-existing-file'

        mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
        mocked_creds.auth_token_loaded = True

        self.mox.StubOutWithMock(ups, 'PrepareCreds')
        self.mox.StubOutWithMock(ups, 'LoadTable')
        self.mox.StubOutWithMock(mps, 'FinalizeTable')
        self.mox.StubOutWithMock(ups.Uploader, 'Upload')

        ups.PrepareCreds(creds_file, token_file, None,
                         None).AndReturn(mocked_creds)
        ups.LoadTable(csv).AndReturn('csv_table')
        mps.FinalizeTable('csv_table')
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.PKGS_WS_NAME)
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.DEPS_WS_NAME)
        mocked_creds.StoreCredsIfNeeded(creds_file)
        mocked_creds.StoreAuthTokenIfNeeded(token_file)
        self.mox.ReplayAll()

        ups.main([
            '--cred-file=%s' % creds_file,
            '--auth-token-file=%s' % token_file, csv
        ])

        self.mox.VerifyAll()
  def testMainEmailPassword(self):
    """Verify that running main with email/password follows flow."""
    csv = 'any.csv'
    email = '*****@*****.**'
    password = '******'

    mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
    creds_file = 'non-existing-file'

    self.mox.StubOutWithMock(ups, 'PrepareCreds')
    self.mox.StubOutWithMock(ups, 'LoadTable')
    self.mox.StubOutWithMock(mps, 'FinalizeTable')
    self.mox.StubOutWithMock(ups.Uploader, 'Upload')

    ups.PrepareCreds(creds_file, None, email, password).AndReturn(mocked_creds)
    ups.LoadTable(csv).AndReturn('csv_table')
    mps.FinalizeTable('csv_table')
    ups.Uploader.Upload(mox.IgnoreArg(), ws_name='Packages')
    ups.Uploader.Upload(mox.IgnoreArg(), ws_name='Dependencies')
    mocked_creds.StoreCredsIfNeeded(creds_file)
    self.mox.ReplayAll()

    ups.main(['--email=%s' % email,
              '--password=%s' % password,
              '--cred-file=%s' % creds_file,
               csv])

    self.mox.VerifyAll()
  def testMainCredsFile(self):
    """Verify that running main with creds file follows flow."""
    csv = 'any.csv'
    creds_file = self.tempfile
    token_file = 'non-existing-file'

    creds = gdata_lib.Creds()

    self.mox.StubOutWithMock(ups, 'PrepareCreds')
    self.mox.StubOutWithMock(ups, 'LoadTable')
    self.mox.StubOutWithMock(mps, 'FinalizeTable')
    self.mox.StubOutWithMock(ups.Uploader, 'Upload')

    ups.PrepareCreds(creds_file, token_file, None, None).AndReturn(creds)
    ups.LoadTable(csv).AndReturn('csv_table')
    mps.FinalizeTable('csv_table')
    ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.PKGS_WS_NAME)
    ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.DEPS_WS_NAME)
    self.mox.ReplayAll()

    ups.main([
        '--cred-file=%s' % creds_file,
        '--auth-token-file=%s' % token_file,
        csv,
    ])

    self.mox.VerifyAll()
    def testMainEmailPassword(self):
        """Verify that running main with email/password follows flow."""
        csv = 'any.csv'
        email = '*****@*****.**'
        password = '******'

        mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
        creds_file = 'non-existing-file'

        self.mox.StubOutWithMock(ups, 'PrepareCreds')
        self.mox.StubOutWithMock(ups, 'LoadTable')
        self.mox.StubOutWithMock(mps, 'FinalizeTable')
        self.mox.StubOutWithMock(ups.Uploader, 'Upload')

        ups.PrepareCreds(creds_file, None, email,
                         password).AndReturn(mocked_creds)
        ups.LoadTable(csv).AndReturn('csv_table')
        mps.FinalizeTable('csv_table')
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name='Packages')
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name='Dependencies')
        mocked_creds.StoreCredsIfNeeded(creds_file)
        self.mox.ReplayAll()

        ups.main([
            '--email=%s' % email,
            '--password=%s' % password,
            '--cred-file=%s' % creds_file, csv
        ])

        self.mox.VerifyAll()
    def testMainCredsFile(self):
        """Verify that running main with creds file follows flow."""
        csv = "any.csv"
        creds_file = self.tempfile
        token_file = "non-existing-file"

        mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
        mocked_creds.auth_token_loaded = False

        self.mox.StubOutWithMock(ups, "PrepareCreds")
        self.mox.StubOutWithMock(ups, "LoadTable")
        self.mox.StubOutWithMock(mps, "FinalizeTable")
        self.mox.StubOutWithMock(ups.Uploader, "Upload")

        ups.PrepareCreds(creds_file, token_file, None, None).AndReturn(mocked_creds)
        ups.LoadTable(csv).AndReturn("csv_table")
        mps.FinalizeTable("csv_table")
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.PKGS_WS_NAME)
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name=ups.DEPS_WS_NAME)
        mocked_creds.StoreCredsIfNeeded(creds_file)
        mocked_creds.StoreAuthTokenIfNeeded(token_file)
        self.mox.ReplayAll()

        ups.main(["--cred-file=%s" % creds_file, "--auth-token-file=%s" % token_file, csv])

        self.mox.VerifyAll()
    def testMainEmailPassword(self):
        """Verify that running main with email/password follows flow."""
        csv = "any.csv"
        email = "*****@*****.**"
        password = "******"

        mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
        creds_file = "non-existing-file"

        self.mox.StubOutWithMock(ups, "PrepareCreds")
        self.mox.StubOutWithMock(ups, "LoadTable")
        self.mox.StubOutWithMock(mps, "FinalizeTable")
        self.mox.StubOutWithMock(ups.Uploader, "Upload")

        ups.PrepareCreds(creds_file, None, email, password).AndReturn(mocked_creds)
        ups.LoadTable(csv).AndReturn("csv_table")
        mps.FinalizeTable("csv_table")
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name="Packages")
        ups.Uploader.Upload(mox.IgnoreArg(), ws_name="Dependencies")
        mocked_creds.StoreCredsIfNeeded(creds_file)
        self.mox.ReplayAll()

        ups.main(["--email=%s" % email, "--password=%s" % password, "--cred-file=%s" % creds_file, csv])

        self.mox.VerifyAll()
 def testMissingCSV(self):
   """Test that running without a csv file argument exits with an error."""
   with self.OutputCapturer():
     # Running without a package should exit with code!=0
     try:
       ups.main([])
     except exceptions.SystemExit, e:
       self.assertNotEquals(e.args[0], 0)
 def testHelp(self):
   """Test that --help is functioning"""
   with self.OutputCapturer() as output:
     # Running with --help should exit with code==0
     try:
       ups.main(['--help'])
     except exceptions.SystemExit, e:
       self.assertEquals(e.args[0], 0)
 def testMissingCSV(self):
     """Test that running without a csv file argument exits with an error."""
     with self.OutputCapturer():
         # Running without a package should exit with code!=0
         try:
             ups.main([])
         except exceptions.SystemExit, e:
             self.assertNotEquals(e.args[0], 0)
 def testHelp(self):
     """Test that --help is functioning"""
     with self.OutputCapturer() as output:
         # Running with --help should exit with code==0
         try:
             ups.main(['--help'])
         except exceptions.SystemExit, e:
             self.assertEquals(e.args[0], 0)
  def testHelp(self):
    """Test that --help is functioning"""
    with self.OutputCapturer() as output:
      # Running with --help should exit with code==0
      try:
        ups.main(['--help'])
      except exceptions.SystemExit as e:
        self.assertEquals(e.args[0], 0)

    # Verify that a message beginning with "Usage: " was printed
    stdout = output.GetStdout()
    self.assertTrue(stdout.startswith('Usage: '))