def testPost(self, render_mock, *_): mode = 'Mod1' self.testapp.post('/admin/panic', {'mode': mode, 'enabled': 'enable'}) render_mock.assert_called_once() self.assertTrue( test.GetArgFromCallHistory( render_mock).endswith('panic_set_verify.html')) self.assertEqual( {'name': mode, 'enabled': 'enable'}, test.GetArgFromCallHistory(render_mock, arg_index=1)['mode'])
def testDisplayMainWithIncorrectTag(self, render, *_): resp = gae_main.app.get_response('/admin/manifest_modifications?mod_type=b') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual(1, len(params['mods'])) self.assertGreater(len(params['error']), 0)
def testDisplayMainAsAdmin(self, render, *_): resp = gae_main.app.get_response('/admin/manifest_modifications') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual(1, len(params['mods'])) self.assertEqual(True, params['can_add_manifest_mods']) self.assertEqual(0, len(params['error']))
def testUserFilter(self, render, *_): resp = gae_main.app.get_response( '/admin/manifest_modifications?filter_field=admin&' '[email protected]') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual(1, len(params['mods']))
def testSiteSummary(self, render, *_): resp = gae_main.app.get_response('/admin/?filter-type=site&filter=MTV') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual('search', params['report_type']) self.assertEqual(2, len(params['computers']))
def testOwnerFilterEmptyResult(self, render, *_): resp = gae_main.app.get_response( '/admin/manifest_modifications?filter_field=target&' 'filter_value=notfound') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual(0, len(params['mods']))
def testGet(self, render_mock, _): tagname = 'ak47' models.Tag(key_name=tagname).put() self.testapp.get('/admin/tags', status=httplib.OK) args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEqual(tagname, args['tags'][0].key().name())
def testGet(self, render_mock, _): data = {'192.168.1.1': 'zerocool'} models.KeyValueCache.MemcacheWrappedSet( 'client_exit_ip_blocks', 'text_value', util.Serialize(data)) self.testapp.get('/admin/ip_blacklist', status=httplib.OK) args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEquals(data.items(), args['list'])
def testDisplayMain(self, render_mock, *_): aliasname = 'aliasname' pkgname = 'pkgname' models.PackageAlias(key_name=aliasname, munki_pkg_name=pkgname).put() self.testapp.get('/admin/package_alias') args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEqual(1, len(args['package_aliases'].fetch(None)))
def testHaveEntriesWithSameSerial(self, render, *_): resp = gae_main.app.get_response('/admin/host/NEWUUID1==/') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual(1, len(params['duplicates'])) other = params['duplicates'][0] self.assertEqual(self.common_serial, other.serial) self.assertEqual('UUID1', other.uuid)
def testGet(self, render_mock, *_): self.testapp.get('/admin/panic', status=httplib.OK) modes = [] for mode in panic.common.PANIC_MODES: modes.append({'name': mode, 'enabled': False}) render_mock.assert_called_once() self.assertEqual( modes, test.GetArgFromCallHistory(render_mock, arg_index=1)['modes'])
def testGet(self, render_mock, *_): package.settings.LIST_OF_CATEGORIES = 'category1,category2' filename = 'testpackage.dmg' self.test_package.put() resp = self.testapp.get('/admin/package/' + filename) self.assertEqual(httplib.OK, resp.status_int) args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEqual(filename, args['pkg'].filename)
def testPostDeleteNoManModsNoGroup(self, render_mock, *unused_args): """Test post() delete action, no manifest modifications, no group.""" self.testapp.get('/admin/groups', status=httplib.OK) render_dict = test.GetArgFromCallHistory(render_mock, arg_index=1) params = { 'xsrf_token': render_dict['xsrf_token'], 'group': 'test group42', 'action': 'delete', } self.testapp.post('/admin/groups', params, status=httplib.NOT_FOUND)
def testSelfReport(self, render, *_): resp = gae_main.app.get_response('/admin/') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertTrue(params['self_report']) self.assertEqual('owner', params['search_type']) self.assertEqual('zerocool', params['search_term']) self.assertEqual(2, len(params['computers'])) self.assertEqual('zerocool', params['computers'][0].owner) self.assertEqual('zerocool', params['computers'][1].owner)
def testOwnerSummary(self, render, *_): resp = gae_main.app.get_response( '/admin/?filter-type=owner&filter=zerocool') self.assertEqual(httplib.OK, resp.status_int) params = test.GetArgFromCallHistory(render, arg_index=1) self.assertFalse(params['self_report']) self.assertEqual('search', params['report_type']) self.assertEqual(2, len(params['computers'])) self.assertEqual(('MTV', 2), params['summary']['sites_histogram'][0]) self.assertAlmostEqual(99.0196, params['summary']['conns_off_corp_percent'], 3)
def testPostWithValidToken(self, render_mock, _): newuser = '******' self.testapp.get('/admin/acl_groups', status=httplib.OK) params = test.GetArgFromCallHistory(render_mock, arg_index=1) params = {'xsrf_token': params['xsrf_token'], 'item_0': [newuser]} self.testapp.post('/admin/acl_groups/support_users', params, status=httplib.FOUND) users = json.loads( models.KeyValueCache.MemcacheWrappedGet('support_users', 'text_value')) self.assertEqual([newuser], users)
def testDisplayUpdateLogs(self, render_mock, _): product_id = 'pid' p = models.AppleSUSProduct(key_name=product_id, product_id=product_id, tracks=['unstable']) p.put() models.AdminAppleSUSProductLog.Log(p, 'action description') self.testapp.get('/admin/applesus/logs', {'product_id': product_id}, status=httplib.OK) args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEqual(1, len(args['logs'])) self.assertEqual(product_id, args['product_id'])
def testPostChangeNoGroup(self, render_mock, *unused_args): """Test post() change action, group doesn't exist.""" self.testapp.get('/admin/groups', status=httplib.OK) render_dict = test.GetArgFromCallHistory(render_mock, arg_index=1) params = { 'xsrf_token': render_dict['xsrf_token'], 'group': 'test group42', 'action': 'change', 'user': '******', 'add': '1' } self.testapp.post('/admin/groups', params, status=httplib.NOT_FOUND)
def testDisplayMain(self, render_mock, _): product_id = 'pid' models.AppleSUSProduct(key_name=product_id, product_id=product_id, tracks=['unstable']).put() self.testapp.get('/admin/applesus/', status=httplib.OK) args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEqual(1, len(args['products'])) self.assertLess(args['products'][0].stable_promote_date, (datetime.datetime.now() + datetime.timedelta(days=60)).date())
def testPostDeleteNoManMods(self, render_mock, *unused_args): """Test post() delete action, no manifest modifications.""" self.testapp.get('/admin/groups', status=httplib.OK) render_dict = test.GetArgFromCallHistory(render_mock, arg_index=1) params = { 'xsrf_token': render_dict['xsrf_token'], 'group': 'test group', 'action': 'delete', } resp = self.testapp.post('/admin/groups', params, status=httplib.FOUND) redirect_url = '/admin/groups?msg=Group successfully deleted.' self.assertTrue(resp.location.endswith(redirect_url)) self.assertNotIn('test group', models.Group.GetAllGroupNames())
def testPostCreate(self, render_mock, *unused_args): """Test post() create action.""" self.testapp.get('/admin/groups', status=httplib.OK) render_dict = test.GetArgFromCallHistory(render_mock, arg_index=1) params = { 'xsrf_token': render_dict['xsrf_token'], 'group': 'test group3', 'action': 'create', 'user': '******', } resp = self.testapp.post('/admin/groups', params, status=httplib.FOUND) redirect_url = '/admin/groups?msg=Group successfully saved.' self.assertTrue(resp.location.endswith(redirect_url)) self.assertIn('user5', models.Group.get_by_key_name('test group3').users)
def testPostDeleteWithManMods(self, render_mock, *unused_args): """Test post() delete action, manifiest modifications exist.""" models.GroupManifestModification.GenerateInstance( mod_type='group', target='test group', munki_pkg_name='Firefox').put() self.testapp.get('/admin/groups', status=httplib.OK) render_dict = test.GetArgFromCallHistory(render_mock, arg_index=1) params = { 'xsrf_token': render_dict['xsrf_token'], 'group': 'test group', 'action': 'delete', } resp = self.testapp.post('/admin/groups', params, status=httplib.FOUND) redirect_url = ("/admin/groups?msg=Group not deleted as it's being used " "for Manifest Modifications.") self.assertTrue(resp.location.endswith(redirect_url)) self.assertIn('test group', models.Group.GetAllGroupNames())
def testGet(self, render_mock, _): past = datetime.datetime.now() - datetime.timedelta(days=1) broken_uuid = 'uuid1' models.Computer( key_name=broken_uuid, preflight_datetime=past, uuid=broken_uuid).put() models.ComputerClientBroken( uuid=broken_uuid, details='42343243234', connections_off_corp=50, broken_datetimes=[datetime.datetime.now()]).put() toomany_preflight_uuid = 'toomany_preflight_since_postflight' models.Computer( uuid=toomany_preflight_uuid, connections_on_corp=40, preflight_count_since_postflight=50, postflight_datetime=past, preflight_datetime=datetime.datetime.now(), ).put() models.Computer( uuid='not_broken', connections_on_corp=40, preflight_count_since_postflight=3, postflight_datetime=past, preflight_datetime=datetime.datetime.now(), ).put() no_connections_uuid = 'client without connections' models.Computer( uuid=no_connections_uuid, preflight_count_since_postflight=6).put() self.testapp.get('/admin/brokenclients') args = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertEqual( [no_connections_uuid], _ComputersListToUuidList(args['zero_conn_computers'])) self.assertEqual( [broken_uuid], _ComputersListToUuidList(args['py_computers'])) self.assertEqual( [toomany_preflight_uuid], _ComputersListToUuidList(args['pf_computers']))
def testGet(self, render_mock, *unused_args): """Test get().""" self.testapp.get('/admin/groups', status=httplib.OK) render_dict = test.GetArgFromCallHistory(render_mock, arg_index=1) self.assertIn('test group', [x.key().name() for x in render_dict['groups']])
def testSelfReport(self, render, *_): resp = gae_main.app.get_response('/admin/host/UUID2/') params = test.GetArgFromCallHistory(render, arg_index=1) self.assertEqual(httplib.OK, resp.status_int) self.assertTrue(params['self_report'])