class TestTag(unittest.TestCase):

        class TestData:
            def __init__(self, name):
                self.name = name
                self.verbose = True

        def setUp(self):
            self.recognition = Recognition()

        def create_tags(self):
            print "Creating some watchlists"

            test_data = [
                        TestTag.TestData(name='Blacklist'),
                        TestTag.TestData(name='Whitelist'),
                        TestTag.TestData(name='Office')
            ]

            for this_test in test_data:
                print "** Testing {0} **".format(this_test.name)
                tag = self.recognition.create_tag(name=this_test.name)
                print 'created tag {name} {tag_id}'.format(name=tag['name'], tag_id=tag['watchlist_id'])
                self.assertIsNotNone(tag['tag_id'])

        def list_tags(self):
            print "List all the watchlists"

            tags = self.recognition.list_tags()

            self.assertIsNotNone(tags)

            for tag in tags:
                print '{0} has id {1}'.format(tag['name'], tag['tag_id'])

        def delete_tags(self):
            tags = self.recognition.list_tags()
            for tag in tags:
                print 'Going to delete {0}'.format(tag['tag_id'])
                deleted_id = self.recognition.delete_tag(tag['tag_id'])
                self.assertEqual(tag['tag_id'], deleted_id)
示例#2
0
recognition = Recognition(host=args.host, key_file=args.key_file, verbose=args.verbose)

# List all tags
if args.tags:
    print "Listing all the tags"
    tags = recognition.list_tags()

# List tags
if args.tagged:
    print "Listing all the tags"
    tags = recognition.list_tagged(args.tag, args.object)

# Generic delete tag
elif args.delete:
    try:
        recognition.delete_tag(tag_name=args.tag, object_id=args.object)
    except:
        print 'Unable to delete tag id'

# Generic update tags
elif args.create:
    try:
        recognition.create_tag(args.tag)
    except:
        print 'Failed to create tag {}'.format(args.tag)

# Generic update tags
elif args.default:
    try:
        recognition.default_tags()
    except: