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 testDeleteTag(self, *_): tagname = 'ak47' models.Tag(key_name=tagname).put() self.testapp.post('/admin/tags', { 'action': 'delete', 'tag': tagname }, status=httplib.FOUND) tags = models.Tag.all().fetch(None) self.assertEqual(0, len(tags))
def post(self): """POST handler.""" can_mod_tags = (self.IsAdminUser() or auth.IsSupportUser or auth.IsSecurityUser()) if not can_mod_tags: return tag = self.request.get('tag').strip() tag = urllib.unquote(tag) action = self.request.get('action') if action == 'create': t = models.Tag(key_name=tag) uuid = self.request.get('uuid') if uuid: key = db.Key.from_path('Computer', uuid) t.keys.append(key) t.put() msg = 'Tag successfully saved.' elif action == 'delete': tag_manifest_mods = models.TagManifestModification.all().filter( 'tag_key_name =', tag).get() if tag_manifest_mods: msg = 'Tag not deleted as it\'s being used for Manifest Modifications.' else: t = models.Tag.get_by_key_name(tag) if t: t.delete() else: self.error(404) return msg = 'Tag successfully deleted.' elif action == 'change': uuid = self.request.get('uuid') add_tag = self.request.get('add') == '1' t = models.Tag.get_by_key_name(tag) if not t: self.error(404) return key = db.Key.from_path('Computer', uuid) if add_tag: t.keys.append(key) else: if key in t.keys: t.keys.remove(key) t.put() msg = 'Tag successfully modified' self.redirect('/admin/tags?msg=%s' % msg)
def testModifyTag(self, *_): uuid = 'id1' tagname = 'ak47' models.Tag(key_name=tagname).put() self.testapp.post('/admin/tags', { 'action': 'change', 'tag': tagname, 'add': 1, 'uuid': uuid }, status=httplib.FOUND) tags = models.Tag.all().fetch(None) self.assertEqual(1, len(tags)) self.assertEqual(1, len(tags[0].keys)) self.assertEqual(uuid, tags[0].keys[0].name())