This file is indexed.

/usr/lib/python2.7/dist-packages/trytond/modules/calendar/tests/scenario_calendar.py is in tryton-modules-calendar 3.4.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python
#This file is part of Tryton.  The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from argparse import ArgumentParser
from urlparse import urlparse
import unittest
import sys
import datetime

from dateutil.relativedelta import relativedelta
import caldav
import vobject
from proteus import config, Model, Wizard


def install_module(name, config):
    Module = Model.get('ir.module.module')
    module, = Module.find([('name', '=', name)])
    if module.state != 'installed':
        Module.install([module.id], config.context)
        Wizard('ir.module.module.install_upgrade').execute('upgrade')


def configure_user(login, config):
    User = Model.get('res.user')
    users = User.find([('login', '=', login)])
    email = '%s@example.com' % login
    if not users:
        User(login=login, name=login, email=email).save()
    else:
        user, = users
        user.email = email
        user.save()


def create_calendar(login, user, config):
    Calendar = Model.get('calendar.calendar')
    User = Model.get('res.user')
    current_user, = User.find([('login', '=', login)])
    main_user, = User.find([('login', '=', user)])
    for calendar in Calendar.find([('owner', '=', login)]):
        calendar.write_users.append(User(main_user.id))
        calendar.save()
        calendar.delete()
    calendar = Calendar(name=login, owner=current_user)
    if login != 'bar':
        calendar.read_users.append(main_user)
    calendar.save()


class TestCase(unittest.TestCase):

    def setUp(self):
        self.client = caldav.DAVClient(URL)
        self.principal = caldav.Principal(self.client, URL)
        self.calendar, = [x for x in self.principal.calendars()
            if x.url.path.endswith(user)]

    def test0010calendar(self):
        'Test calendar'
        calendar, _ = self.principal.calendars()

    def test0020create_event(self):
        'Create event'
        ical = vobject.iCalendar()
        vevent = ical.add('vevent')
        vevent.add('summary')
        vevent.summary.value = 'Test event'
        vevent.add('dtstart')
        vevent.dtstart.value = (datetime.datetime.now()
            + relativedelta(months=1))
        vevent.add('dtend')
        vevent.dtend.value = datetime.datetime.now() + relativedelta(months=1,
            hours=1)
        caldav.Event(self.client, data=ical.serialize(),
            parent=self.calendar).save()

    def test0030search_event(self):
        'Search date'
        events = self.calendar.date_search(datetime.datetime.now(),
            datetime.datetime.now() + relativedelta(months=2))
        self.assertEqual(len(events), 1)
        events = self.calendar.date_search(
            datetime.datetime.now() - relativedelta(months=1),
            datetime.datetime.now())
        self.assertEqual(len(events), 0)

    def test0040get_event(self):
        'Get event'
        event = self.calendar.events()[0]
        event.load()
        self.assertEqual(event.url, self.calendar.event(event.id).url)

    def test0050create_event_attendee(self):
        'Create event with attendee'
        ical = vobject.iCalendar()
        vevent = ical.add('vevent')
        vevent.add('summary')
        vevent.summary.value = 'Test event with attendee'
        vevent.add('dtstart')
        vevent.dtstart.value = datetime.datetime.now() + relativedelta(days=10)
        vevent.add('dtend')
        vevent.dtend.value = datetime.datetime.now() + relativedelta(days=10,
            hours=4)
        vevent.add('organizer')
        vevent.organizer.value = '%s@example.com' % user
        attendees = []
        for name in ('foo', 'bar'):
            attendee = vobject.base.ContentLine('ATTENDEE', [], '')
            attendee.partstat_param = 'TENTATIVE'
            attendee.value = 'MAILTO:%s@example.com' % name
            attendees.append(attendee)
        vevent.attendee_list = attendees
        caldav.Event(self.client, data=ical.serialize(),
            parent=self.calendar).save()

        Event = Model.get('calendar.event')
        owner_event, = Event.find([
                ('calendar.owner.email', '=', '%s@example.com' % user),
                ('summary', '=', vevent.summary.value),
                ])
        attendee_event, = Event.find([
                ('calendar.owner.email', '=', 'foo@example.com'),
                ])
        self.assertEqual(attendee_event.uuid, owner_event.uuid)

    def test0060update_attendee_status(self):
        'Update status of attendee'
        for event in self.calendar.events():
            event.load()
            value = event.instance.vevent.summary.value
            if value == 'Test event with attendee':
                break
        for attendee in event.instance.vevent.attendee_list:
            attendee.partstat_param = 'accepted'
        event.save()

        Event = Model.get('calendar.event')
        attendee_event, = Event.find([
                ('calendar.owner.email', '=', 'foo@example.com'),
                ])
        for attendee in attendee_event.attendees:
            self.assertEqual(attendee.status, 'accepted')

    def test0070delete_attendee(self):
        'Delete attendee'
        for event in self.calendar.events():
            event.load()
            value = event.instance.vevent.summary.value
            if value == 'Test event with attendee':
                break
        event.instance.vevent.attendee_list = []
        event.save()

        Event = Model.get('calendar.event')
        self.assertEqual(Event.find([
                    ('calendar.owner.email', '=', 'foo@example.com'),
                    ]), [])

if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument('--xmlrpc', dest='xmlrpc', metavar='URL',
        help='use trytond XML-RPC at URL')
    parser.add_argument('--url', dest='url', metavar='URL',
        help='use calendar at URL')
    options = parser.parse_args()
    config = config.set_xmlrpc(options.xmlrpc)
    xmlrpc_user = urlparse(options.xmlrpc).username
    user = urlparse(options.url).username
    assert xmlrpc_user == user
    assert user != 'foo'
    install_module('calendar', config)
    configure_user(user, config)
    configure_user('foo', config)
    configure_user('bar', config)
    create_calendar(user, user, config)
    create_calendar('foo', user, config)
    create_calendar('bar', user, config)
    URL = options.url
    unittest.main(argv=sys.argv[:1])