[REF] calendar: Migrated yml test cases to python unittest
This commit is contained in:
committed by
Jérome Maes
parent
6af6148a24
commit
e3560bd310
@@ -32,10 +32,6 @@ If you need to manage your meetings, you should install the CRM module.
|
||||
'views/calendar_views.xml',
|
||||
],
|
||||
'qweb': ['static/src/xml/*.xml'],
|
||||
'test': [
|
||||
'test/calendar_test.yml',
|
||||
'test/test_calendar_recurrent_event_case2.yml'
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
'auto_install': False,
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
-
|
||||
In Order to test calendar, I will first create One Simple Event with real data
|
||||
-
|
||||
!record {model: calendar.event, id: calendar_event_technicalpresentation0}:
|
||||
privacy: private
|
||||
start: '2011-04-30 16:00:00'
|
||||
stop: '2011-04-30 18:30:00'
|
||||
description: The Technical Presentation will cover following topics:\n* Creating OpenERP
|
||||
class\n* Views\n* Wizards\n* Workflows
|
||||
duration: 2.5
|
||||
location: OpenERP S.A.
|
||||
name: Technical Presentation
|
||||
-
|
||||
Now I will set recurrence for this event to occur monday and friday of week
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
data = {'fr': 1, 'mo': 1, 'interval': 1, 'rrule_type': 'weekly', 'end_type': 'end_date', 'final_date': '2011-05-31 00:00:00', 'recurrency' : True}
|
||||
self.write(cr, uid, [ref("calendar_event_technicalpresentation0")], data)
|
||||
-
|
||||
In order to check that recurrent events are views successfully in calendar view, I will open calendar view of events
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
self.fields_view_get(cr, uid, False, 'calendar', context)
|
||||
-
|
||||
In order to check that recurrent events are views successfully in calendar view, I will search for one of the recurrent event and count the number of events
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
ids = self.search(cr, uid, [('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')], context={'virtual_id': True} )
|
||||
assert len(ids) == 9, 'Wrong number of events found'
|
||||
-
|
||||
Now I move a virtual event, to see that a real event is well created and depending from the native recurrence
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
ids = self.search(cr, uid, [('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')], context={'virtual_id': True} )
|
||||
before = self.search(cr, uid, [('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')], context={'virtual_id': False})
|
||||
# We start by detach the event
|
||||
newid = self._detach_one_event(cr, uid,ids[1]).id
|
||||
self.write(cr, uid,[newid], {'name':'New Name','recurrency' : True}, context={'virtual_id': True})
|
||||
after = self.search(cr, uid, [('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')], context={'virtual_id': False})
|
||||
assert len(after) == len(before)+1, 'Wrong number of events found, after to have moved a virtual event'
|
||||
new_id = list(set(after)-set(before))[0]
|
||||
new_event = self.browse(cr,uid,new_id,context=context)
|
||||
assert new_event.recurrent_id == before[0], 'Recurrent_id not correctly passed to the new event'
|
||||
-
|
||||
Now I will make All day event and test it
|
||||
-
|
||||
!record {model: calendar.event, id: calendar_event_alldaytestevent0}:
|
||||
allday: 1
|
||||
privacy: confidential
|
||||
start: '2011-04-30 00:00:00'
|
||||
stop: '2011-04-30 00:00:00'
|
||||
description: 'All day technical test '
|
||||
location: School
|
||||
name: All day test event
|
||||
-
|
||||
In order to check reminder I will first create reminder
|
||||
-
|
||||
!record {model: calendar.alarm, id: res_alarm_daybeforeeventstarts0}:
|
||||
name: 1 Day before event starts
|
||||
duration: 1
|
||||
interval: days
|
||||
type: notification
|
||||
-
|
||||
Now I will assign this reminder to all day event
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
self.write(cr, uid, [ref("calendar_event_alldaytestevent0")], {'alarm_ids': [(6,0,[ref("res_alarm_daybeforeeventstarts0")])]})
|
||||
-
|
||||
I create a recuring rule for my event
|
||||
-
|
||||
!record {model: calendar.event, id: calendar.event_sprintreview1}:
|
||||
name: Begin of month meeting
|
||||
start: !eval time.strftime('%Y-%m-%d 12:00:00')
|
||||
stop: !eval time.strftime('%Y-%m-%d 18:00:00')
|
||||
recurrency: true
|
||||
rrule: FREQ=MONTHLY;INTERVAL=1;COUNT=12;BYDAY=1MO
|
||||
-
|
||||
I check that the attributes are set correctly
|
||||
-
|
||||
!assert {model: calendar.event, id: calendar.event_sprintreview1}:
|
||||
- rrule_type == 'monthly'
|
||||
- count == 12
|
||||
- month_by == 'day'
|
||||
- byday == '1'
|
||||
- week_list == 'MO'
|
||||
@@ -1,102 +0,0 @@
|
||||
-
|
||||
In order to test recurrent meetings in OpenERP, I create meetings with different recurrency using different test cases.
|
||||
-
|
||||
I create a recurrent meeting with daily recurrency and fixed amount of time.
|
||||
-
|
||||
!record {model: calendar.event, id: calendar_event_testmeeting0}:
|
||||
count: 5
|
||||
start: '2011-04-13 11:04:00'
|
||||
stop: '2011-04-13 12:04:00'
|
||||
day: 0.0
|
||||
duration: 1.0
|
||||
name: Test Meeting
|
||||
recurrency: true
|
||||
recurrent_id: 0.0
|
||||
rrule_type: daily
|
||||
-
|
||||
I search for all the recurrent meetings.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
meeting_ids = self.search(cr, uid, [('id', 'in', [ref('calendar_event_testmeeting0')]),('start','>=','2011-03-13'), ('stop', '<=', '2011-05-13')], context={'virtual_id': True})
|
||||
assert len(meeting_ids) == 5, 'Recurrent daily meetings are not created !'
|
||||
-
|
||||
I create a weekly meeting till a particular end date.
|
||||
-
|
||||
!record {model: calendar.event, id: calendar_event_reviewcodewithprogrammer0}:
|
||||
start: '2011-04-18 11:47:00'
|
||||
stop: '2011-04-18 12:47:00'
|
||||
day: 0.0
|
||||
duration: 1.0
|
||||
final_date: '2011-04-30'
|
||||
end_type: end_date
|
||||
fr: true
|
||||
mo: true
|
||||
th: true
|
||||
tu: true
|
||||
we: true
|
||||
name: Review code with programmer
|
||||
recurrency: true
|
||||
recurrent_id: 0
|
||||
rrule_type: weekly
|
||||
-
|
||||
I search for all the recurrent weekly meetings.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
meeting_ids = self.search(cr, uid, [('id', 'in', [ref('calendar_event_reviewcodewithprogrammer0')]),('start','>=','2011-03-13'), ('stop', '<=', '2011-05-13')], context={'virtual_id': True})
|
||||
assert len(meeting_ids) == 10, 'Recurrent weekly meetings are not created !'
|
||||
-
|
||||
I want to schedule a meeting every month for Sprint review.
|
||||
-
|
||||
!record {model: calendar.event, id: calendar_event_sprintreview0}:
|
||||
count: 12
|
||||
start: '2011-04-01 12:01:00'
|
||||
stop: '2011-04-01 13:01:00'
|
||||
day: 1
|
||||
duration: 1.0
|
||||
name: Sprint Review
|
||||
recurrency: true
|
||||
recurrent_id: 0.0
|
||||
rrule_type: monthly
|
||||
-
|
||||
I search for all the recurrent monthly meetings.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
meeting_ids = self.search(cr, uid, [('id', 'in', [ref('calendar_event_sprintreview0')]),('start','>=','2011-03-01'), ('stop', '<=', '2012-05-13')], context={'virtual_id': True})
|
||||
assert len(meeting_ids) == 12, 'Recurrent monthly meetings are not created !'
|
||||
-
|
||||
I change name of my monthly Sprint Review meeting.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
idval = '%d-%s' % (ref('calendar_event_sprintreview0'), '20110901130100')
|
||||
self.write(cr, uid, [idval], {'name': 'Sprint Review for google modules'})
|
||||
-
|
||||
I check whether all the records are edited or not.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
meeting_ids = self.search(cr, uid, [('id', 'in', [ref('calendar_event_sprintreview0')]),('start','>=','2011-03-01'), ('stop', '<=', '2012-05-13')], context={'virtual_id': True})
|
||||
meetings = self.browse(cr, uid, meeting_ids, context)
|
||||
for meeting in meetings:
|
||||
assert meeting.name == 'Sprint Review for google modules', 'Name not changed for id: %s' %meeting.id
|
||||
-
|
||||
I change description of my weekly meeting Review code with programmer.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
idval = '%d-%s' % (ref('calendar_event_sprintreview0'), '20110425124700')
|
||||
self.write(cr, uid, [idval], {'description': 'Review code of the module: sync_google_calendar.'})
|
||||
-
|
||||
I check whether that all the records of this recurrence has been edited.
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
meeting_ids = self.search(cr, uid, [('recurrent_id', '=', ref('calendar_event_sprintreview0'))], context)
|
||||
meetings = self.browse(cr, uid, meeting_ids, context)
|
||||
for meeting in meetings:
|
||||
assert meeting.description == 'Review code of the module: sync_google_calendar.', 'Description not changed for id: %s' %meeting.id
|
||||
-
|
||||
I update the description of two meetings, and check that both have been updated
|
||||
-
|
||||
!python {model: calendar.event}: |
|
||||
DESCRIPTION = "Some description"
|
||||
ids = [ref('calendar_event_testmeeting0'), ref('calendar_event_sprintreview0')]
|
||||
self.write(cr, uid, ids, {'description': DESCRIPTION}, context=context)
|
||||
for i, event in enumerate(self.browse(cr, uid, ids, context)):
|
||||
assert event.description == DESCRIPTION, "Event %d has not been updated" % i
|
||||
@@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_calendar
|
||||
from . import test_calendar_recurrent_event_case2
|
||||
@@ -0,0 +1,99 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestCalendar(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCalendar, self).setUp()
|
||||
|
||||
self.CalendarEvent = self.env['calendar.event']
|
||||
# In Order to test calendar, I will first create One Simple Event with real data
|
||||
self.event_tech_presentation = self.CalendarEvent.create({
|
||||
'privacy': 'private',
|
||||
'start': '2011-04-30 16:00:00',
|
||||
'stop': '2011-04-30 18:30:00',
|
||||
'description': 'The Technical Presentation will cover following topics:\n* Creating Odoo class\n* Views\n* Wizards\n* Workflows',
|
||||
'duration': 2.5,
|
||||
'location': 'Odoo S.A.',
|
||||
'name': 'Technical Presentation'
|
||||
})
|
||||
|
||||
def test_calender_event(self):
|
||||
# Now I will set recurrence for this event to occur monday and friday of week
|
||||
data = {
|
||||
'fr': 1,
|
||||
'mo': 1,
|
||||
'interval': 1,
|
||||
'rrule_type': 'weekly',
|
||||
'end_type': 'end_date',
|
||||
'final_date': '2011-05-31 00:00:00',
|
||||
'recurrency': True
|
||||
}
|
||||
|
||||
self.event_tech_presentation.write(data)
|
||||
|
||||
# In order to check that recurrent events are views successfully in calendar view, I will open calendar view of events|
|
||||
self.CalendarEvent.fields_view_get(False, 'calendar')
|
||||
|
||||
# In order to check that recurrent events are views successfully in calendar view, I will search for one of the recurrent event and count the number of events
|
||||
rec_events = self.CalendarEvent.with_context({'virtual_id': True}).search([
|
||||
('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')
|
||||
])
|
||||
self.assertEqual(len(rec_events), 9, 'Wrong number of events found')
|
||||
|
||||
# Now I move a virtual event, to see that a real event is well created and depending from the native recurrence
|
||||
before = self.CalendarEvent.with_context({'virtual_id': False}).search([
|
||||
('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')
|
||||
])
|
||||
|
||||
# We start by detach the event
|
||||
newevent = rec_events[1].detach_recurring_event()
|
||||
newevent.with_context({'virtual_id': True}).write({'name': 'New Name', 'recurrency': True})
|
||||
after = self.CalendarEvent.with_context({'virtual_id': False}).search([
|
||||
('start', '>=', '2011-04-30 16:00:00'), ('start', '<=', '2011-05-31 00:00:00')
|
||||
])
|
||||
self.assertEqual(len(after), len(before) + 1, 'Wrong number of events found, after to have moved a virtual event')
|
||||
new_event = after - before
|
||||
self.assertEqual(new_event[0].recurrent_id, before.id, 'Recurrent_id not correctly passed to the new event')
|
||||
|
||||
# Now I will test All day event
|
||||
allday_event = self.CalendarEvent.create({
|
||||
'allday': 1,
|
||||
'privacy': 'confidential',
|
||||
'start': '2011-04-30 00:00:00',
|
||||
'stop': '2011-04-30 00:00:00',
|
||||
'description': 'All day technical test',
|
||||
'location': 'School',
|
||||
'name': 'All day test event'
|
||||
})
|
||||
|
||||
# In order to check reminder I will first create reminder
|
||||
res_alarm_day_before_event_starts = self.env['calendar.alarm'].create({
|
||||
'name': '1 Day before event starts',
|
||||
'duration': 1,
|
||||
'interval': 'days',
|
||||
'type': 'notification'
|
||||
})
|
||||
|
||||
# Now I will assign this reminder to all day event|
|
||||
allday_event.write({'alarm_ids': [(6, 0, [res_alarm_day_before_event_starts.id])]})
|
||||
|
||||
# I create a recuring rule for my event
|
||||
calendar_event_sprint_review = self.CalendarEvent.create({
|
||||
'name': 'Begin of month meeting',
|
||||
'start': fields.Date.today() + ' 12:00:00',
|
||||
'stop': fields.Date.today() + ' 18:00:00',
|
||||
'recurrency': True,
|
||||
'rrule': 'FREQ=MONTHLY;INTERVAL=1;COUNT=12;BYDAY=1MO'
|
||||
})
|
||||
|
||||
# I check that the attributes are set correctly
|
||||
self.assertEqual(calendar_event_sprint_review.rrule_type, 'monthly', 'rrule_type should be mothly')
|
||||
self.assertEqual(calendar_event_sprint_review.count, 12, 'rrule_type should be mothly')
|
||||
self.assertEqual(calendar_event_sprint_review.month_by, 'day', 'rrule_type should be mothly')
|
||||
self.assertEqual(calendar_event_sprint_review.byday, '1', 'rrule_type should be mothly')
|
||||
self.assertEqual(calendar_event_sprint_review.week_list, 'MO', 'rrule_type should be mothly')
|
||||
@@ -0,0 +1,98 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRecurrentEvent(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRecurrentEvent, self).setUp()
|
||||
|
||||
self.CalendarEvent = self.env['calendar.event']
|
||||
|
||||
def test_recurrent_meeting1(self):
|
||||
# In order to test recurrent meetings in Odoo, I create meetings with different recurrency using different test cases.
|
||||
# I create a recurrent meeting with daily recurrency and fixed amount of time.
|
||||
self.CalendarEvent.create({
|
||||
'count': 5,
|
||||
'start': '2011-04-13 11:04:00',
|
||||
'stop': '2011-04-13 12:04:00',
|
||||
'duration': 1.0,
|
||||
'name': 'Test Meeting',
|
||||
'recurrency': True,
|
||||
'rrule_type': 'daily'
|
||||
})
|
||||
# I search for all the recurrent meetings
|
||||
meetings_count = self.CalendarEvent.with_context({'virtual_id': True}).search_count([
|
||||
('start', '>=', '2011-03-13'), ('stop', '<=', '2011-05-13')
|
||||
])
|
||||
self.assertEqual(meetings_count, 5, 'Recurrent daily meetings are not created !')
|
||||
|
||||
def test_recurrent_meeting2(self):
|
||||
# I create a weekly meeting till a particular end date.
|
||||
self.CalendarEvent.create({
|
||||
'start': '2011-04-18 11:47:00',
|
||||
'stop': '2011-04-18 12:47:00',
|
||||
'day': 0.0,
|
||||
'duration': 1.0,
|
||||
'final_date': '2011-04-30',
|
||||
'end_type': 'end_date',
|
||||
'fr': True,
|
||||
'mo': True,
|
||||
'th': True,
|
||||
'tu': True,
|
||||
'we': True,
|
||||
'name': 'Review code with programmer',
|
||||
'recurrency': True,
|
||||
'rrule_type': 'weekly'
|
||||
})
|
||||
|
||||
# I search for all the recurrent weekly meetings.
|
||||
meetings_count = self.CalendarEvent.with_context({'virtual_id': True}).search_count([
|
||||
('start', '>=', '2011-03-13'), ('stop', '<=', '2011-05-13')
|
||||
])
|
||||
self.assertEqual(meetings_count, 10, 'Recurrent weekly meetings are not created !')
|
||||
|
||||
def test_recurrent_meeting3(self):
|
||||
#I want to schedule a meeting every month for Sprint review.
|
||||
self.calendar_event_sprint_review = self.CalendarEvent.create({
|
||||
'count': 12,
|
||||
'start': '2011-04-01 12:01:00',
|
||||
'stop': '2011-04-01 13:01:00',
|
||||
'day': 1,
|
||||
'duration': 1.0,
|
||||
'name': 'Sprint Review',
|
||||
'recurrency': True,
|
||||
'rrule_type': 'monthly'
|
||||
})
|
||||
|
||||
# I search for all the recurrent monthly meetings.
|
||||
meetings_count = self.CalendarEvent.with_context({'virtual_id': True}).search_count([
|
||||
('start', '>=', '2011-03-01'), ('stop', '<=', '2012-05-13')
|
||||
])
|
||||
self.assertEqual(meetings_count, 12, 'Recurrent weekly meetings are not created !')
|
||||
|
||||
# I change name of my monthly Sprint Review meeting.
|
||||
idval = '%d-%s' % (self.calendar_event_sprint_review.id, '20110901130100')
|
||||
self.CalendarEvent.browse(idval).write({'name': 'Sprint Review for google modules'})
|
||||
|
||||
# I check whether all the records are edited or not.
|
||||
meetings = self.CalendarEvent.with_context({'virtual_id': True}).search([
|
||||
('start', '>=', '2011-03-01'), ('stop', '<=', '2012-05-13')
|
||||
])
|
||||
for meeting in meetings:
|
||||
self.assertEqual(meeting.name, 'Sprint Review for google modules', 'Name not changed for id: %s' % meeting.id)
|
||||
|
||||
# I change description of my weekly meeting Review code with programmer.
|
||||
idval = '%d-%s' % (self.calendar_event_sprint_review.id, '20110425124700')
|
||||
self.CalendarEvent.browse(idval).write({'description': 'Review code of the module: sync_google_calendar.'})
|
||||
|
||||
# I check whether that all the records of this recurrence has been edited.
|
||||
meetings = self.CalendarEvent.search([('recurrent_id', '=', self.calendar_event_sprint_review.id)])
|
||||
for meeting in meetings:
|
||||
self.assertEqual(meeting.description, 'Review code of the module: sync_google_calendar.', 'Description not changed for id: %s' % meeting.id)
|
||||
|
||||
# I update the description of two meetings, and check that both have been updated
|
||||
self.calendar_event_sprint_review.write({'description': "Some description"})
|
||||
self.assertEqual(self.calendar_event_sprint_review.description, "Some description", "Event %d has not been updated" % self.calendar_event_sprint_review.id)
|
||||
Reference in New Issue
Block a user