Esempio n. 1
0
    def get_sugarcrm_connection(self):
        """
        Returns an authenticated instance of the SugarCRM client

        :return: SugarCRM connection object
        """
        if not all([self.url, self.username, self.password]):
            self.raise_user_error('sugarcrm_settings_missing')

        return sugarcrm.Sugarcrm(self.url, self.username, self.password)
Esempio n. 2
0
    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: []
Esempio n. 3
0
 def setUp(self):
     self._conn = sugarcrm.Sugarcrm(sugarcrm_config.url,
                                    sugarcrm_config.username,
                                    sugarcrm_config.password)
Esempio n. 4
0
 def test_login(self):
     response = sugarcrm.Sugarcrm(sugarcrm_config.url,
                                  sugarcrm_config.username,
                                  sugarcrm_config.password)
     self.assertNotEqual(response._session, '')
#    Copyright 2012 Luis Barrueco
#
#    This file is part of sugarcrm/python_webservices_library.
#

import sugarcrm

# This is the URL for the v4 REST API in your SugarCRM server.
url = 'http://127.0.0.1/sugarcrm-6.5.0/service/v4/rest.php'
username = '******'
password = '******'

# This way you log-in to your SugarCRM instance.
conn = sugarcrm.Sugarcrm(url, username, password)

# This way you query all the Contacts in your CRM...
query = conn.modules['Contacts'].query()
# ... but we just show the first ten of them.
for contact in query[:10]:
    print contact['first_name'] + ' ' + contact['last_name']

# OUTPUT:
# Darrin Adger
# Gilbert Adkins
# Maritza Bail
# Morris Balmer
# Polly Barahona
# Claude Barksdale
# Merrill Barragan
# Aimee Bassler
# Rosario Bassler