Exemple #1
0
 def testBadDefaults(self):
   """Pass in None for some defaults with no pref overrides."""
   runtime = RuntimeNoDialog(None,
                             launcher.Preferences(self.filename,
                                                  FakePlatform(None, None)))
   self.assertTrue(runtime.problem)
   runtime = RuntimeNoDialog(None,
                             launcher.Preferences(self.filename,
                                                  FakePlatform(None, 'hi')))
   self.assertTrue(runtime.problem)
   runtime = RuntimeNoDialog(None,
                             launcher.Preferences(self.filename,
                                                  FakePlatform('hi', None)))
   self.assertTrue(runtime.problem)
Exemple #2
0
 def __init__(self):
   super(AboutBoxController, self).__init__()
   self._dialog = None
   self._preferences = launcher.Preferences()
   self._CreateDialog()
   self._CreateHtmlContent()
   self._SetPage()
Exemple #3
0
    def testWindowPositionSaving(self):
        file = tempfile.NamedTemporaryFile()
        prefs = launcher.Preferences(file.name)

        mainframe = launcher.MainFrame(None, -1, launcher.MainTable(), prefs,
                                       None, None)
        mainframe.SetPosition((10, 20))
        mainframe.SetSize((500, 600))
        mainframe.Close()

        # Make sure the size gets saved... but adjusted for minimum sizing.
        rect = prefs.Get(launcher.Preferences.PREF_MAIN_WINDOW_RECT)
        self.assertEqual('10 20 500 600', rect)

        # Make sure the size gets restored... but adjusted for minimum sizing.
        mainframe = launcher.MainFrame(None, -1, launcher.MainTable(), prefs,
                                       None, None)
        position = mainframe.GetPositionTuple()
        self.assertEqual((10, 20), position)
        size = mainframe.GetSizeTuple()
        self.assertEqual((500, 600), size)

        # Make sure an off-the-screen window gets moved elsewhere
        prefs.Set(launcher.Preferences.PREF_MAIN_WINDOW_RECT,
                  '-300 -900 300 400')
        mainframe = launcher.MainFrame(None, -1, launcher.MainTable(), prefs,
                                       None, None)
        position = mainframe.GetPositionTuple()
        self.assertNotEqual((-300, -900), position)
        size = mainframe.GetSizeTuple()
        self.assertEqual((300, 400), size)

        # Clean up our temp prefs file.
        file.close()
Exemple #4
0
 def testBadFile(self):
     p = launcher.Preferences(
         '/this_path_does_not_exist/bin_denial_factory')
     self._problem = False
     p._PreferenceProblem = self._PreferenceProblem
     p.Save()
     self.assertTrue(self._problem)
Exemple #5
0
 def testGetVsDefault(self):
     p = launcher.Preferences('/foo', self.FakePlatform())
     p.Set(launcher.Preferences.PREF_PYTHON, 'clown-shoes')
     self.assertEqual('clown-shoes',
                      p.Get(launcher.Preferences.PREF_PYTHON))
     self.assertEqual('super-python',
                      p.GetDefault(launcher.Preferences.PREF_PYTHON))
     self.assertEqual(p[launcher.Preferences.PREF_PYTHON],
                      p.Get(launcher.Preferences.PREF_PYTHON))
Exemple #6
0
 def testInit(self):
   runtime = launcher.Runtime()
   preferences = launcher.Preferences()
   projects = ['hi', 'mom']
   dialog = auth_dialog.AuthDialog(None)
   d = launcher.DeployController(runtime, preferences, projects, dialog)
   self.assertEqual(dialog, d.dialog)
   d = launcher.DeployController(runtime, preferences, projects)
   self.assertTrue(d.dialog)
Exemple #7
0
    def testWindowMinSize(self):
        file = tempfile.NamedTemporaryFile()
        prefs = launcher.Preferences(file.name)

        mainframe = launcher.MainFrame(None, -1, launcher.MainTable(), prefs,
                                       None, None)
        mainframe.SetPosition((10, 20))
        mainframe.SetSize((100, 50))
        size = mainframe.GetSizeTuple()
        self.assertEqual(launcher.MainFrame.WINDOW_MIN_SIZE, size)

        file.close()
Exemple #8
0
 def testSetThenGet(self):
   platform = FakePlatform('pythoncmd', 'dir')
   pref = launcher.Preferences(self.filename, platform)
   runtime = RuntimeNoDialog(platform, pref)
   self.assertFalse(runtime.problem)
   project = launcher.Project('super-path', '123', False)
   das = runtime.DevAppServerCommand(project, verify=False)
   self.assertTrue('pythoncmd' in das)
   self.assertTrue('photojournalist' not in das)
   pref[launcher.Preferences.PREF_PYTHON] = 'photojournalist'
   das = runtime.DevAppServerCommand(project, verify=False)
   self.assertTrue('pythoncmd' not in das)
   self.assertTrue('photojournalist' in das)
   self.assertRaises(launcher.RuntimeException,
                     runtime.DevAppServerCommand,
                     project)
    def __init__(self, preferences=None):
        """Initialize a Runtime object.

    Args:
      preferences: An object with a dictionary 'get' interface
        for preferences (such as launcher.Preferences); created if None.
    """
        self._preferences = preferences or launcher.Preferences()
        # The preferences object will use a default value if not set
        # when accessed with the __getitem__ interface.
        python = self._preferences[launcher.Preferences.PREF_PYTHON]
        appengine = self._preferences[launcher.Preferences.PREF_APPENGINE]
        if not python or not appengine:
            self._RequirementProblem(self._REQ_FAIL_STRING %
                                     (python, appengine))
        else:
            self._ConfigureEnvironment()
    def _NewProjectTemplate(self, preferences=None):
        """Return the new project template directory.

    Args:
      preferences: the preference object to use to find our App Engine SDK.
        If None, a default is chosen.
    Returns:
      A directory name the new project template.
      (Its correctness isn't verified.)
    """
        preferences = preferences or launcher.Preferences()
        basedir = preferences[launcher.Preferences.PREF_APPENGINE]
        if not basedir:
            self.FailureMessage(self._NO_SDK_STRING, 'Create new Project')
            return
        templatedir = os.path.join(basedir, 'new_project_template')
        return templatedir
Exemple #11
0
  def Deploy(self, event, deploy_controller=None):
    """Initiates a deploy to Google of the project selected in the main frame.

    Called directly from UI.

    Args:
      event: the wx.Event that initiated the transaction
      deploy_controller: if not None, the controller to be used for
        deployment.  If None, a default is used
        (launcher.DeployController).  Only non-None in a unit test.
    """
    project_list = self._frame.SelectedProjects()
    if not project_list:
      logging.warning('No projects selected for deployment.')
      return
    dc = deploy_controller or launcher.DeployController(self._runtime,
                                                        launcher.Preferences(),
                                                        project_list)
    dc.InitiateDeployment()
Exemple #12
0
 def testBasics(self):
     # I know "tmpnam is a potential security risk to your program", but
     # I need a filename, and os.tmpfile() doesn't give me one.
     # Test empty prefs on creation
     p = self.preferences()
     self.assertFalse(p.Items())
     # Add an item and save it
     p['key'] = 'value'
     self.assertEqual('value', p['key'])
     p.Save()
     # New prefs with the same filename; make sure we see the same thing
     nextp = launcher.Preferences(self.filename)
     self.assertTrue(nextp.Items())
     self.assertEqual('value', nextp['key'])
     nextp['new'] = 'new'
     # Make sure the 1st prefs doesn't see it until it's saved/reloaded
     self.assertFalse(p['new'])
     nextp.Save()
     self.assertFalse(p['new'])
     p.Load()
     self.assertEqual('new', p['new'])
Exemple #13
0
 def testTaskThreadForProject(self):
   project = launcher.Project('path', 8000, 'project_name')
   d = launcher.DeployController(launcher.Runtime(), launcher.Preferences(),
                                 [project])
   d._name = 'fred'
   d._password = '******'
   tt = d._TaskThreadForProject(project)
   self.assertFalse(tt.isAlive())
   # confirm stdin works.  Use python so we don't need cygwin.
   # Print out the 'Running application' string so that
   # taskthread will know to transition from WillStart to DidStart.
   script = ('import sys; print "Running application http://x:5"; '
             'print sys.stdin.read().strip()')
   cat_cmd = [sys.executable, '-c', script]
   tt = d._TaskThreadForProject(project, cat_cmd)
   output = ['']
   def collect(line, date=True):
     output[0] += line
   tt.LogOutput = collect
   starting = [0]
   started = [0]
   lock = threading.Lock()
   def _TaskWillStart():
     starting[0] = time.time()
   def _TaskDidStart():
     started[0] = time.time()
   def _TaskDidStop(code):
     lock.release()
   tt._TaskWillStart = _TaskWillStart
   tt._TaskDidStart = _TaskDidStart
   tt._TaskDidStop = _TaskDidStop
   lock.acquire()
   tt.start()
   lock.acquire()  # blocks until _TaskDidStop() releases it
   lock.release()
   self.assertNotEqual(0, starting[0])
   self.assertNotEqual(0, started[0])
   # Make sure the 'started' happens after 'starting'
   self.assertTrue(started > starting)
   self.assertTrue('himom' in output[0])
Exemple #14
0
  def testNoDefaultsAllPrefsOverride(self):
    """None for ALL defaults, all pref overrides, and make sure all is happy."""
    pref = launcher.Preferences(self.filename, FakePlatform(None, None))
    pycmd = '/usr/bin/python'
    pref[launcher.Preferences.PREF_PYTHON] = pycmd
    pref[launcher.Preferences.PREF_APPENGINE] = '/tmp/foo/bar/baz'
    runtime = RuntimeNoDialog(preferences=pref)
    self.assertFalse(runtime.problem)
    project = launcher.Project('super-path', '123')

    # test of DevAppServerCommand()
    das = runtime.DevAppServerCommand(project, verify=False)
    self.assertTrue(pycmd in das)
    self.assertTrue('super-path' in das)
    self.assertTrue('--port=123' in das)
    self.assertFalse('--mega-flag' in das)
    self.assertRaises(launcher.RuntimeException,
                      runtime.DevAppServerCommand,
                      project, verify=True)

    # test project flags
    project.flags = ['--mega-flag', '--oops']
    das = runtime.DevAppServerCommand(project, verify=False)
    self.assertTrue('--mega-flag' in das)
    self.assertTrue('--oops' in das)

    # test DevAppServerCommand's extra_flags
    extras = ['--hammertime', '--singsong']
    for flag in extras:
      self.assertFalse(flag in das)
    das = runtime.DevAppServerCommand(project, extra_flags=extras, verify=False)
    for flag in extras:
      self.assertTrue(flag in das)

    # test of DeployCommand()
    deploy_cmd = runtime.DeployCommand(project, '*****@*****.**')
    for s in (pycmd, '[email protected]', 'update', 'super-path'):
      self.assertTrue(s in deploy_cmd)
    deploy_cmd = runtime.DeployCommand(project, '*****@*****.**', 'xazzy')
    self.assertTrue('--server=xazzy' in deploy_cmd)
Exemple #15
0
 def preferences(self):
     p = launcher.Preferences(self.filename)
     p._PreferenceProblem = self._PreferenceProblem
     self.saved_preferences = p
     return p
Exemple #16
0
 def testGetSDKEnvironmentSetting(self):
   pref = launcher.Preferences(self.filename, platform=launcher.Platform())
   runtime = RuntimeNoDialog(preferences=pref)
   sdk_env = runtime._GetSDKEnvironmentSetting()
   self.assertTrue('-launcher-' in sdk_env)
   self.assertTrue('\n' not in sdk_env)
Exemple #17
0
 def __init__(self, platform=None, preferences=None):
   """Odd args for historical reasons."""
   self.problem = False
   preferences = preferences or launcher.Preferences(platform=platform)
   super(RuntimeNoDialog,self).__init__(preferences)
Exemple #18
0
 def testDefaultEditor(self):
     p = launcher.Preferences('/foo', launcher.Platform())
     editor = p.GetDefault(launcher.Preferences.PREF_EDITOR)
     self.assertTrue(os.path.exists(editor))
Exemple #19
0
 def _CreateModels(self):
   """Create models (MVC) for this application."""
   self._table = launcher.MainTable()
   self._preferences = launcher.Preferences()
   self._runtime = launcher.Runtime(preferences=self._preferences)