[IMP][TEST] membership: tests updates

- update yml tests, crashing because of changes in the accounting
+ some light cleaning
- add python unittests, because those are way cooler than yml
This commit is contained in:
Thibault Delavallée
2015-08-12 14:42:31 +02:00
parent 0deef9b7f5
commit 7fc8577238
4 changed files with 122 additions and 0 deletions
@@ -120,6 +120,8 @@
membership_line = membership_lines[0]
refund_id = invoice_refund_pool.create(cr, uid, {'description': 'Refund of Membership', 'filter_refund': 'refund'}, {'active_id': membership_line.account_invoice_id.id})
invoice_refund_pool.invoice_refund(cr, uid, [refund_id], {'active_id': membership_line.account_invoice_id.id, 'active_ids': [membership_line.account_invoice_id.id]})
membership_line.account_invoice_id.journal_id.write({'update_posted': True})
membership_line.account_invoice_id.signal_workflow('invoice_cancel')
- |
I'm checking "Current membership state" of "Seagate". It is an "Cancelled Member" or not.
-
+3
View File
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from openerp.addons.membership.tests import test_membership
+35
View File
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
import datetime
from dateutil.relativedelta import relativedelta
from openerp.tests import common
class TestMembershipCommon(common.TransactionCase):
def setUp(self):
super(TestMembershipCommon, self).setUp()
# Usefull models
Product = self.env['product.product']
Partner = self.env['res.partner']
# Test memberships
self.membership_1 = Product.create({
'membership': True,
'membership_date_from': datetime.date.today() + relativedelta(days=-2),
'membership_date_to': datetime.date.today() + relativedelta(months=1),
'name': 'Basic Limited',
'type': 'service',
'list_price': 100.00,
})
# Test people
self.partner_1 = Partner.create({
'name': 'Ignasse Reblochon',
})
self.partner_2 = Partner.create({
'name': 'Martine Poulichette',
'free_member': True,
})
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
import datetime
from dateutil.relativedelta import relativedelta
from openerp.addons.membership.tests.common import TestMembershipCommon
class TestMembership(TestMembershipCommon):
def test_old_membership(self):
self.membership_1.write({
'membership_date_from': datetime.date.today() + relativedelta(years=-2),
'membership_date_to': datetime.date.today() + relativedelta(years=-1),
})
self.partner_1.create_membership_invoice(product_id=self.membership_1.id, datas={'amount': 75.0})
self.assertEqual(
self.partner_1.membership_state, 'old',
'membership: outdated subscription should put member in old state')
def test_paid_membership(self):
self.assertEqual(
self.partner_1.membership_state, 'none',
'membership: default membership status of partners should be None')
# subscribes to a membership
self.partner_1.create_membership_invoice(product_id=self.membership_1.id, datas={'amount': 75.0})
# checks for invoices
invoice = self.env['account.invoice'].search([('partner_id', '=', self.partner_1.id)], limit=1)[0]
self.assertEqual(
invoice.state, 'draft',
'membership: new subscription should create a draft invoice')
self.assertEqual(
invoice.invoice_line_ids[0].product_id, self.membership_1,
'membership: new subscription should create a line with the membership as product')
self.assertEqual(
invoice.invoice_line_ids[0].price_unit, 75.0,
'membership: new subscription should create a line with the given price instead of product price')
self.assertEqual(
self.partner_1.membership_state, 'waiting',
'membership: new membership should be in waiting state')
# the invoice is open -> customer goes to invoiced status
invoice.signal_workflow('invoice_open')
self.assertEqual(
self.partner_1.membership_state, 'invoiced',
'membership: after opening the invoice, customer should be in invoiced status')
# the invoice is paid -> customer goes to paid status
bank_journals = self.env['account.journal'].search([('type', '=', 'bank')])
invoice.pay_and_reconcile(bank_journals[0], invoice.amount_total)
self.assertEqual(
self.partner_1.membership_state, 'paid',
'membership: after paying the invoice, customer should be in paid status')
# check second partner then associate them
self.assertEqual(
self.partner_2.membership_state, 'free',
'membership: free member customer should be in free state')
self.partner_2.write({'free_member': False, 'associate_member': self.partner_1.id})
self.assertEqual(
self.partner_2.membership_state, 'paid',
'membership: associated customer should be in paid state')
def test_cancel_membership(self):
self.assertEqual(
self.partner_1.membership_state, 'none',
'membership: default membership status of partners should be None')
# subscribes to a membership
self.partner_1.create_membership_invoice(product_id=self.membership_1.id, datas={'amount': 75.0})
# checks for invoices
invoice = self.env['account.invoice'].search([('partner_id', '=', self.partner_1.id)], limit=1)[0]
# the invoice is canceled -> membership state of the customer goes to canceled
invoice.signal_workflow('invoice_cancel')
self.assertEqual(invoice.state, 'cancel')
self.assertEqual(self.partner_1.membership_state, 'canceled')