コード例 #1
0
 def test_has_options(self):
     mock_field = MagicMock(name='MockField')
     vlist = mock_field.foreign_model.objects.all.return_value.values_list
     vlist.return_value = ['the option']
     with patch.object(crd.random, 'randint') as randint:
         randint.return_value = 9
         result = crd.foreign_key_or_free_text_generator(mock_field)
         self.assertEqual('the option', result)
コード例 #2
0
 def test_has_options(self):
     mock_field = MagicMock(name='MockField')
     vlist = mock_field.foreign_model.objects.all.return_value.values_list
     vlist.return_value = ['the option']
     with patch.object(crd.random, 'randint') as randint:
         randint.return_value = 9
         result = crd.foreign_key_or_free_text_generator(mock_field)
         self.assertEqual('the option', result)
コード例 #3
0
 def test_free_text(self):
     mock_field = MagicMock(name='MockField')
     vlist = mock_field.foreign_model.objects.all.return_value.values_list
     vlist.return_value = ['the option']
     with patch.object(crd.random, 'randint') as randint:
         randint.return_value = 1
         with patch.object(crd, 'string_generator') as stringgen:
             stringgen.return_value = 'the string'
             result = crd.foreign_key_or_free_text_generator(mock_field)
             stringgen.assert_called_with(mock_field)
             self.assertEqual('the string', result)
コード例 #4
0
 def test_free_text(self):
     mock_field = MagicMock(name='MockField')
     vlist = mock_field.foreign_model.objects.all.return_value.values_list
     vlist.return_value = ['the option']
     with patch.object(crd.random, 'randint') as randint:
         randint.return_value = 1
         with patch.object(crd, 'string_generator') as stringgen:
             stringgen.return_value = 'the string'
             result = crd.foreign_key_or_free_text_generator(mock_field)
             stringgen.assert_called_with(mock_field)
             self.assertEqual('the string', result)