def test_04_get_classes(self, mock_client): """ Test that get_classes returns the classes parameter of the OdooModelCollection object. :param mock_client: A mocked out version of erppeek.Client :return: """ test_omc = OdooModelCollection() test_omc.classes = ['class'] self.assertListEqual(['class'], test_omc.get_classes()) mock_client.stop()
def test_05_get_relation_models(self, mock_client): """ Test that get_relation_models returns the relation_models parameter of the OdooModelCollection object. :param mock_client: A mocked out version of erppeek.Client :return: """ test_omc = OdooModelCollection() test_omc.relation_models = ['model'] self.assertListEqual(['model'], test_omc.get_relation_models()) mock_client.stop()
def test_06_convert_collection_to_json(self): """ Test json conversion is returned correctly. :return: """ # Mock Up mock_client = MagicMock() model_1 = MagicMock() model_1._name = 'test.model.1' model_1.fields = MagicMock(return_value={ 'm1_f1': {'type': 'boolean'}, 'm1_f2': {'type': 'char'}, 'm1_f3': {'type': 'many2one', 'relation': 'test.model.2'}, }) model_2 = MagicMock() model_2._name = 'test.model.2' model_2.fields = MagicMock(return_value={ 'm2_f1': {'type': 'text'}, 'm2_f2': {'type': 'many2many', 'relation': 'test.model.3'}, 'm2_f3': {'type': 'one2many', 'relation': 'test.model.1'}, }) mock_client.models = MagicMock(return_value={'Model 1': model_1, 'Model 2': model_2}) mock_erppeek = MagicMock(return_value=mock_client) with patch('erppeek.Client', mock_erppeek): test_omc = OdooModelCollection() json = [ { "fields": [{"type": "text", "name": "m2_f1"}], "name": "test.model.2", "relations": [ {"model": "test.model.1", "type": "one2many", "name": "m2_f3"}, {"model": "test.model.3", "type": "many2many", "name": "m2_f2"} ] }, { "fields": [{"type": "char", "name": "m1_f2"}, {"type": "boolean", "name": "m1_f1"}], "name": "test.model.1", "relations": [ {"model": "test.model.2", "type": "many2one", "name": "m1_f3"} ] }, { "fields": [], "name": "test.model.3", "relations": [] }] self.assertListEqual(eval(test_omc.convert_collection_to_json()), json)
def test_06_convert_collection_to_json(self): """ Test json conversion is returned correctly. :return: """ # Mock Up mock_client = MagicMock() mock_model = MagicMock() model_1 = MagicMock() model_1._name = 'test.model.1' model_1.fields = MagicMock(return_value={ 'm1_f1': {'type': 'boolean'}, 'm1_f2': {'type': 'char'}, 'm1_f3': {'type': 'many2one', 'relation': 'test.model.2'}, }) model_2 = MagicMock() model_2._name = 'test.model.2' model_2.fields = MagicMock(return_value={ 'm2_f1': {'type': 'text'}, 'm2_f2': {'type': 'many2many', 'relation': 'test.model.3'}, 'm2_f3': {'type': 'one2many', 'relation': 'test.model.1'}, }) mock_client.models = MagicMock(return_value={'Model 1': model_1, 'Model 2': model_2}) mock_client.model = MagicMock(return_value=mock_model) mock_erppeek = MagicMock(return_value=mock_client) def search(domain): if domain[0][2] == 'test.model.1': return [1] elif domain[0][2] == 'test.model.2': return [2] else: return [0] def browse(model_id): model_browse = MagicMock() if model_id == 1: model = MagicMock() model.model = 'test.model.2' model_browse.inherited_model_ids = [model] else: model_browse.inherited_model_ids = [] return model_browse mock_model.search = search mock_model.browse = browse with patch('erppeek.Client', mock_erppeek): test_omc = OdooModelCollection() json = [ { "fields": [{"type": "text", "name": "m2_f1"}], "name": "test.model.2", "relations": [ {"model": "test.model.1", "type": "one2many", "name": "m2_f3"}, {"model": "test.model.3", "type": "many2many", "name": "m2_f2"} ] }, { "fields": [{"type": "char", "name": "m1_f2"}, {"type": "boolean", "name": "m1_f1"}], "name": "test.model.1", "relations": [ {"model": "test.model.2", "type": "many2one", "name": "m1_f3"} ] }, { "fields": [], "name": "test.model.3", "relations": [] }] self.assertListEqual(eval(test_omc.convert_collection_to_json()), json)