Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
susu105 committed Jun 23, 2020
1 parent 0162d73 commit 5c9775a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
3 changes: 2 additions & 1 deletion som_generationkwh/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from emission_tests import *
from investment_tests import *
from partner_tests import *
from somenergia_soci_tests import *
from somenergia_soci_tests import *
from test_wizard_baixa_soci import *
11 changes: 11 additions & 0 deletions som_generationkwh/tests/generation_data_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@
<field name="state">approved</field>
<field name="smtpport">587</field>
</record>

<record model="poweremail.core_accounts" id="info_som_mail_account">
<field name="email_id">info@somenergia.coop</field>
<field name="company">yes</field>
<field name="smtpserver">smtp.mandrillapp.com</field>
<field name="send_pref">html</field>
<field name="name">Info Som Energia</field>
<field name="state">approved</field>
<field name="smtpport">587</field>
</record>

<record id="res_partner_inversor1" model="res.partner">
<field name="bank_inversions" ref="partner_bank1"></field>
</record>
Expand Down
97 changes: 97 additions & 0 deletions som_generationkwh/tests/test_wizard_baixa_soci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
from destral import testing
from destral.transaction import Transaction
from osv import osv
from datetime import datetime
import poweremail
import mock


class TestWizardBaixaSoci(testing.OOTestCase):
def setUp(self):
self.txn = Transaction().start(self.database)
self.cursor = self.txn.cursor
self.uid = self.txn.user
self.Investment = self.openerp.pool.get('generationkwh.investment')
self.IrModelData = self.openerp.pool.get('ir.model.data')
self.Soci = self.openerp.pool.get('somenergia.soci')
self.WizardBaixaSoci = self.openerp.pool.get('wizard.baixa.soci')
self.AccountObj = self.openerp.pool.get('poweremail.core_accounts')

def tearDown(self):
self.txn.stop()

def test__baixa_soci__allowed(self):
member_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'soci_0003'
)[1]
self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
context = {'active_ids':[member_id]}

wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
self.WizardBaixaSoci.baixa_soci(self.cursor, self.uid, wiz_id, context=context, send_mail=False)

baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
self.assertTrue(baixa)

def test__baixa_soci__notAllowed(self):
member_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
)[1]
self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
context = {'active_ids':[member_id]}

wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
self.WizardBaixaSoci.baixa_soci(self.cursor, self.uid, wiz_id, context=context, send_mail=False)

baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
self.assertFalse(baixa)

@mock.patch("poweremail.poweremail_send_wizard.poweremail_send_wizard.send_mail")
def test__baixa_soci_and_send_mail__allowed(self, mocked_send_mail):
member_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'soci_0003'
)[1]
self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
context = {'active_ids':[member_id]}

wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
self.WizardBaixaSoci.baixa_soci(self.cursor, self.uid, wiz_id, context=context, send_mail=True)

baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
self.assertTrue(baixa)

template_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'email_baixa_soci'
)[1]

email_from = self.AccountObj.search(self.cursor, self.uid, [('name', '=', 'Info Som Energia')])[0]

expected_ctx = {
'active_ids': [member_id],
'active_id': member_id,
'template_id': template_id,
'src_model': 'somenergia.soci',
'src_rec_ids': [member_id],
'from': email_from,
'state': 'single',
'priority': '0',
}

mocked_send_mail.assert_called_with(self.cursor, self.uid, mock.ANY, expected_ctx)

@mock.patch("poweremail.poweremail_send_wizard.poweremail_send_wizard.send_mail")
def test__baixa_soci_and_send_mail__notAllowed(self, mocked_send_mail):
member_id = self.IrModelData.get_object_reference(
self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
)[1]
self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})

context = {'active_ids':[member_id]}

wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
self.WizardBaixaSoci.baixa_soci_and_send_mail(self.cursor, self.uid, wiz_id, context=context)

baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
self.assertFalse(baixa)
mocked_send_mail.assert_not_called()

0 comments on commit 5c9775a

Please sign in to comment.