Ejemplo n.º 1
0
 def test_send_with_files(self):
     file1 = BytesIO(get_binay('blablabla\blabla.'))
     file2 = open(join(dirname(__file__), 'static', 'lucterios.mailing',
                       'images', 'config_mail.png'),
                  mode='rb')
     try:
         configSMTP('localhost', 1025)
         self.assertEqual(0, self.server.count())
         self.assertEqual(True, will_mail_send())
         send_email('*****@*****.**', 'send with files', '2 files sent!',
                    [('filename1.txt', file1), ('filename2.png', file2)])
         self.assertEqual(1, self.server.count())
         self.assertEqual('*****@*****.**',
                          self.server.get(0)[1])
         self.assertEqual(['*****@*****.**'], self.server.get(0)[2])
         msg, msg_f1, msg_f2 = self.server.check_first_message(
             'send with files', 3)
         self.assertEqual('text/plain', msg.get_content_type())
         self.assertEqual('base64', msg.get('Content-Transfer-Encoding',
                                            ''))
         self.assertEqual('2 files sent!', decode_b64(msg.get_payload()))
         self.assertEqual(None, self.server.smtp.auth_params)
         self.assertTrue('filename1.txt' in msg_f1.get('Content-Type', ''),
                         msg_f1.get('Content-Type', ''))
         self.assertEqual('blablabla\blabla.',
                          decode_b64(msg_f1.get_payload()))
         self.assertTrue('filename2.png' in msg_f2.get('Content-Type', ''),
                         msg_f2.get('Content-Type', ''))
         file2.seek(0, SEEK_END)
         self.assertEqual(file2.tell(),
                          len(b64decode(msg_f2.get_payload())))
     finally:
         file1.close()
         file2.close()
Ejemplo n.º 2
0
 def test_send_withdouble(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     send_email(
         ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
         'send correct config',
         'Yessss!!!',
         cclist=['*****@*****.**', '*****@*****.**', '*****@*****.**'],
         bcclist=['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual([
         '*****@*****.**', '*****@*****.**', '*****@*****.**',
         '*****@*****.**', '*****@*****.**', '*****@*****.**'
     ],
                      self.server.get(0)[2])
     msg, = self.server.check_first_message(
         'send correct config', 1, {
             'To': '[email protected], [email protected], [email protected]',
             'Cc': '[email protected], [email protected]'
         })
     self.assertEqual('text/plain', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual('Yessss!!!', decode_b64(msg.get_payload()))
     self.assertEqual(None, self.server.smtp.auth_params)
Ejemplo n.º 3
0
 def test_email_message(self):
     configSMTP('localhost', 1025)
     self.factory.xfer = MessageAddModify()
     self.call(
         '/lucterios.mailing/messageAddModify', {
             'SAVE':
             'YES',
             'subject':
             'new message',
             'body':
             '{[b]}{[font color="blue"]}All{[/font]}{[/b]}{[newline]}Small message to give a big {[u]}kiss{[/u]} ;){[newline]}{[newline]}Bye'
         }, False)
     self.factory.xfer = MessageValidRecipient()
     self.call(
         '/lucterios.mailing/messageValidRecipient', {
             'message': '1',
             'modelname': 'contacts.Individual',
             'CRITERIA': 'genre||8||1'
         }, False)
     self.factory.xfer = MessageValidRecipient()
     self.call('/lucterios.mailing/messageValidRecipient', {
         'message': '1',
         'modelname': 'contacts.LegalEntity',
         'CRITERIA': ''
     }, False)
     self.factory.xfer = MessageTransition()
     self.call('/lucterios.mailing/messageValid', {
         'message': '1',
         'CONFIRME': 'YES'
     }, False)
     server = TestReceiver()
     server.start(1025)
     try:
         self.assertEqual(0, server.count())
         self.factory.xfer = MessageEmail()
         self.call('/lucterios.mailing/messageEmail', {
             'message': '1',
             'CONFIRME': 'YES'
         }, False)
         self.assert_observer('core.dialogbox', 'lucterios.mailing',
                              'messageEmail')
         self.assertEqual(2, server.count())
         self.assertEqual('*****@*****.**', server.get(0)[1])
         self.assertEqual(['*****@*****.**'],
                          server.get(0)[2])
         msg, = server.check_first_message('new message', 1)
         self.assertEqual('text/html', msg.get_content_type())
         self.assertEqual('base64', msg.get('Content-Transfer-Encoding',
                                            ''))
         self.assertEqual(
             '<html><body><b><font color="blue">All</font></b><br/>Small message to give a big <u>kiss</u> ;)<br/><br/>Bye</body></html>',
             decode_b64(msg.get_payload()))
     finally:
         server.stop()
Ejemplo n.º 4
0
 def test_send_with_auth(self):
     if six.PY3:
         self.server.smtp.with_authentificate = True
         configSMTP('localhost', 1025, 0, 'toto', 'abc123')
         self.assertEqual(0, self.server.count())
         self.assertEqual(True, will_mail_send())
         send_email('*****@*****.**', 'send with auth', 'OK!')
         self.assertEqual(1, self.server.count())
         msg, = self.server.check_first_message('send with auth', 1)
         self.assertEqual('OK!', decode_b64(msg.get_payload()))
         self.assertEqual(['', 'toto', 'abc123'],
                          self.server.smtp.auth_params)
Ejemplo n.º 5
0
 def test_user_change_password(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.factory.xfer = UsersEdit()
     self.call(
         '/CORE/usersEdit', {
             'SAVE': 'YES',
             'user_actif': '1',
             "password_generate": 'o',
             "email": '*****@*****.**'
         }, False)
     self.assert_observer('core.acknowledge', 'CORE', 'usersEdit')
     self.assertEqual(1, self.server.count())
     msg, = self.server.check_first_message('Mot de passe de connexion', 1)
     self.assertEqual('text/plain', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     content_msg = decode_b64(msg.get_payload())
     self.assertEqual(
         'Confirmation de connexion à votre application:\nAlias:admin\nMot de passe:',
         decode_b64(msg.get_payload())[:72])
     password = content_msg[72:].strip()
     user = LucteriosUser.objects.get(id=1)
     self.assertTrue(user.check_password(password), content_msg)
Ejemplo n.º 6
0
 def test_send_html(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     send_email('*****@*****.**', 'send html',
                '<html><body><h1>Yessss!!!</h1></body></html>')
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual(['*****@*****.**'], self.server.get(0)[2])
     msg, = self.server.check_first_message('send html', 1)
     self.assertEqual('text/html', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual('<html><body><h1>Yessss!!!</h1></body></html>',
                      decode_b64(msg.get_payload()))
Ejemplo n.º 7
0
 def test_send_copyhimself(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     send_email('*****@*****.**',
                'send correct config',
                'Yessss!!!',
                withcopy=True)
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual(['*****@*****.**', '*****@*****.**'],
                      self.server.get(0)[2])
     msg, = self.server.check_first_message('send correct config', 1)
     self.assertEqual('text/plain', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual('Yessss!!!', decode_b64(msg.get_payload()))
     self.assertEqual(None, self.server.smtp.auth_params)
Ejemplo n.º 8
0
    def test_pwd_forget(self):
        configSMTP('localhost', 1025)
        self.factory.xfer = AskPassword()
        self.call('/lucterios.CORE/askPassword', {}, False)
        self.assert_observer('core.custom', 'lucterios.CORE', 'askPassword')
        self.assert_count_equal('CONTEXT', 0)
        self.assert_count_equal('COMPONENTS/*', 4)
        self.assert_xml_equal('COMPONENTS/EDIT[@name="email"]', None)
        self.assert_count_equal('ACTIONS/ACTION', 2)

        server = TestReceiver()
        server.start(1025)
        try:
            self.assertEqual(0, server.count())

            self.factory.xfer = AskPasswordAct()
            self.call('/lucterios.CORE/askPasswordAct',
                      {"email": "*****@*****.**"}, False)
            self.assert_observer('core.acknowledge', 'lucterios.CORE',
                                 'askPasswordAct')
            self.assertEqual(0, server.count())

            self.factory.xfer = AskPasswordAct()
            self.call('/lucterios.CORE/askPasswordAct',
                      {"email": "*****@*****.**"}, False)
            self.assert_observer('core.acknowledge', 'lucterios.CORE',
                                 'askPasswordAct')
            self.assertEqual(1, server.count())
            self.assertEqual('*****@*****.**', server.get(0)[1])
            self.assertEqual(['*****@*****.**'], server.get(0)[2])
            msg, = server.check_first_message('Mot de passe de connexion', 1)
            self.assertEqual('text/plain', msg.get_content_type())
            self.assertEqual('base64', msg.get('Content-Transfer-Encoding',
                                               ''))
            message = decode_b64(msg.get_payload())
            self.assertEqual(
                'Confirmation de connexion à votre application:\nAlias:jack\nMot de passe:',
                message[:71])
            password = message[71:]
        finally:
            server.stop()
        user = LucteriosUser.objects.get(id=2)
        self.assertTrue(user.check_password(password), 'success after change')
Ejemplo n.º 9
0
 def test_tryemail_success(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.factory.xfer = SendEmailTry()
     self.call('/lucterios.mailing/sendEmailTry', {}, False)
     self.assert_observer('core.dialogbox', 'lucterios.mailing',
                          'sendEmailTry')
     self.assert_xml_equal('TEXT', 'Courriel envoyé, veuillez le vérifier.')
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual(['*****@*****.**'],
                      self.server.get(0)[2])
     msg, = self.server.check_first_message('Essai de courriel', 1)
     self.assertEqual('text/plain', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual(
         'Courriel envoyé pour vérifier la configuration\n\nWoldCompany\n',
         decode_b64(msg.get_payload())[:60])
Ejemplo n.º 10
0
    def test_new_account_with_structure(self):
        param = Parameter.objects.get(name='contacts-createaccount')
        param.value = '2'
        param.save()
        configSMTP('localhost', 1025)

        self.factory.xfer = CreateAccount()
        self.call('/lucterios.contact/createAccount', {}, False)
        self.assert_observer('core.custom', 'lucterios.contact',
                             'createAccount')
        self.assert_count_equal('CONTEXT', 0)
        self.assert_count_equal('COMPONENTS/*', 16)
        self.assert_xml_equal('COMPONENTS/SELECT[@name="genre"]', '1')
        self.assert_xml_equal('COMPONENTS/EDIT[@name="firstname"]', None)
        self.assert_xml_equal('COMPONENTS/EDIT[@name="lastname"]', None)
        self.assert_xml_equal('COMPONENTS/EDIT[@name="username"]', None)
        self.assert_xml_equal('COMPONENTS/EDIT[@name="email"]', None)
        self.assert_xml_equal('COMPONENTS/EDIT[@name="legalentity"]', None)
        self.assert_xml_equal('COMPONENTS/CAPTCHA[@name="captcha"]', None)
        self.assert_count_equal('ACTIONS/ACTION', 2)

        server = TestReceiver()
        server.start(1025)
        try:
            self.factory.xfer = CreateAccount()
            self.call(
                '/lucterios.contacts/createAccount', {
                    'SAVE': 'YES',
                    'firstname': 'pierre',
                    'genre': 1,
                    'legalentity': 'Chez moi',
                    'lastname': 'DUPONT',
                    'username': '******',
                    'email': '*****@*****.**'
                }, False)
            self.assert_observer('core.dialogbox', 'lucterios.contacts',
                                 'createAccount')
            self.assert_xml_equal(
                'TEXT',
                'Votre compte est créé{[br/]}Vous allez recevoir un courriel avec votre mot de passe.'
            )
            self.assertEqual(1, server.count())
            self.assertEqual('*****@*****.**', server.get(0)[1])
            self.assertEqual(['*****@*****.**'], server.get(0)[2])
            msg, = server.check_first_message('Mot de passe de connexion', 1)
            self.assertEqual('text/plain', msg.get_content_type())
            self.assertEqual('base64', msg.get('Content-Transfer-Encoding',
                                               ''))
            message = decode_b64(msg.get_payload())
            self.assertEqual(
                'Confirmation de connexion à votre application:\nAlias:pierre\nMot de passe:',
                message[:73])
            password = message[73:]
        finally:
            server.stop()
        user = LucteriosUser.objects.get(id=3)
        self.assertEqual('pierre', user.username)
        self.assertTrue(user.check_password(password), 'success after change')
        cont = Individual.objects.filter(user=user)
        self.assertEqual(1, len(cont))
        self.assertEqual('pierre', cont[0].firstname)
        moral = LegalEntity.objects.filter(
            responsability__individual__user=user)
        self.assertEqual(1, len(moral))
        self.assertEqual('Chez moi', moral[0].name)
        self.assertEqual('*****@*****.**', moral[0].email)
        self.assertEqual('---', moral[0].address)
        self.assertEqual('---', moral[0].postal_code)
        self.assertEqual('---', moral[0].city)
        self.assertEqual(2, len(LegalEntity.objects.all()))