Ejemplo n.º 1
0
    def test_create_all_fiches_new_fiche_no_mobile(self, send_fiche):
        '''
        Verify that a new fiche is created if none exists and has no mobile
        '''

        clic = migclic.clicrdv('prod')
        clic.group_id = 'deadbeef'
        clic.contact = {
            'skywalker, luke': {
                'nom': 'skywalker',
                'prenom': 'luke',
                'fixe': '01 01 01 01 01',
                'email': '*****@*****.**',
            }
        }
        clic.create_all_fiches()
        self.assertEquals(clic.stats['newly_created_fiches'], 1)
        self.assertEquals(clic.stats['found_contacts_in_fiches'], 0)
        new_fiche = clic.all_fiches['skywalker, luke']
        self.assertEquals(new_fiche['group_id'], 'deadbeef')
        self.assertEquals(new_fiche['firstname'], 'luke')
        self.assertEquals(new_fiche['lastname'], 'skywalker')
        self.assertEquals(new_fiche['firstphone'], '01 01 01 01 01')
        self.assertEquals(new_fiche['email'], '*****@*****.**')
        self.assertFalse(new_fiche['from_web'])
Ejemplo n.º 2
0
    def test_get_fiches(self, sess):
        '''
        Test fiche retrieval
        '''

        session = MagicMock()
        session.status_code = 200
        json_return = {
            'pro': {
                'group_id': 'deadbeef',
            },
            'records': [{
                'lastname': 'skywalker',
                'firstname': 'luke',
            }]
        }
        one_fiche = {'skywalker, luke': json_return['records'][0]}
        sess.return_value.post.return_value = session
        sess.return_value.post.return_value.json.return_value = json_return
        sess.return_value.get.return_value = session
        sess.return_value.get.return_value.json.return_value = json_return
        clic = migclic.clicrdv('prod')
        clic.session_open(self.auth)
        clic.get_fiches()
        self.assertIsNotNone(clic.ses)
        self.assertEquals(clic.all_fiches, one_fiche)
Ejemplo n.º 3
0
    def test_fiche_exists_does_not_exist(self):
        '''
        Test _fiche_exists if the contact does not exists
        '''

        clic = migclic.clicrdv('prod')
        clic.all_fiches = {'skywalker, luke': 'one entry'}
        ret = clic._fiche_exists({'nom': 'organa', 'prenom': 'leia'})
        self.assertFalse(ret)
Ejemplo n.º 4
0
    def test_fiche_exists_exist(self):
        '''
        Test _fiche_exists if the contact exists
        '''

        clic = migclic.clicrdv('prod')
        clic.all_fiches = {'skywalker, luke': 'one entry'}
        ret = clic._fiche_exists(self.contact)
        self.assertTrue(ret)
Ejemplo n.º 5
0
 def test_get_contacts(self, cred, build):
     '''
     Test contact retrieval
     '''
     cred.return_value = MagicMock()
     build.return_value.contactGroups.return_value.list.return_value.\
         execute.return_value = self.cgresult
     build.return_value.people.return_value.connections.return_value.\
         list.return_value.execute.return_value = self.ctcresult
     clic = migclic.clicrdv('test')
     clic.get_contacts()
     self.assertEquals(len(clic.contact), 3)
     self.assertEquals(len(clic.contact_by_email), 1)
Ejemplo n.º 6
0
    def test_session_open_resp_invalid(self, sess):
        '''
        Test session_open with invalid return code
        '''

        session = MagicMock()
        session.status_code = 404
        session.reason = 'Not found'
        session.text = '404 - Not Found'
        sess.return_value.post.return_value = session
        clic = migclic.clicrdv('prod')
        clic.session_open(self.auth)
        self.assertIsNone(clic.ses)
        self.assertIsNone(clic.group_id)
Ejemplo n.º 7
0
    def test_create_all_fiches_fiche_exists(self):
        '''
        Verify that no new fiche is created if it already exists
        '''

        clic = migclic.clicrdv('prod')
        clic.contact = {
            'skywalker, luke': {
                'nom': 'skywalker',
                'prenom': 'luke',
            }
        }
        clic.all_fiches = {'skywalker, luke': 'one entry'}
        clic.create_all_fiches()
        self.assertEquals(clic.stats['newly_created_fiches'], 0)
        self.assertEquals(clic.stats['found_contacts_in_fiches'], 1)
Ejemplo n.º 8
0
    def test_session_open_resp_ok(self, sess):
        '''
        Test session_open with valid return code
        '''

        session = MagicMock()
        session.status_code = 200
        json_return = {
            'pro': {
                'group_id': 'deadbeef',
            },
        }
        sess.return_value.post.return_value = session
        sess.return_value.post.return_value.json.return_value = json_return
        clic = migclic.clicrdv('prod')
        clic.session_open(self.auth)
        self.assertIsNotNone(clic.ses)
        self.assertEquals(clic.group_id, 'deadbeef')
        return clic
Ejemplo n.º 9
0
 def test_get_calendar(self, cred, build):
     '''
     Test calendar retrieval
     '''
     cred.return_value = MagicMock()
     build.return_value.contactGroups.return_value.list.return_value.\
         execute.return_value = self.cgresult
     build.return_value.people.return_value.connections.return_value.\
         list.return_value.execute.return_value = self.ctcresult
     build.return_value.events.return_value.list.return_value.\
         execute.return_value = self.calresult
     clic = migclic.clicrdv('test')
     clic.get_contacts()
     clic.get_calendar_entries()
     has_client = [
         clnt['email'] for clnt in clic.agenda if 'client' in clnt.keys()
     ]
     self.assertEquals(len(clic.agenda), 2)
     self.assertEquals(len(clic.contact_by_email), 1)
     self.assertEquals(has_client, ['*****@*****.**'])
Ejemplo n.º 10
0
    def test_get_fiches_nok(self, sess):
        '''
        Test fiche retrieval
        '''

        session = MagicMock()
        session.status_code = 200
        json_return = {
            'pro': {
                'group_id': 'deadbeef',
            },
        }
        sess.return_value.post.return_value = session
        sess.return_value.post.return_value.json.return_value = json_return
        sess.return_value.get.return_value = session
        sess.return_value.get.return_value.json.return_value = json_return
        clic = migclic.clicrdv('prod')
        clic.session_open(self.auth)
        session.status_code = 404
        clic.get_fiches()
        self.assertIsNotNone(clic.ses)
        self.assertIsNone(clic.all_fiches)