Exemplo n.º 1
0
    def test_to_dict(self):
        '''method to test State.to_dict()'''
        # testing key equality
        state_dict = State().to_dict()
        my_dict = self.State.to_dict()
        state_keys = state_dict.keys()
        my_keys = my_dict.keys()
        self.assertEqual(state_keys, my_keys)

        # testing attrs in dicts
        self.assertTrue(hasattr(state_dict, '__class__'))

        # test that __dict__ & .to_dict() are diff
        self.assertIsNot(self.State.__dict__, self.State.to_dict())
Exemplo n.º 2
0
class Test_06_State_To_Dict(unittest.TestCase):
    '''Test State To_Dict Method'''
    def setUp(self):
        '''Set Up'''
        self.dct1 = State().to_dict()
        self.dct2 = State().to_dict()

    def test_01_is_dict_type(self):
        '''Test to_dict simple'''
        self.assertIsInstance(
            self.dct1, dict, "Failed to_dict does not prodice dictionary"
            " type")

    def test_02_required_keys(self):
        '''Test for proper output format'''
        key_list = self.dct1.keys()
        self.assertIn('id', key_list, "Error 'id' not in to_dict() output")
        self.assertIn('created_at', key_list,
                      "Error 'created_by' not in to_dict() output")
        self.assertIn('updated_at', key_list,
                      "Error 'updated_at' not in to_dict() output")
        self.assertIn('__class__', key_list,
                      "Error '__class__' not in to_dict() output")

    def test_03_value_type(self):
        '''Test for proper value format'''
        value_list = self.dct1.values()
        for e in value_list:
            self.assertIsInstance(e, str, "Error to_dict has non-str value")

    def test_04_classname_value(self):
        '''Test if class name is properly stored'''
        self.assertEqual('State', self.dct1['__class__'],
                         "Error incorrect key for BaseModel")

    def test_05_different_to_dict(self):
        '''Test for different outputs'''
        self.assertNotEqual(self.dct1, self.dct2,
                            "Error to_dict does not produce different output")