def test_with_human(self):
     field = Field('/fake', 'fake', {0: 'Off', 1: 'On'})
     field._convert_to_human = MagicMock(return_value='On')
     ret = field._build_get_return(self.INT_RETURN_VALUE)
     self.assertTrue('raw' in ret)
     self.assertTrue('human' in ret)
     self.assertEqual(ret['human'], 'On')
Exemplo n.º 2
0
 def test_with_human(self):
     field = Field('/fake', 'fake', {0: 'Off', 1: 'On'})
     field._convert_to_human = MagicMock(return_value='On')
     ret = field._build_get_return(self.INT_RETURN_VALUE)
     self.assertTrue('raw' in ret)
     self.assertTrue('human' in ret)
     self.assertEqual(ret['human'], 'On')
class TestConvertToHuman(BaseTestCase):
    def setUp(self):
        self.field = Field('/fake', 'fake', {0: 'Off', 1: 'On', 'foo': 'Foo'})

    def test_convert_int_success(self):
        ret = self.field._convert_to_human(0)
        self.assertEqual(ret, 'Off')

    def test_convert_int_fail(self):
        self.assertRaises(AttributeError, self.field._convert_to_human, 3)

    def test_convert_string_success(self):
        ret = self.field._convert_to_human('foo')
        self.assertEqual(ret, 'Foo')

    def test_convert_string_fail(self):
        self.assertRaises(AttributeError, self.field._convert_to_human, 'bar')
class TestConvertToHuman(BaseTestCase):
    def setUp(self):
        self.field = Field('/fake', 'fake', {
            0 : 'Off',
            1 : 'On',
            'foo' : 'Foo'
        })

    def test_convert_int_success(self):
        ret = self.field._convert_to_human(0)
        self.assertEqual(ret, 'Off')

    def test_convert_int_fail(self):
        self.assertRaises(AttributeError, self.field._convert_to_human, 3)

    def test_convert_string_success(self):
        ret = self.field._convert_to_human('foo')
        self.assertEqual(ret, 'Foo')

    def test_convert_string_fail(self):
        self.assertRaises(AttributeError, self.field._convert_to_human, 'bar')
 def setUp(self):
     self.field = Field('/fake', 'fake', {
         0 : 'Off',
         1 : 'On',
         'foo' : 'Foo'
     })
 def setUp(self):
     self.field = Field('/fake', 'fake', {0: 'Off', 1: 'On', 'foo': 'Foo'})
 def test_with_name(self):
     field = Field('/fake', 'fake')
     ret = field._build_get_return(self.INT_RETURN_VALUE)
     self.assertTrue('raw' in ret)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret['raw'], self.INT_RETURN_VALUE['fake'])
 def test_without_name(self):
     field = Field('/fake', None)
     ret = field._build_get_return(self.NO_NAME_RETURN_VALUE)
     self.assertTrue('raw' in ret)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret['raw'], self.NO_NAME_RETURN_VALUE)
Exemplo n.º 9
0
 def test_without_name(self):
     field = Field('/fake', None)
     ret = field._build_get_return(self.NO_NAME_RETURN_VALUE)
     self.assertTrue('raw' in ret)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret['raw'], self.NO_NAME_RETURN_VALUE)
Exemplo n.º 10
0
 def test_with_name(self):
     field = Field('/fake', 'fake')
     ret = field._build_get_return(self.INT_RETURN_VALUE)
     self.assertTrue('raw' in ret)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret['raw'], self.INT_RETURN_VALUE['fake'])