<s> import mock <EOL> import os <EOL> import unittest <EOL> from codalab . common import ( <EOL> State , <EOL> UsageError , <EOL> ) <EOL> from codalab . lib import ( <EOL> canonicalize , <EOL> spec_util , <EOL> ) <EOL> class CanonicalizeTest ( unittest . TestCase ) : <EOL> def test_get_bundle_uuid ( self ) : <EOL> tester = self <EOL> worksheet_uuid = '<STR_LIT>' <EOL> missing_name = '<STR_LIT>' <EOL> unique_name = '<STR_LIT>' <EOL> ambiguous_name = '<STR_LIT>' <EOL> bundle_counts = { <EOL> missing_name : <NUM_LIT:0> , <EOL> unique_name : <NUM_LIT:1> , <EOL> ambiguous_name : <NUM_LIT:2> , <EOL> } <EOL> test_uuids = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> test_uuid = test_uuids [ <NUM_LIT:0> ] <EOL> class MockBundleModel ( object ) : <EOL> def get_bundle_uuids ( self , conditions , max_results , count = False ) : <EOL> tester . assertEqual ( set ( conditions ) , set ( [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> name = conditions [ '<STR_LIT:name>' ] . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) <EOL> tester . assertIn ( name , bundle_counts ) <EOL> count = bundle_counts [ name ] <EOL> return [ <EOL> test_uuids [ i ] <EOL> for i in range ( count ) <EOL> ] <EOL> model = MockBundleModel ( ) <EOL> user_id = None <EOL> uuid = spec_util . generate_uuid ( ) <EOL> self . assertEqual ( uuid , canonicalize . get_bundle_uuid ( model , user_id , worksheet_uuid , uuid ) ) <EOL> self . assertEqual ( test_uuid , canonicalize . get_bundle_uuid ( model , user_id , worksheet_uuid , unique_name ) ) <EOL> self . assertRaises ( <EOL> UsageError , <EOL> lambda : canonicalize . get_bundle_uuid ( model , user_id , worksheet_uuid , missing_name ) , <EOL> ) <EOL> self . assertRaises ( <EOL> UsageError , <EOL> lambda : canonicalize . get_bundle_uuid ( model , user_id , worksheet_uuid , '<STR_LIT>' ) , <EOL> ) </s>
