Exemple #1
0
  def testGet(self):
    """Test get()."""
    plist_file = (
        'simian/mac/common/testdata/testpackage.plist')
    plist = open('src/tests/' + plist_file).read()
    pkg1_munki_name = 'testpackage-1'
    models.PackageInfo(filename='filename1', _plist=plist).put()

    with mock.patch.object(models.ReportsCache, 'GetInstallCounts') as m:
      m.return_value = ({
          pkg1_munki_name: {
              'install_count': 3,
              'applesus': True,
              'duration_count': 2,
              'duration_total_seconds': 50,
              'duration_seconds_avg': int((50)/2),
          }
      }, 0)
      resp = gae_app.get_response(
          '/cron/maintenance/update_avg_install_durations')
    self.assertEqual(httplib.OK, resp.status_int)

    pkg_info = models.PackageInfo().all().fetch(1)[0]
    self.assertEqual(
        'test package\n\n'
        '2 users have installed this with an average duration of 25 seconds.',
        pkg_info.plist['description'])
Exemple #2
0
  def testGet(self):
    """Test get()."""
    self.testapp = webtest.TestApp(gae_app)
    blobstore_stub = self.testbed.get_stub(testbed.BLOBSTORE_SERVICE_NAME)
    mail_stub = self.testbed.get_stub('mail')

    goodblob_key = 'good'
    blobstore_stub.CreateBlob(goodblob_key, 'content')
    blobstore_stub.CreateBlob('to_be_deleted', '123B')

    filename_bad = 'missing_blob'

    models.PackageInfo(
        filename=filename_bad, mtime=datetime.datetime(1970, 1, 1)).put(
            avoid_mtime_update=True)
    models.PackageInfo(
        filename='good', mtime=datetime.datetime(1970, 1, 1),
        blobstore_key=goodblob_key).put(avoid_mtime_update=True)

    self.testapp.get('/cron/maintenance/verify_packages')
    self.RunAllDeferredTasks()

    self.assertEqual(1, len(mail_stub.get_sent_messages()))
    mail = mail_stub.get_sent_messages()[0]
    self.assertEqual('Package is lacking a file: missing_blob', mail.subject)

    keys = []
    for b in blobstore.BlobInfo.all():
      keys.append(str(b.key()))
    self.assertEqual([goodblob_key], keys)
    def testSuccess(self, *_):
        settings.ICONS_GCS_BUCKET = 'test'

        filename = 'testpackage.dmg'
        munki_name = 'testpackage'
        models.PackageInfo(key_name=filename,
                           filename=filename,
                           name=munki_name,
                           _plist=self.plist).put()
        content = 'ICON_CONTETN'
        resp = self.testapp.post('/admin/upload_icon/%s' % filename,
                                 upload_files=[('icon', '1.png', content)],
                                 status=httplib.FOUND)
        self.assertTrue(resp.headers['Location'].endswith('/admin/package/%s' %
                                                          filename))
Exemple #4
0
    def testCreatePackageAlias(self, *_):
        aliasname = 'aliasname'
        pkgname = 'pkgname'
        models.PackageInfo(name=pkgname).put()

        self.testapp.post('/admin/package_alias', {
            'create_package_alias': 1,
            'package_alias': aliasname,
            'munki_pkg_name': pkgname
        },
                          status=httplib.FOUND)

        aliases = models.PackageAlias.all().fetch(None)
        self.assertEqual(1, len(aliases))
        self.assertEqual(aliasname, aliases[0].key().name())
        self.assertEqual(pkgname, aliases[0].munki_pkg_name)
        self.assertTrue(aliases[0].enabled)