#NEWLINE# def test_form( self ) : #NEWLINE# #INDENT# 'Test that the form has choices from R.metric_slugs, and that\n        providing a ``category`` argument sets initial values.' #NEWLINE# config = { #NEWLINE# #INDENT# 'return_value.metric_slugs.return_value' : [ 'test-slug' ] , #NEWLINE# 'return_value._category_slugs.return_value' : [ 'test-slug' ] , #NEWLINE# #UNINDENT# } #NEWLINE# with patch ( 'redis_metrics.forms.R' , ** config ) as mock_R : #NEWLINE# #INDENT# form = MetricCategoryForm ( ) #NEWLINE# self . assertFalse ( form . fields [ 'metrics' ] . required ) #NEWLINE# mock_R . assert_has_calls ( [ call ( ) , call ( ) . metric_slugs ( ) ] ) #NEWLINE# self . assertEqual ( form . fields [ 'metrics' ] . choices , [ ( 'test-slug' , 'test-slug' ) ] ) #NEWLINE# self . assertEqual ( form . fields [ 'metrics' ] . initial , None ) #NEWLINE# self . assertEqual ( form . fields [ 'category_name' ] . initial , None ) #NEWLINE# self . assertFalse ( mock_R . _category_slugs . called ) #NEWLINE# mock_R . reset_mock ( ) #NEWLINE# initial = { #NEWLINE# #INDENT# 'category_name' : 'Sample Category' , #NEWLINE# #UNINDENT# } #NEWLINE# form = MetricCategoryForm ( initial = initial ) #NEWLINE# self . assertFalse ( form . fields [ 'metrics' ] . required ) #NEWLINE# self . assertEqual ( form . fields [ 'metrics' ] . initial , [ 'test-slug' ] ) #NEWLINE# self . assertEqual ( form . fields [ 'category_name' ] . initial , 'Sample Category' ) #NEWLINE# r = mock_R . return_value #NEWLINE# r . _category_slugs . assert_called_once_with ( 'Sample Category' )