def setUp(self): trytond.tests.test_tryton.install_module('sugarcrm') self.Party = POOL.get('party.party') self.PartyAddress = POOL.get('party.address') self.SugarcrmConfig = POOL.get('sugarcrm.configuration') self.Attachment = POOL.get('ir.attachment') self.connection_patcher = patch('sugarcrm.Sugarcrm', autospec=True) PatchedConnection = self.connection_patcher.start() self.module_patcher = patch('sugarcrm.SugarModule', autospec=True) PatchedModule = self.module_patcher.start() self.entry_patcher = patch('sugarcrm.SugarEntry', autospec=True) PatchedEntry = self.entry_patcher.start() connection = sugarcrm.Sugarcrm('Some url', 'admin', 'admin') PatchedConnection.return_value.modules = { 'Opportunities': sugarcrm.SugarModule(connection, 'Opportunities'), 'Accounts': sugarcrm.SugarModule(connection, 'Accounts'), 'Contacts': sugarcrm.SugarModule(connection, 'Contacts'), 'Documents': sugarcrm.SugarModule(connection, 'Documents'), 'EmailAddresses': sugarcrm.SugarModule(connection, 'EmailAddresses'), } PatchedConnection.return_value.get_relationships = \ lambda *args, **kwargs: { 'entry_list': [] } PatchedConnection.return_value.modules['Opportunities']._name = \ 'Opportunities' PatchedConnection.return_value.modules['Opportunities']._fields = { 'id': None } PatchedConnection.return_value.modules['Opportunities']._connection = \ connection PatchedConnection.return_value.modules['Accounts']._name = 'Accounts' PatchedConnection.return_value.modules['Contacts']._name = 'Contacts' PatchedConnection.return_value.modules['Documents']._name = 'Documents' PatchedConnection.return_value.modules['EmailAddresses']._name = \ 'EmailAddresses' PatchedConnection.return_value.get_entries_count = lambda x, y: { 'result_count': '1' } PatchedModule.return_value = sugarcrm.SugarModule( connection, 'Opportunities') PatchedModule.return_value._search.return_value = [ sugarcrm.SugarEntry('Opportunities') ] values = {'id': 'some-ramdom-id', 'name': 'John Doe'} PatchedEntry.return_value = sugarcrm.SugarEntry(values) PatchedEntry.return_value.__getitem__ = lambda _, field: values[field] PatchedEntry.return_value.__setitem__ = lambda _, field, value: True PatchedEntry.return_value.get_related = lambda *args, **kwargs: []
def setUp(self): BaseTests.setUp(self) contacts = self._conn.modules['Contacts'] contact = sugarcrm.SugarEntry(contacts) contact['first_name'] = 'John' contact['last_name'] = 'Smith' contact['birthdate'] = '1970-01-10' contact.save() self._contact = contact
def test_relationship(self): accounts = self._conn.modules['Accounts'] account = sugarcrm.SugarEntry(accounts) account['name'] = 'John\'s Account' account['website'] = 'http//www.hash-tag.com.ar/' account.save() self._contact.relate(account) self._contact.save() account.save() rel_accounts = self._contact.get_related(accounts) rel_account = rel_accounts[0] self.assertEqual(account['name'], rel_account['name']) rel_contacts = account.get_related(self._conn.modules['Contacts']) rel_contact = rel_contacts[0] self.assertEqual(self._contact['first_name'], rel_contact['first_name']) account['deleted'] = 1 account.save()