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 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 testPrepareCredsEmailPassword(self):
        email = '*****@*****.**'
        password = '******'
        creds_file = 'bogus'
        token_file = 'boguser'

        mocked_creds = self.mox.CreateMock(gdata_lib.Creds)
        self.mox.StubOutWithMock(gdata_lib.Creds, '__new__')

        gdata_lib.Creds.__new__(gdata_lib.Creds).AndReturn(mocked_creds)
        mocked_creds.SetCreds(email, password)
        self.mox.ReplayAll()

        ups.PrepareCreds(creds_file, token_file, email, password)
        self.mox.VerifyAll()