| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## $Id: conference_test.py,v 1.20 2008/04/24 16:59:57 jose Exp $ |
|---|
| 4 | ## |
|---|
| 5 | ## This file is part of CDS Indico. |
|---|
| 6 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 7 | ## |
|---|
| 8 | ## CDS Indico is free software; you can redistribute it and/or |
|---|
| 9 | ## modify it under the terms of the GNU General Public License as |
|---|
| 10 | ## published by the Free Software Foundation; either version 2 of the |
|---|
| 11 | ## License, or (at your option) any later version. |
|---|
| 12 | ## |
|---|
| 13 | ## CDS Indico is distributed in the hope that it will be useful, but |
|---|
| 14 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | ## General Public License for more details. |
|---|
| 17 | ## |
|---|
| 18 | ## You should have received a copy of the GNU General Public License |
|---|
| 19 | ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., |
|---|
| 20 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | from MaKaC.common.db import DBMgr |
|---|
| 24 | from MaKaC import conference |
|---|
| 25 | from MaKaC import user |
|---|
| 26 | from MaKaC.user import Avatar |
|---|
| 27 | from MaKaC.conference import Conference, Category |
|---|
| 28 | from MaKaC.conference import Session,Contribution,SessionSlot |
|---|
| 29 | from MaKaC.conference import ContributionParticipation |
|---|
| 30 | from MaKaC.conference import SCIndex |
|---|
| 31 | from MaKaC.errors import MaKaCError |
|---|
| 32 | from MaKaC.schedule import BreakTimeSchEntry |
|---|
| 33 | from datetime import datetime,timedelta |
|---|
| 34 | from pytz import timezone |
|---|
| 35 | |
|---|
| 36 | import unittest |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | def setup_module(): |
|---|
| 40 | DBMgr.getInstance().startRequest() |
|---|
| 41 | |
|---|
| 42 | def teardown_module(): |
|---|
| 43 | DBMgr.getInstance().abort() |
|---|
| 44 | DBMgr.getInstance().endRequest() |
|---|
| 45 | |
|---|
| 46 | #From testCategories.py |
|---|
| 47 | class TestCategories(): |
|---|
| 48 | |
|---|
| 49 | def testBasicAddAndRemoveConferences(self): |
|---|
| 50 | #creation of basic category structure over which perform the tests |
|---|
| 51 | croot=conference.Category() |
|---|
| 52 | c1=conference.Category() |
|---|
| 53 | croot._addSubCategory(c1) |
|---|
| 54 | c2=conference.Category() |
|---|
| 55 | croot._addSubCategory(c2) |
|---|
| 56 | c1_1=conference.Category() |
|---|
| 57 | c1._addSubCategory(c1_1) |
|---|
| 58 | #checks adding a conference increases the conference number of the |
|---|
| 59 | # involved categories |
|---|
| 60 | creator=user.Avatar() |
|---|
| 61 | conf1=conference.Conference(creator) |
|---|
| 62 | conf1.setId("0") |
|---|
| 63 | c1_1._addConference(conf1) |
|---|
| 64 | assert (c1_1.getNumConferences()==1) |
|---|
| 65 | assert (c1.getNumConferences()==1) |
|---|
| 66 | assert (c2.getNumConferences()==0) |
|---|
| 67 | assert (croot.getNumConferences()==1) |
|---|
| 68 | conf2=conference.Conference(creator) |
|---|
| 69 | conf2.setId("1") |
|---|
| 70 | c2._addConference(conf2) |
|---|
| 71 | assert (c1_1.getNumConferences()==1) |
|---|
| 72 | assert (c1.getNumConferences()==1) |
|---|
| 73 | assert (c2.getNumConferences()==1) |
|---|
| 74 | assert (croot.getNumConferences()==2) |
|---|
| 75 | c1_1.removeConference(conf1) |
|---|
| 76 | assert (c1_1.getNumConferences()==0) |
|---|
| 77 | assert (c1.getNumConferences()==0) |
|---|
| 78 | assert (c2.getNumConferences()==1) |
|---|
| 79 | assert (croot.getNumConferences()==1) |
|---|
| 80 | c2.removeConference(conf2) |
|---|
| 81 | assert (c1_1.getNumConferences()==0) |
|---|
| 82 | assert (c1.getNumConferences()==0) |
|---|
| 83 | assert (c2.getNumConferences()==0) |
|---|
| 84 | assert (croot.getNumConferences()==0) |
|---|
| 85 | |
|---|
| 86 | def testAddAndRemoveSubCategories(self): |
|---|
| 87 | #checks that the conference counter works fine when adding a new |
|---|
| 88 | # sub-category |
|---|
| 89 | croot=conference.Category() |
|---|
| 90 | c1=conference.Category() |
|---|
| 91 | c2=conference.Category() |
|---|
| 92 | croot._addSubCategory(c2) |
|---|
| 93 | creator=user.Avatar() |
|---|
| 94 | conf0=conference.Conference(creator) |
|---|
| 95 | conf0.setId("0") |
|---|
| 96 | conf1=conference.Conference(creator) |
|---|
| 97 | conf1.setId("1") |
|---|
| 98 | c1._addConference(conf0) |
|---|
| 99 | c1._addConference(conf1) |
|---|
| 100 | assert (croot.getNumConferences()==0) |
|---|
| 101 | assert (c1.getNumConferences()==2) |
|---|
| 102 | assert (c2.getNumConferences()==0) |
|---|
| 103 | croot._addSubCategory(c1) |
|---|
| 104 | assert (croot.getNumConferences()==2) |
|---|
| 105 | assert (c1.getNumConferences()==2) |
|---|
| 106 | assert (c2.getNumConferences()==0) |
|---|
| 107 | c1_1=conference.Category() |
|---|
| 108 | c1._addSubCategory(c1_1) |
|---|
| 109 | assert (croot.getNumConferences()==2) |
|---|
| 110 | assert (c1.getNumConferences()==2) |
|---|
| 111 | assert (c1_1.getNumConferences()==2) |
|---|
| 112 | assert (c2.getNumConferences()==0) |
|---|
| 113 | c1_1.move(c2) |
|---|
| 114 | assert (croot.getNumConferences()==2) |
|---|
| 115 | assert (c1.getNumConferences()==0) |
|---|
| 116 | assert (c1_1.getNumConferences()==2) |
|---|
| 117 | |
|---|
| 118 | assert (c2.getNumConferences()==2) |
|---|
| 119 | croot._removeSubCategory(c1) |
|---|
| 120 | assert (croot.getNumConferences()==2) |
|---|
| 121 | assert (c1.getNumConferences()==0) |
|---|
| 122 | assert (c1_1.getNumConferences()==2) |
|---|
| 123 | assert (c2.getNumConferences()==2) |
|---|
| 124 | c2._removeSubCategory(c1_1) |
|---|
| 125 | assert (croot.getNumConferences()==0) |
|---|
| 126 | assert (c1.getNumConferences()==0) |
|---|
| 127 | assert (c1_1.getNumConferences()==2) |
|---|
| 128 | assert (c2.getNumConferences()==0) |
|---|
| 129 | |
|---|
| 130 | #from testConferences.py |
|---|
| 131 | class TestBasicManagement(unittest.TestCase): |
|---|
| 132 | """Tests the basic conference management functions |
|---|
| 133 | """ |
|---|
| 134 | |
|---|
| 135 | def setUp( self ): |
|---|
| 136 | self._creator=Avatar() |
|---|
| 137 | self._creator.setId("creator") |
|---|
| 138 | self._conf=Conference(self._creator) |
|---|
| 139 | self._conf.setTimezone('UTC') |
|---|
| 140 | |
|---|
| 141 | category=conference.Category() |
|---|
| 142 | self._conf.addOwner(category) |
|---|
| 143 | |
|---|
| 144 | confTZ = self._conf.getTimezone() |
|---|
| 145 | sd = timezone(confTZ).localize(datetime(2000, 1, 1)) |
|---|
| 146 | sdUTC = sd.astimezone(timezone('UTC')) |
|---|
| 147 | ed = timezone(confTZ).localize(datetime(2020, 1, 1)) |
|---|
| 148 | edUTC = ed.astimezone(timezone('UTC')) |
|---|
| 149 | self._conf.setDates(sdUTC,edUTC) |
|---|
| 150 | |
|---|
| 151 | def testAddRemoveSessions(self): |
|---|
| 152 | s1,s2=Session(),Session() |
|---|
| 153 | self._conf.addSession(s1) |
|---|
| 154 | self._conf.addSession(s2) |
|---|
| 155 | self.assert_(s1 in self._conf.getSessionList()) |
|---|
| 156 | self.assert_(s1==self._conf.getSessionById(s1.getId())) |
|---|
| 157 | self.assert_(s2 in self._conf.getSessionList()) |
|---|
| 158 | self.assert_(s2==self._conf.getSessionById(s2.getId())) |
|---|
| 159 | self._conf.removeSession(s1) |
|---|
| 160 | self.assert_(s1 not in self._conf.getSessionList()) |
|---|
| 161 | self.assert_(None==self._conf.getSessionById(s1.getId())) |
|---|
| 162 | self.assert_(s2 in self._conf.getSessionList()) |
|---|
| 163 | self.assert_(s2==self._conf.getSessionById(s2.getId())) |
|---|
| 164 | c1,c2,c3=Contribution(),Contribution(),Contribution() |
|---|
| 165 | self._conf.addSession(s1) |
|---|
| 166 | s1.addContribution(c1) |
|---|
| 167 | s1.addContribution(c2) |
|---|
| 168 | s2.addContribution(c3) |
|---|
| 169 | self.assert_(s1 in self._conf.getSessionList()) |
|---|
| 170 | self.assert_(s1==self._conf.getSessionById(s1.getId())) |
|---|
| 171 | self.assert_(s2 in self._conf.getSessionList()) |
|---|
| 172 | self.assert_(s2==self._conf.getSessionById(s2.getId())) |
|---|
| 173 | self.assert_(c1 in self._conf.getContributionList()) |
|---|
| 174 | self.assert_(c2 in self._conf.getContributionList()) |
|---|
| 175 | self.assert_(c3 in self._conf.getContributionList()) |
|---|
| 176 | self.assert_(c1 in s1.getContributionList()) |
|---|
| 177 | self.assert_(c2 in s1.getContributionList()) |
|---|
| 178 | self.assert_(c3 in s2.getContributionList()) |
|---|
| 179 | self._conf.removeSession(s1) |
|---|
| 180 | self.assert_(s1 not in self._conf.getSessionList()) |
|---|
| 181 | self.assert_(s2 in self._conf.getSessionList()) |
|---|
| 182 | self.assert_(c1 in self._conf.getContributionList()) |
|---|
| 183 | self.assert_(c2 in self._conf.getContributionList()) |
|---|
| 184 | self.assert_(c3 in self._conf.getContributionList()) |
|---|
| 185 | self.assert_(c1 not in s1.getContributionList()) |
|---|
| 186 | self.assert_(c1.getSession()==None) |
|---|
| 187 | self.assert_(c2.getSession()==None) |
|---|
| 188 | self.assert_(c2 not in s1.getContributionList()) |
|---|
| 189 | self.assert_(c3 in s2.getContributionList()) |
|---|
| 190 | |
|---|
| 191 | class TestModifyConferenceDates(unittest.TestCase): |
|---|
| 192 | """Tests different scenarios which can occur when modifying conference start |
|---|
| 193 | and end dates |
|---|
| 194 | """ |
|---|
| 195 | def setUp(self): |
|---|
| 196 | a = Avatar() |
|---|
| 197 | a.setId("creator") |
|---|
| 198 | self._conf=Conference(a) |
|---|
| 199 | self._conf.setTimezone('UTC') |
|---|
| 200 | |
|---|
| 201 | category=conference.Category() |
|---|
| 202 | self._conf.addOwner(category) |
|---|
| 203 | |
|---|
| 204 | sd=datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 205 | ed=datetime(2004, 01, 05, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 206 | self._conf.setDates(sd,ed) |
|---|
| 207 | |
|---|
| 208 | def testSessions(self): |
|---|
| 209 | s1=Session() |
|---|
| 210 | s1.setDates(datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC')),datetime(2004, 01, 01, 12, 00, tzinfo=timezone('UTC'))) |
|---|
| 211 | self._conf.addSession(s1) |
|---|
| 212 | s2=Session() |
|---|
| 213 | s2.setDates(datetime(2004, 01, 01, 15, 00, tzinfo=timezone('UTC')),datetime(2004, 01, 01, 18, 00, tzinfo=timezone('UTC'))) |
|---|
| 214 | self._conf.addSession(s2) |
|---|
| 215 | #checks that modifying conference dates which does not affect to |
|---|
| 216 | # sessions is allowed |
|---|
| 217 | self._conf.setStartDate(datetime(2004, 01, 01, 9, 00, tzinfo=timezone('UTC'))) |
|---|
| 218 | self._conf.setEndDate(datetime(2004, 01, 01, 19, 00, tzinfo=timezone('UTC'))) |
|---|
| 219 | #if a session is affected an error should be reported |
|---|
| 220 | #self.assertRaises(MaKaCError,self._conf.setStartDate,datetime(2004, 01, 01, 10, 01, tzinfo=timezone('UTC'))) |
|---|
| 221 | #self.assertRaises(MaKaCError,self._conf.setEndDate,datetime(2004, 01, 01, 17, 00, tzinfo=timezone('UTC'))) |
|---|
| 222 | |
|---|
| 223 | def testEntries(self): |
|---|
| 224 | c1,c2=Contribution(),Contribution() |
|---|
| 225 | b=BreakTimeSchEntry() |
|---|
| 226 | self._conf.addContribution(c1) |
|---|
| 227 | self._conf.addContribution(c2) |
|---|
| 228 | self._conf.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 229 | self._conf.getSchedule().addEntry(b) |
|---|
| 230 | self._conf.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 231 | #checks that modifying conference dates which does not affect to |
|---|
| 232 | # entries is allowed |
|---|
| 233 | self._conf.setStartDate(datetime(2004, 01, 01, 9, 00, tzinfo=timezone('UTC'))) |
|---|
| 234 | self._conf.setEndDate(datetime(2004, 01, 01, 19, 00, tzinfo=timezone('UTC'))) |
|---|
| 235 | #if any entry is affected an error should be reported |
|---|
| 236 | #self.assertRaises(MaKaCError,self._conf.setStartDate,datetime(2004, 01, 01, 10, 01, tzinfo=timezone('UTC'))) |
|---|
| 237 | #self.assertRaises(MaKaCError,self._conf.setEndDate,datetime(2004, 01, 01, 10, 20, tzinfo=timezone('UTC'))) |
|---|
| 238 | |
|---|
| 239 | class TestSchedule(unittest.TestCase): |
|---|
| 240 | """Tests the schedule management functions |
|---|
| 241 | """ |
|---|
| 242 | |
|---|
| 243 | def setUp( self ): |
|---|
| 244 | a = Avatar() |
|---|
| 245 | a.setId("creator") |
|---|
| 246 | self._conf=Conference(a) |
|---|
| 247 | self._conf.setTimezone('UTC') |
|---|
| 248 | sd=datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 249 | ed=datetime(2004, 01, 05, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 250 | self._conf.setDates(datetime(2000, 01, 01, tzinfo=timezone('UTC')),datetime(2020, 01, 01, tzinfo=timezone('UTC'))) |
|---|
| 251 | self._conf.setScreenStartDate(sd) |
|---|
| 252 | self._conf.setScreenEndDate(ed) |
|---|
| 253 | |
|---|
| 254 | def testAddSessionOutsideBoundaries(self): |
|---|
| 255 | #adding a session outside the conference dates must fail |
|---|
| 256 | #s1=Session() |
|---|
| 257 | #sd=datetime(2004, 01, 01, 9, 00, tzinfo=timezone('UTC')) |
|---|
| 258 | #ed=datetime(2004, 01, 01, 16, 00, tzinfo=timezone('UTC')) |
|---|
| 259 | #s1.setDates(sd,ed) |
|---|
| 260 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 261 | #sd=datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 262 | #ed=datetime(2004, 01, 05, 10, 01, tzinfo=timezone('UTC')) |
|---|
| 263 | #s1.setDates(sd,ed) |
|---|
| 264 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 265 | #sd=datetime(2004, 01, 01, 9, 00, tzinfo=timezone('UTC')) |
|---|
| 266 | #ed=datetime(2004, 01, 05, 9, 59, tzinfo=timezone('UTC')) |
|---|
| 267 | #s1.setDates(sd,ed) |
|---|
| 268 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 269 | pass |
|---|
| 270 | |
|---|
| 271 | def testAddEntryOutsideBoundaries(self): |
|---|
| 272 | #adding an entry outside the conference dates must fail |
|---|
| 273 | #c1=Contribution() |
|---|
| 274 | #self._conf.addContribution(c1) |
|---|
| 275 | #c1.setStartDate(datetime(1999, 01, 01, 9, 00, tzinfo=timezone('UTC'))) |
|---|
| 276 | #self.assertRaises(MaKaCError,self._conf.getSchedule().addEntry,c1.getSchEntry()) |
|---|
| 277 | #b=BreakTimeSchEntry() |
|---|
| 278 | #b.setStartDate(datetime(2004, 01, 01, 9, 00, tzinfo=timezone('UTC'))) |
|---|
| 279 | #self.assertRaises(MaKaCError,self._conf.getSchedule().addEntry,b) |
|---|
| 280 | pass |
|---|
| 281 | |
|---|
| 282 | def testSetScheduleDifferentDates(self): |
|---|
| 283 | self._conf.setDates(datetime(2004, 01, 03, 10, 00, tzinfo=timezone('UTC')),datetime(2004, 01, 05, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 284 | s=Session() |
|---|
| 285 | s.setDates(datetime(2004, 01, 04, 10, 00, tzinfo=timezone('UTC')),datetime(2004, 01, 04, 12, 00, tzinfo=timezone('UTC'))) |
|---|
| 286 | self._conf.addSession(s) |
|---|
| 287 | c=Contribution() |
|---|
| 288 | self._conf.addContribution(c) |
|---|
| 289 | c.setStartDate(datetime(2004, 01, 04, 13, 00, tzinfo=timezone('UTC'))) |
|---|
| 290 | self._conf.getSchedule().addEntry(c.getSchEntry()) |
|---|
| 291 | #checks that everything works fine when changing conference schdule |
|---|
| 292 | # dates to ones different from the conference |
|---|
| 293 | #self._conf.setScreenStartDate(datetime(2004, 01, 04, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 294 | #self._conf.setScreenEndDate(datetime(2004, 01, 05, 12, 00, tzinfo=timezone('UTC'))) |
|---|
| 295 | #self.assertRaises(MaKaCError,self._conf.setScreenStartDate,datetime(2004, 01, 04, 10, 01, tzinfo=timezone('UTC'))) |
|---|
| 296 | #self.assertRaises(MaKaCError,self._conf.setScreenEndDate,datetime(2004, 01, 04, 13, 00, tzinfo=timezone('UTC'))) |
|---|
| 297 | #self._conf.setScreenStartDate(datetime(2004, 01, 04, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 298 | #self._conf.setScreenEndDate(datetime(2004, 01, 04, 14, 00, tzinfo=timezone('UTC'))) |
|---|
| 299 | |
|---|
| 300 | #self._conf.setScreenStartDate(datetime(2004, 01, 01, tzinfo=timezone('UTC'))) |
|---|
| 301 | #self._conf.setScreenEndDate(datetime(2004, 01, 05, tzinfo=timezone('UTC'))) |
|---|
| 302 | |
|---|
| 303 | #s.setDates(datetime(2004, 01, 02, 10, 00, tzinfo=timezone('UTC')),datetime(2004, 01, 04, 12, 00, tzinfo=timezone('UTC'))) |
|---|
| 304 | #c.setStartDate(datetime(2004, 01, 02, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 305 | #self.assertRaises(MaKaCError,self._conf.getSchedule().setDates,None,None) |
|---|
| 306 | #s.setDates(datetime(2004, 01, 04, 10, 00, tzinfo=timezone('UTC')),datetime(2004, 01, 04, 12, 00, tzinfo=timezone('UTC'))) |
|---|
| 307 | #self.assertRaises(MaKaCError,self._conf.getSchedule().setDates,None,None) |
|---|
| 308 | #c.setStartDate(datetime(2004, 01, 04, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 309 | #self._conf.getSchedule().setDates(None,None) |
|---|
| 310 | pass |
|---|
| 311 | |
|---|
| 312 | def testSessions(self): |
|---|
| 313 | s1=Session() |
|---|
| 314 | self._conf.addSession(s1) |
|---|
| 315 | sd=datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 316 | ed=datetime(2004, 01, 01, 16, 00, tzinfo=timezone('UTC')) |
|---|
| 317 | s1.setDates(sd,ed) |
|---|
| 318 | slot1=SessionSlot(s1) |
|---|
| 319 | s1.addSlot(slot1) |
|---|
| 320 | slot1.setStartDate(datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 321 | slot1.setDuration(hours=2,minutes=0) |
|---|
| 322 | slot2=SessionSlot(s1) |
|---|
| 323 | s1.addSlot(slot2) |
|---|
| 324 | slot2.setStartDate(datetime(2004, 01, 01, 12, 00, tzinfo=timezone('UTC'))) |
|---|
| 325 | slot2.setDuration(hours=2,minutes=0) |
|---|
| 326 | self.assert_(slot1.getConfSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 327 | self.assert_(slot2.getConfSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 328 | slot3=SessionSlot(s1) |
|---|
| 329 | s1.addSlot(slot3) |
|---|
| 330 | slot3.setStartDate(datetime(2004, 01, 01, 13, 00, tzinfo=timezone('UTC'))) |
|---|
| 331 | slot3.setDuration(hours=2,minutes=0) |
|---|
| 332 | self.assert_(slot3.getConfSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 333 | slot3.delete() |
|---|
| 334 | self.assert_(slot1.getConfSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 335 | self.assert_(slot2.getConfSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 336 | self.assert_(slot3.getConfSchEntry() not in self._conf.getSchedule().getEntries()) |
|---|
| 337 | |
|---|
| 338 | def testContributions(self): |
|---|
| 339 | c1,c2=Contribution(),Contribution() |
|---|
| 340 | self._conf.addContribution(c1) |
|---|
| 341 | self._conf.addContribution(c2) |
|---|
| 342 | sDate=datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC')) |
|---|
| 343 | eDate=datetime(2004, 01, 01, 12, 00, tzinfo=timezone('UTC')) |
|---|
| 344 | self._conf.setStartDate(sDate) |
|---|
| 345 | self._conf.setEndDate(eDate) |
|---|
| 346 | c1.setDuration(0,10) |
|---|
| 347 | c2.setDuration(0,30) |
|---|
| 348 | self._conf.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 349 | self._conf.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 350 | self.assert_(c1.getSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 351 | self.assert_(c1.getStartDate()==datetime(2004, 01, 01, 10, 00, tzinfo=timezone('UTC'))) |
|---|
| 352 | self.assert_(c2.getSchEntry() in self._conf.getSchedule().getEntries()) |
|---|
| 353 | self.assert_(c2.getStartDate()==datetime(2004, 01, 01, 10, 10, tzinfo=timezone('UTC'))) |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | class TestAuthorIndex(unittest.TestCase): |
|---|
| 357 | """Tests the author index |
|---|
| 358 | """ |
|---|
| 359 | |
|---|
| 360 | def setUp( self ): |
|---|
| 361 | self._creator = Avatar() |
|---|
| 362 | self._creator.setId("creator") |
|---|
| 363 | self._categ = Category() |
|---|
| 364 | self._conf=Conference(self._creator) |
|---|
| 365 | self._conf.setId('a') |
|---|
| 366 | self._conf.setTimezone('UTC') |
|---|
| 367 | self._categ._addConference(self._conf) |
|---|
| 368 | |
|---|
| 369 | def testBasicIndexing(self): |
|---|
| 370 | #Tests adding a contribution with some authors already on it |
|---|
| 371 | c1=Contribution() |
|---|
| 372 | self._conf.addContribution(c1) |
|---|
| 373 | auth1,auth2=ContributionParticipation(),ContributionParticipation() |
|---|
| 374 | auth1.setFirstName("hector") |
|---|
| 375 | auth1.setFamilyName("sanchez sanmartin") |
|---|
| 376 | auth1.setEmail("hector.sanchez@cern.ch") |
|---|
| 377 | auth2.setFirstName("jose benito") |
|---|
| 378 | auth2.setFamilyName("gonzalez lopez") |
|---|
| 379 | auth2.setEmail("jose.benito.gonzalez@cern.ch") |
|---|
| 380 | c1.addPrimaryAuthor(auth1) |
|---|
| 381 | c1.addPrimaryAuthor(auth2) |
|---|
| 382 | idx=self._conf.getAuthorIndex() |
|---|
| 383 | self.assert_(auth1 in idx.getParticipations()[1]) |
|---|
| 384 | self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 385 | self.assert_(auth2 in idx.getParticipations()[0]) |
|---|
| 386 | self.assert_(len(idx.getParticipations()[0])==1) |
|---|
| 387 | c2=Contribution() |
|---|
| 388 | self._conf.addContribution(c2) |
|---|
| 389 | auth3,auth4=ContributionParticipation(),ContributionParticipation() |
|---|
| 390 | auth3.setFirstName("hector") |
|---|
| 391 | auth3.setFamilyName("sanchez sanmartin") |
|---|
| 392 | auth3.setEmail("hector.sanchez@cern.ch") |
|---|
| 393 | auth4.setFirstName("jose benito") |
|---|
| 394 | auth4.setFamilyName("gonzalez lopez2") |
|---|
| 395 | auth4.setEmail("jose.benito.gonzalez@cern.ch") |
|---|
| 396 | c2.addPrimaryAuthor(auth3) |
|---|
| 397 | c2.addPrimaryAuthor(auth4) |
|---|
| 398 | #Tests removing a contribution from a conference updates the author |
|---|
| 399 | # index correctly |
|---|
| 400 | #self.assert_(auth3 in idx.getParticipations()[2]) |
|---|
| 401 | #self.assert_(len(idx.getParticipations()[2])==2) |
|---|
| 402 | #self.assert_(auth4 in idx.getParticipations()[1]) |
|---|
| 403 | #self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 404 | #self._conf.removeContribution(c2) |
|---|
| 405 | #self.assert_(auth1 in idx.getParticipations()[1]) |
|---|
| 406 | #self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 407 | #self.assert_(auth2 in idx.getParticipations()[0]) |
|---|
| 408 | #self.assert_(len(idx.getParticipations()[0])==1) |
|---|
| 409 | #Tests adding additional authors to a contribution which is already |
|---|
| 410 | # included in a conference updates the author index correctly |
|---|
| 411 | #auth5=ContributionParticipation() |
|---|
| 412 | #auth5.setFirstName("jean-yves") |
|---|
| 413 | #auth5.setFamilyName("le meur") |
|---|
| 414 | #auth5.setEmail("jean-yves.le.meur@cern.ch") |
|---|
| 415 | #c1.addPrimaryAuthor(auth5) |
|---|
| 416 | #self.assert_(auth1 in idx.getParticipations()[2]) |
|---|
| 417 | #self.assert_(len(idx.getParticipations()[2])==1) |
|---|
| 418 | #self.assert_(auth2 in idx.getParticipations()[0]) |
|---|
| 419 | #self.assert_(len(idx.getParticipations()[0])==1) |
|---|
| 420 | #self.assert_(auth5 in idx.getParticipations()[1]) |
|---|
| 421 | #self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 422 | #Tests removing authors from a contribution which is already |
|---|
| 423 | # included in a conference updates the author index correctly |
|---|
| 424 | #c1.removePrimaryAuthor(auth5) |
|---|
| 425 | #self.assert_(auth1 in idx.getParticipations()[1]) |
|---|
| 426 | #self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 427 | #self.assert_(auth2 in idx.getParticipations()[0]) |
|---|
| 428 | #self.assert_(len(idx.getParticipations()[0])==1) |
|---|
| 429 | |
|---|
| 430 | def testChangesInAuthorData(self): |
|---|
| 431 | #Checks that changes in the author data updates the author index |
|---|
| 432 | # correctly |
|---|
| 433 | c1=Contribution() |
|---|
| 434 | self._conf.addContribution(c1) |
|---|
| 435 | auth1,auth2=ContributionParticipation(),ContributionParticipation() |
|---|
| 436 | auth1.setFirstName("zFN") |
|---|
| 437 | auth1.setFamilyName("zSN") |
|---|
| 438 | auth1.setEmail("zM") |
|---|
| 439 | auth2.setFirstName("AFN") |
|---|
| 440 | auth2.setFamilyName("ASN") |
|---|
| 441 | auth2.setEmail("aM") |
|---|
| 442 | c1.addPrimaryAuthor(auth1) |
|---|
| 443 | c1.addPrimaryAuthor(auth2) |
|---|
| 444 | |
|---|
| 445 | idx=self._conf.getAuthorIndex() |
|---|
| 446 | self.assert_(auth1 in idx.getParticipations()[1]) |
|---|
| 447 | self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 448 | self.assert_(auth2 in idx.getParticipations()[0]) |
|---|
| 449 | self.assert_(len(idx.getParticipations()[0])==1) |
|---|
| 450 | auth2.setFamilyName("ZZSN") |
|---|
| 451 | self.assert_(auth1 in idx.getParticipations()[0]) |
|---|
| 452 | self.assert_(len(idx.getParticipations()[0])==1) |
|---|
| 453 | self.assert_(auth2 in idx.getParticipations()[1]) |
|---|
| 454 | self.assert_(len(idx.getParticipations()[1])==1) |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | class TestAuthorSearch(unittest.TestCase): |
|---|
| 458 | """Tests the author search |
|---|
| 459 | """ |
|---|
| 460 | |
|---|
| 461 | def setUp( self ): |
|---|
| 462 | self._creator = Avatar() |
|---|
| 463 | self._creator.setId("creator") |
|---|
| 464 | self._conf=Conference(self._creator) |
|---|
| 465 | self._conf.setTimezone('UTC') |
|---|
| 466 | |
|---|
| 467 | def testBasicSearch(self): |
|---|
| 468 | c1=Contribution() |
|---|
| 469 | self._conf.addContribution(c1) |
|---|
| 470 | auth1,auth2=ContributionParticipation(),ContributionParticipation() |
|---|
| 471 | auth1.setFamilyName("a") |
|---|
| 472 | auth1.setFirstName("a") |
|---|
| 473 | auth2.setFamilyName("b") |
|---|
| 474 | auth2.setFirstName("b") |
|---|
| 475 | c1.addPrimaryAuthor(auth1) |
|---|
| 476 | c1.addPrimaryAuthor(auth2) |
|---|
| 477 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 478 | self.assert_(len(self._conf.getContribsMatchingAuth("a"))==1) |
|---|
| 479 | self.assert_(c1 in self._conf.getContribsMatchingAuth("a")) |
|---|
| 480 | self.assert_(c1 in self._conf.getContribsMatchingAuth("B")) |
|---|
| 481 | self.assert_(len(self._conf.getContribsMatchingAuth("B"))==1) |
|---|
| 482 | auth3=ContributionParticipation() |
|---|
| 483 | auth3.setFamilyName("c") |
|---|
| 484 | auth3.setFirstName("c") |
|---|
| 485 | c1.addCoAuthor(auth3) |
|---|
| 486 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 487 | self.assert_(len(self._conf.getContribsMatchingAuth("c"))==0) |
|---|
| 488 | |
|---|
| 489 | def testAddAuthor(self): |
|---|
| 490 | c1=Contribution() |
|---|
| 491 | self._conf.addContribution(c1) |
|---|
| 492 | auth1,auth2=ContributionParticipation(),ContributionParticipation() |
|---|
| 493 | auth1.setFamilyName("a") |
|---|
| 494 | auth1.setFirstName("a") |
|---|
| 495 | auth2.setFamilyName("b") |
|---|
| 496 | auth2.setFirstName("b") |
|---|
| 497 | c1.addPrimaryAuthor(auth1) |
|---|
| 498 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 499 | self.assert_(len(self._conf.getContribsMatchingAuth("a"))==1) |
|---|
| 500 | self.assert_(c1 in self._conf.getContribsMatchingAuth("a")) |
|---|
| 501 | c1.addPrimaryAuthor(auth2) |
|---|
| 502 | self.assert_(len(self._conf.getContribsMatchingAuth("b"))==1) |
|---|
| 503 | self.assert_(c1 in self._conf.getContribsMatchingAuth("b")) |
|---|
| 504 | c1.removePrimaryAuthor(auth1) |
|---|
| 505 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 506 | self.assert_(len(self._conf.getContribsMatchingAuth("a"))==0) |
|---|
| 507 | self.assert_(c1 not in self._conf.getContribsMatchingAuth("a")) |
|---|
| 508 | self.assert_(len(self._conf.getContribsMatchingAuth("b"))==1) |
|---|
| 509 | self.assert_(c1 in self._conf.getContribsMatchingAuth("b")) |
|---|
| 510 | |
|---|
| 511 | def testWithdrawnContrib(self): |
|---|
| 512 | #Withdrawn contributions authors must be searchable |
|---|
| 513 | c1=Contribution() |
|---|
| 514 | self._conf.addContribution(c1) |
|---|
| 515 | auth1=ContributionParticipation() |
|---|
| 516 | auth1.setFamilyName("a") |
|---|
| 517 | auth1.setFirstName("a") |
|---|
| 518 | c1.addPrimaryAuthor(auth1) |
|---|
| 519 | c1.withdraw(self._creator,"ll") |
|---|
| 520 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 521 | self.assert_(len(self._conf.getContribsMatchingAuth("a"))==1) |
|---|
| 522 | self.assert_(c1 in self._conf.getContribsMatchingAuth("a")) |
|---|
| 523 | auth2=ContributionParticipation() |
|---|
| 524 | auth2.setFamilyName("b") |
|---|
| 525 | auth2.setFirstName("b") |
|---|
| 526 | c1.addPrimaryAuthor(auth2) |
|---|
| 527 | #self._conf.getContribsMatchingAuth("b") |
|---|
| 528 | #self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 529 | #self.assert_(len(self._conf.getContribsMatchingAuth("b"))==1) |
|---|
| 530 | #self.assert_(c1 in self._conf.getContribsMatchingAuth("b")) |
|---|
| 531 | |
|---|
| 532 | def testAuthorsWithSameName(self): |
|---|
| 533 | #one contribution could have 2 authors with the same name |
|---|
| 534 | c1=Contribution() |
|---|
| 535 | self._conf.addContribution(c1) |
|---|
| 536 | auth1=ContributionParticipation() |
|---|
| 537 | auth1.setFamilyName("a") |
|---|
| 538 | auth1.setFirstName("a") |
|---|
| 539 | c1.addPrimaryAuthor(auth1) |
|---|
| 540 | auth2=ContributionParticipation() |
|---|
| 541 | auth2.setFamilyName("a") |
|---|
| 542 | auth2.setFirstName("a") |
|---|
| 543 | c1.addPrimaryAuthor(auth2) |
|---|
| 544 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 545 | self.assert_(len(self._conf.getContribsMatchingAuth("a"))==1) |
|---|
| 546 | self.assert_(c1 in self._conf.getContribsMatchingAuth("a")) |
|---|
| 547 | c1.removePrimaryAuthor(auth1) |
|---|
| 548 | self.assert_(len(self._conf.getContribsMatchingAuth(""))==1) |
|---|
| 549 | self.assert_(len(self._conf.getContribsMatchingAuth("a"))==1) |
|---|
| 550 | self.assert_(c1 in self._conf.getContribsMatchingAuth("a")) |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | class TestContributionSubmitterIndex(unittest.TestCase): |
|---|
| 554 | """ |
|---|
| 555 | """ |
|---|
| 556 | |
|---|
| 557 | def setUp( self ): |
|---|
| 558 | self._creator = Avatar() |
|---|
| 559 | self._creator.setId("creator") |
|---|
| 560 | self._categ = Category() |
|---|
| 561 | self._conf=Conference(self._creator) |
|---|
| 562 | self._conf.setId('a') |
|---|
| 563 | self._conf.setTimezone('UTC') |
|---|
| 564 | self._categ._addConference(self._conf) |
|---|
| 565 | |
|---|
| 566 | def testBasic(self): |
|---|
| 567 | c1,c2=Contribution(),Contribution() |
|---|
| 568 | av1,av2=Avatar(),Avatar() |
|---|
| 569 | av1.setId("1") |
|---|
| 570 | av2.setId("2") |
|---|
| 571 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==0) |
|---|
| 572 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==0) |
|---|
| 573 | self._conf.addContribution(c1) |
|---|
| 574 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==0) |
|---|
| 575 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==0) |
|---|
| 576 | c1.grantSubmission(av1) |
|---|
| 577 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==1) |
|---|
| 578 | self.assert_(c1 in self._conf.getContribsForSubmitter(av1)) |
|---|
| 579 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==0) |
|---|
| 580 | c2.grantSubmission(av2) |
|---|
| 581 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==1) |
|---|
| 582 | self.assert_(c1 in self._conf.getContribsForSubmitter(av1)) |
|---|
| 583 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==0) |
|---|
| 584 | self._conf.addContribution(c2) |
|---|
| 585 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==1) |
|---|
| 586 | self.assert_(c1 in self._conf.getContribsForSubmitter(av1)) |
|---|
| 587 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==1) |
|---|
| 588 | self.assert_(c2 in self._conf.getContribsForSubmitter(av2)) |
|---|
| 589 | c1.grantSubmission(av2) |
|---|
| 590 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==1) |
|---|
| 591 | self.assert_(c1 in self._conf.getContribsForSubmitter(av1)) |
|---|
| 592 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==2) |
|---|
| 593 | self.assert_(c1 in self._conf.getContribsForSubmitter(av2)) |
|---|
| 594 | self.assert_(c2 in self._conf.getContribsForSubmitter(av2)) |
|---|
| 595 | c1.revokeSubmission(av2) |
|---|
| 596 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==1) |
|---|
| 597 | self.assert_(c1 in self._conf.getContribsForSubmitter(av1)) |
|---|
| 598 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==1) |
|---|
| 599 | self.assert_(c1 not in self._conf.getContribsForSubmitter(av2)) |
|---|
| 600 | self.assert_(c2 in self._conf.getContribsForSubmitter(av2)) |
|---|
| 601 | self._conf.removeContribution(c2) |
|---|
| 602 | self.assert_(len(self._conf.getContribsForSubmitter(av1))==1) |
|---|
| 603 | self.assert_(c1 in self._conf.getContribsForSubmitter(av1)) |
|---|
| 604 | self.assert_(len(self._conf.getContribsForSubmitter(av2))==0) |
|---|
| 605 | self.assert_(c1 not in self._conf.getContribsForSubmitter(av2)) |
|---|
| 606 | self.assert_(c2 not in self._conf.getContribsForSubmitter(av2)) |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | class TestBasicManagement(unittest.TestCase): |
|---|
| 611 | """Tests the basic contribution management functions |
|---|
| 612 | """ |
|---|
| 613 | |
|---|
| 614 | def setUp( self ): |
|---|
| 615 | a = Avatar() |
|---|
| 616 | a.setId("creator") |
|---|
| 617 | self._categ = Category() |
|---|
| 618 | self._conf = Conference( a ) |
|---|
| 619 | category=conference.Category() |
|---|
| 620 | self._conf.addOwner(category) |
|---|
| 621 | self._conf.setId('a') |
|---|
| 622 | self._conf.setDates(datetime(2000, 01, 01, tzinfo=timezone("UTC")),datetime(2020, 01, 01, tzinfo=timezone("UTC"))) |
|---|
| 623 | self._categ._addConference(self._conf) |
|---|
| 624 | |
|---|
| 625 | def testBasicAddAndRemove( self ): |
|---|
| 626 | contrib1 = Contribution() |
|---|
| 627 | contrib2 = Contribution() |
|---|
| 628 | contrib3 = Contribution() |
|---|
| 629 | self._conf.addContribution( contrib1 ) |
|---|
| 630 | self.assert_( self._conf.getContributionById( contrib1.getId() ) == contrib1 ) |
|---|
| 631 | self._conf.removeContribution( contrib2 ) |
|---|
| 632 | self.assert_( self._conf.getContributionById( contrib1.getId() ) == contrib1 ) |
|---|
| 633 | self._conf.removeContribution( contrib1 ) |
|---|
| 634 | self.assert_( self._conf.getContributionById( contrib1.getId() ) == None ) |
|---|
| 635 | self._conf.addContribution( contrib2 ) |
|---|
| 636 | contrib2.delete() |
|---|
| 637 | self.assert_( self._conf.getContributionById( contrib2.getId() ) == None ) |
|---|
| 638 | |
|---|
| 639 | def testTrackDefinition( self ): |
|---|
| 640 | #tests the definition of the track of a contribution |
|---|
| 641 | contrib1 = Contribution() |
|---|
| 642 | track1 = self._conf.newTrack() |
|---|
| 643 | track2 = self._conf.newTrack() |
|---|
| 644 | self._conf.addContribution( contrib1 ) |
|---|
| 645 | contrib1.setTrack( track1 ) |
|---|
| 646 | self.assert_( contrib1.getTrack() == track1 ) |
|---|
| 647 | self.assert_( track1.hasContribution( contrib1 ) ) |
|---|
| 648 | contrib1.setTrack( None ) |
|---|
| 649 | self.assert_( contrib1.getTrack() == None ) |
|---|
| 650 | self.assert_( not track1.hasContribution( contrib1 ) ) |
|---|
| 651 | |
|---|
| 652 | def testSessionInclusion(self): |
|---|
| 653 | session1,session2=Session(),Session() |
|---|
| 654 | self._conf.addSession(session1) |
|---|
| 655 | self._conf.addSession(session2) |
|---|
| 656 | contrib1=Contribution() |
|---|
| 657 | self._conf.addContribution(contrib1) |
|---|
| 658 | contrib1.setTitle("debug") |
|---|
| 659 | contrib1.setSession(session1) |
|---|
| 660 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 661 | self.assert_(session1.hasContribution(contrib1)) |
|---|
| 662 | self.assert_(not session2.hasContribution(contrib1)) |
|---|
| 663 | contrib1.setSession(session2) |
|---|
| 664 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 665 | self.assert_(not session1.hasContribution(contrib1)) |
|---|
| 666 | self.assert_(session2.hasContribution(contrib1)) |
|---|
| 667 | contrib1.setSession(None) |
|---|
| 668 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 669 | self.assert_(not session1.hasContribution(contrib1)) |
|---|
| 670 | self.assert_(not session2.hasContribution(contrib1)) |
|---|
| 671 | contrib1.setSession(session1) |
|---|
| 672 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 673 | self.assert_(session1.hasContribution(contrib1)) |
|---|
| 674 | self.assert_(not session2.hasContribution(contrib1)) |
|---|
| 675 | self._conf.removeContribution(contrib1) |
|---|
| 676 | self.assert_(not self._conf.hasContribution(contrib1)) |
|---|
| 677 | self.assert_(not session1.hasContribution(contrib1)) |
|---|
| 678 | self.assert_(contrib1 not in session1.getContributionList()) |
|---|
| 679 | self.assert_(not session2.hasContribution(contrib1)) |
|---|
| 680 | self.assert_(contrib1 not in session2.getContributionList()) |
|---|
| 681 | |
|---|
| 682 | def testCustomIds(self): |
|---|
| 683 | #tests that adding a contribution with a custom id does not cause any |
|---|
| 684 | # trouble |
|---|
| 685 | contrib1 = Contribution() |
|---|
| 686 | self._conf.addContribution(contrib1,"test") |
|---|
| 687 | self.assert_(contrib1.getId()=="test") |
|---|
| 688 | self.assert_(self._conf.getContributionById("test")==contrib1) |
|---|
| 689 | contrib2 = Contribution() |
|---|
| 690 | self._conf.addContribution(contrib2) |
|---|
| 691 | self.assert_(contrib2.getId()=="0") |
|---|
| 692 | self.assert_(self._conf.getContributionById("0")==contrib2) |
|---|
| 693 | contrib3 = Contribution() |
|---|
| 694 | self._conf.addContribution(contrib3,"12") |
|---|
| 695 | self.assert_(contrib3.getId()=="12") |
|---|
| 696 | self.assert_(self._conf.getContributionById("12")==contrib3) |
|---|
| 697 | contrib4 = Contribution() |
|---|
| 698 | self._conf.addContribution(contrib4) |
|---|
| 699 | self.assert_(contrib4.getId()=="1") |
|---|
| 700 | self.assert_(self._conf.getContributionById("1")==contrib4) |
|---|
| 701 | contrib5 = Contribution() |
|---|
| 702 | self.assertRaises(MaKaCError,self._conf.addContribution,contrib5,"0") |
|---|
| 703 | self._conf.addContribution(contrib5,"2") |
|---|
| 704 | self.assert_(contrib5.getId()=="2") |
|---|
| 705 | self.assert_(self._conf.getContributionById("2")==contrib5) |
|---|
| 706 | contrib6 = Contribution() |
|---|
| 707 | self._conf.addContribution(contrib6) |
|---|
| 708 | self.assert_(contrib6.getId()=="3") |
|---|
| 709 | self.assert_(self._conf.getContributionById("3")==contrib6) |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | class TestWithdrawal(unittest.TestCase): |
|---|
| 713 | """Tests different scenarios concerning the contribution withdrawal |
|---|
| 714 | """ |
|---|
| 715 | |
|---|
| 716 | def setUp( self ): |
|---|
| 717 | self._creator=Avatar() |
|---|
| 718 | self._creator.setId("creator") |
|---|
| 719 | self._conf=Conference(self._creator) |
|---|
| 720 | category=conference.Category() |
|---|
| 721 | self._conf.addOwner(category) |
|---|
| 722 | self._conf.setTimezone('UTC') |
|---|
| 723 | sd=datetime(2004, 01, 01, 10, 00, tzinfo=timezone("UTC")) |
|---|
| 724 | ed=datetime(2004, 01, 05, 10, 00, tzinfo=timezone("UTC")) |
|---|
| 725 | self._conf.setDates(sd,ed) |
|---|
| 726 | |
|---|
| 727 | def testBasicWithdrawal(self): |
|---|
| 728 | c1,c2=Contribution(),Contribution() |
|---|
| 729 | auth1,auth2=ContributionParticipation(),ContributionParticipation() |
|---|
| 730 | self._conf.addContribution(c1) |
|---|
| 731 | self._conf.addContribution(c2) |
|---|
| 732 | auth1.setFirstName("a") |
|---|
| 733 | auth1.setFamilyName("a") |
|---|
| 734 | auth1.setEmail("a") |
|---|
| 735 | auth2.setFirstName("b") |
|---|
| 736 | auth2.setFamilyName("b") |
|---|
| 737 | auth2.setEmail("b") |
|---|
| 738 | c1.addPrimaryAuthor(auth1) |
|---|
| 739 | c2.addPrimaryAuthor(auth2) |
|---|
| 740 | s1=Session() |
|---|
| 741 | sd=datetime(2004, 01, 01, 12, 00, tzinfo=timezone("UTC")) |
|---|
| 742 | ed=datetime(2004, 01, 01, 19, 00, tzinfo=timezone("UTC")) |
|---|
| 743 | s1.setDates(sd,ed) |
|---|
| 744 | slot1=SessionSlot(s1) |
|---|
| 745 | self._conf.addSession(s1) |
|---|
| 746 | s1.addSlot(slot1) |
|---|
| 747 | s1.addContribution(c1) |
|---|
| 748 | s1.addContribution(c2) |
|---|
| 749 | slot1.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 750 | slot1.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 751 | self.assert_(c1.isScheduled()) |
|---|
| 752 | self.assert_(c2.isScheduled()) |
|---|
| 753 | authIdx=self._conf.getAuthorIndex() |
|---|
| 754 | self.assert_(auth1 in authIdx.getParticipations()[0]) |
|---|
| 755 | self.assert_(auth2 in authIdx.getParticipations()[1]) |
|---|
| 756 | c1.withdraw(self._creator,"test") |
|---|
| 757 | self.assert_(not c1.isScheduled()) |
|---|
| 758 | self.assert_(c2.isScheduled()) |
|---|
| 759 | self.assert_(auth1 not in authIdx.getParticipations()[0]) |
|---|
| 760 | self.assert_(auth2 in authIdx.getParticipations()[0]) |
|---|
| 761 | auth1.setFirstName("aa") |
|---|
| 762 | self.assert_(auth1 not in authIdx.getParticipations()[0]) |
|---|
| 763 | self.assert_(auth2 in authIdx.getParticipations()[0]) |
|---|
| 764 | auth3,auth4=ContributionParticipation(),ContributionParticipation() |
|---|
| 765 | auth3.setFirstName("c") |
|---|
| 766 | auth3.setFamilyName("c") |
|---|
| 767 | auth3.setEmail("c") |
|---|
| 768 | auth4.setFirstName("d") |
|---|
| 769 | auth4.setFamilyName("d") |
|---|
| 770 | auth4.setEmail("d") |
|---|
| 771 | c1.addPrimaryAuthor(auth3) |
|---|
| 772 | c2.addPrimaryAuthor(auth4) |
|---|
| 773 | self.assert_(auth2 in authIdx.getParticipations()[0]) |
|---|
| 774 | self.assert_(auth4 in authIdx.getParticipations()[1]) |
|---|
| 775 | self.assertRaises(MaKaCError,slot1.getSchedule().addEntry,c1.getSchEntry()) |
|---|
| 776 | |
|---|
| 777 | class TestSubmissionPrivileges(unittest.TestCase): |
|---|
| 778 | """Tests different scenarios concerning the material submission privileges |
|---|
| 779 | """ |
|---|
| 780 | |
|---|
| 781 | def setUp( self ): |
|---|
| 782 | self._creator=Avatar() |
|---|
| 783 | self._creator.setId("creator") |
|---|
| 784 | self._conf=Conference(self._creator) |
|---|
| 785 | category=conference.Category() |
|---|
| 786 | self._conf.addOwner(category) |
|---|
| 787 | sd=datetime(2004, 01, 01, 10, 00, tzinfo=timezone("UTC")) |
|---|
| 788 | ed=datetime(2004, 01, 05, 10, 00, tzinfo=timezone("UTC")) |
|---|
| 789 | self._conf.setDates(sd,ed) |
|---|
| 790 | |
|---|
| 791 | def testBasic(self): |
|---|
| 792 | c1=Contribution() |
|---|
| 793 | self._conf.addContribution(c1) |
|---|
| 794 | av1,av2=Avatar(),Avatar() |
|---|
| 795 | av1.setId("1") |
|---|
| 796 | av2.setId("2") |
|---|
| 797 | self.assert_(not c1.canUserSubmit(av1)) |
|---|
| 798 | self.assert_(not c1.canUserSubmit(av2)) |
|---|
| 799 | self.assert_(len(c1.getSubmitterList())==0) |
|---|
| 800 | c1.grantSubmission(av1) |
|---|
| 801 | self.assert_(c1.canUserSubmit(av1)) |
|---|
| 802 | self.assert_(not c1.canUserSubmit(av2)) |
|---|
| 803 | self.assert_(len(c1.getSubmitterList())==1) |
|---|
| 804 | self.assert_(av1 in c1.getSubmitterList()) |
|---|
| 805 | self.assert_(av2 not in c1.getSubmitterList()) |
|---|
| 806 | c1.revokeSubmission(av2) |
|---|
| 807 | self.assert_(c1.canUserSubmit(av1)) |
|---|
| 808 | self.assert_(not c1.canUserSubmit(av2)) |
|---|
| 809 | self.assert_(len(c1.getSubmitterList())==1) |
|---|
| 810 | self.assert_(av1 in c1.getSubmitterList()) |
|---|
| 811 | self.assert_(av2 not in c1.getSubmitterList()) |
|---|
| 812 | c1.revokeSubmission(av1) |
|---|
| 813 | self.assert_(not c1.canUserSubmit(av1)) |
|---|
| 814 | self.assert_(not c1.canUserSubmit(av2)) |
|---|
| 815 | self.assert_(len(c1.getSubmitterList())==0) |
|---|
| 816 | |
|---|
| 817 | def testAccContrib(self): |
|---|
| 818 | #tests that when a contribution comes from an accepted abstract the |
|---|
| 819 | # abstract submitters are also granted with submission privileges |
|---|
| 820 | # for the contribution |
|---|
| 821 | av1=Avatar() |
|---|
| 822 | av1.setId("1") |
|---|
| 823 | av2=Avatar() |
|---|
| 824 | av2.setId("2") |
|---|
| 825 | abs=self._conf.getAbstractMgr().newAbstract(av1) |
|---|
| 826 | abs.accept(self._creator,None,None) |
|---|
| 827 | c=abs.getContribution() |
|---|
| 828 | self.assert_(c.canUserSubmit(av1)) |
|---|
| 829 | self.assert_(not c.canUserSubmit(av2)) |
|---|
| 830 | c.grantSubmission(av2) |
|---|
| 831 | self.assert_(c.canUserSubmit(av1)) |
|---|
| 832 | self.assert_(c.canUserSubmit(av2)) |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | #from testSciProgramme.py |
|---|
| 836 | """Contains tests about some typical "scientific programme" scenarios. |
|---|
| 837 | """ |
|---|
| 838 | class TestTCIndex( unittest.TestCase ): |
|---|
| 839 | """Makes sure the track coordinators index is working properly as standalone |
|---|
| 840 | component |
|---|
| 841 | """ |
|---|
| 842 | |
|---|
| 843 | def setUp( self ): |
|---|
| 844 | #Build an index |
|---|
| 845 | from MaKaC.conference import TCIndex |
|---|
| 846 | self._idx = TCIndex() |
|---|
| 847 | |
|---|
| 848 | def tearDown( self ): |
|---|
| 849 | pass |
|---|
| 850 | |
|---|
| 851 | def testSimpleIndexing( self ): |
|---|
| 852 | #adding a simple object to the index |
|---|
| 853 | from MaKaC.user import Avatar |
|---|
| 854 | av = Avatar() |
|---|
| 855 | av.setId( "1" ) #the index needs the avatar to be uniquely identified |
|---|
| 856 | from MaKaC.conference import Track |
|---|
| 857 | t = Track() |
|---|
| 858 | t.setId( "1" ) |
|---|
| 859 | self._idx.indexCoordinator( av , t ) |
|---|
| 860 | self.assert_( len(self._idx.getTracks( av )) == 1 ) |
|---|
| 861 | self.assert_( t in self._idx.getTracks( av ) ) |
|---|
| 862 | |
|---|
| 863 | def testIndexingSeveralCoordinators( self ): |
|---|
| 864 | #adding 2 coordinators for the same track |
|---|
| 865 | from MaKaC.user import Avatar |
|---|
| 866 | av1 = Avatar() |
|---|
| 867 | av1.setId( "1" ) #the index needs the avatar to be uniquely identified |
|---|
| 868 | av2 = Avatar() |
|---|
| 869 | av2.setId( "2" ) #the index needs the avatar to be uniquely identified |
|---|
| 870 | from MaKaC.conference import Track |
|---|
| 871 | t = Track() |
|---|
| 872 | t.setId( "1" ) |
|---|
| 873 | self._idx.indexCoordinator( av1 , t ) |
|---|
| 874 | self._idx.indexCoordinator( av2 , t ) |
|---|
| 875 | self.assert_( t in self._idx.getTracks( av1 ) ) |
|---|
| 876 | self.assert_( t in self._idx.getTracks( av2 ) ) |
|---|
| 877 | |
|---|
| 878 | def testIndexingSeveralTracks( self ): |
|---|
| 879 | #adding 1 coordinator for 2 tracks |
|---|
| 880 | from MaKaC.user import Avatar |
|---|
| 881 | av1 = Avatar() |
|---|
| 882 | av1.setId( "1" ) #the index needs the avatar to be uniquely identified |
|---|
| 883 | from MaKaC.conference import Track |
|---|
| 884 | t1 = Track() |
|---|
| 885 | t1.setId( "1" ) |
|---|
| 886 | t2 = Track() |
|---|
| 887 | t2.setId( "2" ) |
|---|
| 888 | self._idx.indexCoordinator( av1 , t1 ) |
|---|
| 889 | self._idx.indexCoordinator( av1 , t2 ) |
|---|
| 890 | self.assert_( t1 in self._idx.getTracks( av1 ) ) |
|---|
| 891 | self.assert_( t2 in self._idx.getTracks( av1 ) ) |
|---|
| 892 | |
|---|
| 893 | def testSimpleUnidexing( self ): |
|---|
| 894 | #check that unindexing works properly |
|---|
| 895 | from MaKaC.user import Avatar |
|---|
| 896 | av = Avatar() |
|---|
| 897 | av.setId( "1" ) #the index needs the avatar to be uniquely identified |
|---|
| 898 | from MaKaC.conference import Track |
|---|
| 899 | t = Track() |
|---|
| 900 | t.setId( "1" ) |
|---|
| 901 | self._idx.indexCoordinator( av , t ) |
|---|
| 902 | self._idx.unindexCoordinator( av, t ) |
|---|
| 903 | self.assert_( len(self._idx.getTracks( av )) == 0 ) |
|---|
| 904 | |
|---|
| 905 | def testUnindexingSeveralCoordinators( self ): |
|---|
| 906 | from MaKaC.user import Avatar |
|---|
| 907 | av1 = Avatar() |
|---|
| 908 | av1.setId( "1" ) #the index needs the avatar to be uniquely identified |
|---|
| 909 | av2 = Avatar() |
|---|
| 910 | av2.setId( "2" ) #the index needs the avatar to be uniquely identified |
|---|
| 911 | from MaKaC.conference import Track |
|---|
| 912 | t1 = Track() |
|---|
| 913 | t1.setId( "1" ) |
|---|
| 914 | self._idx.indexCoordinator( av1 , t1 ) |
|---|
| 915 | self._idx.indexCoordinator( av2 , t1 ) |
|---|
| 916 | self._idx.unindexCoordinator( av1, t1 ) |
|---|
| 917 | self.assert_( t1 not in self._idx.getTracks( av1 ) ) |
|---|
| 918 | self.assert_( t1 in self._idx.getTracks( av2 ) ) |
|---|
| 919 | |
|---|
| 920 | def testUnindexingSeveralTracks( self ): |
|---|
| 921 | from MaKaC.user import Avatar |
|---|
| 922 | av1 = Avatar() |
|---|
| 923 | av1.setId( "1" ) #the index needs the avatar to be uniquely identified |
|---|
| 924 | from MaKaC.conference import Track |
|---|
| 925 | t1 = Track() |
|---|
| 926 | t1.setId( "1" ) |
|---|
| 927 | t2 = Track() |
|---|
| 928 | t2.setId( "2" ) |
|---|
| 929 | self._idx.indexCoordinator( av1 , t1 ) |
|---|
| 930 | self._idx.indexCoordinator( av1 , t2 ) |
|---|
| 931 | self._idx.unindexCoordinator( av1, t1 ) |
|---|
| 932 | self.assert_( t1 not in self._idx.getTracks( av1 ) ) |
|---|
| 933 | self.assert_( t2 in self._idx.getTracks( av1 ) ) |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | class TestAddTrackCoordinator( unittest.TestCase ): |
|---|
| 937 | """Tests different scenarios of the Define Track Coord use case. |
|---|
| 938 | """ |
|---|
| 939 | |
|---|
| 940 | def setUp( self ): |
|---|
| 941 | from MaKaC.user import Avatar |
|---|
| 942 | cr = Avatar() |
|---|
| 943 | cr.setId( "creator" ) |
|---|
| 944 | from MaKaC.conference import Conference, Track |
|---|
| 945 | self._conf = Conference( cr ) |
|---|
| 946 | self._track1 = Track() |
|---|
| 947 | self._track1.setId( "1" ) |
|---|
| 948 | self._conf.addTrack( self._track1 ) |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | def tearDown( self ): |
|---|
| 952 | pass |
|---|
| 953 | |
|---|
| 954 | def testAddTC( self ): |
|---|
| 955 | from MaKaC.user import Avatar |
|---|
| 956 | tc1 = Avatar() |
|---|
| 957 | tc1.setId( "tc1" ) |
|---|
| 958 | self._track1.addCoordinator( tc1 ) |
|---|
| 959 | self.assert_( len(self._track1.getCoordinatorList()) == 1 ) |
|---|
| 960 | self.assert_( tc1 in self._track1.getCoordinatorList() ) |
|---|
| 961 | self.assert_( self._track1 in self._conf.getCoordinatedTracks( tc1 ) ) |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | class TestRemoveTrackCoordinator( unittest.TestCase ): |
|---|
| 965 | """Tests different scenarios of the Remove Track Coord use case. |
|---|
| 966 | """ |
|---|
| 967 | |
|---|
| 968 | def setUp( self ): |
|---|
| 969 | from MaKaC.user import Avatar |
|---|
| 970 | cr = Avatar() |
|---|
| 971 | cr.setId( "creator" ) |
|---|
| 972 | from MaKaC.conference import Conference, Track |
|---|
| 973 | self._conf = Conference( cr ) |
|---|
| 974 | self._track1 = Track() |
|---|
| 975 | self._track1.setId( "1" ) |
|---|
| 976 | self._conf.addTrack( self._track1 ) |
|---|
| 977 | |
|---|
| 978 | def tearDown( self ): |
|---|
| 979 | pass |
|---|
| 980 | |
|---|
| 981 | def testRemoveTC( self ): |
|---|
| 982 | from MaKaC.user import Avatar |
|---|
| 983 | tc1 = Avatar() |
|---|
| 984 | tc1.setId( "tc1" ) |
|---|
| 985 | tc2 = Avatar() |
|---|
| 986 | tc2.setId( "tc2" ) |
|---|
| 987 | self._track1.addCoordinator( tc1 ) |
|---|
| 988 | self._track1.addCoordinator( tc2 ) |
|---|
| 989 | self._track1.removeCoordinator( tc1 ) |
|---|
| 990 | self.assert_( tc1 not in self._track1.getCoordinatorList() ) |
|---|
| 991 | self.assert_( tc2 in self._track1.getCoordinatorList() ) |
|---|
| 992 | self.assert_( self._track1 not in self._conf.getCoordinatedTracks( tc1 ) ) |
|---|
| 993 | self.assert_( self._track1 in self._conf.getCoordinatedTracks( tc2 ) ) |
|---|
| 994 | |
|---|
| 995 | |
|---|
| 996 | class TestContributionInclusion( unittest.TestCase ): |
|---|
| 997 | |
|---|
| 998 | def setUp( self ): |
|---|
| 999 | from MaKaC.user import Avatar |
|---|
| 1000 | cr = Avatar() |
|---|
| 1001 | cr.setId( "creator" ) |
|---|
| 1002 | from MaKaC.conference import Conference, Track |
|---|
| 1003 | self._conf = Conference( cr ) |
|---|
| 1004 | self._track1 = Track() |
|---|
| 1005 | self._track1.setId( "1" ) |
|---|
| 1006 | self._conf.addTrack( self._track1 ) |
|---|
| 1007 | |
|---|
| 1008 | def test( self ): |
|---|
| 1009 | from MaKaC.conference import Contribution |
|---|
| 1010 | contrib1 = Contribution() |
|---|
| 1011 | self._conf.addContribution( contrib1 ) |
|---|
| 1012 | self._track1.addContribution( contrib1 ) |
|---|
| 1013 | self.assert_( self._track1.hasContribution( contrib1 ) ) |
|---|
| 1014 | self.assert_( contrib1.getTrack() == self._track1 ) |
|---|
| 1015 | self._track1.removeContribution( contrib1 ) |
|---|
| 1016 | self.assert_( not self._track1.hasContribution( contrib1 ) ) |
|---|
| 1017 | self.assert_( contrib1.getTrack() == None ) |
|---|
| 1018 | |
|---|
| 1019 | #from testSessions.py |
|---|
| 1020 | class TestBasicManagement(unittest.TestCase): |
|---|
| 1021 | """Tests the basic contribution management functions |
|---|
| 1022 | """ |
|---|
| 1023 | |
|---|
| 1024 | def setUp( self ): |
|---|
| 1025 | a = Avatar() |
|---|
| 1026 | a.setId("creator") |
|---|
| 1027 | self._conf = Conference( a ) |
|---|
| 1028 | category=conference.Category() |
|---|
| 1029 | self._conf.addOwner(category) |
|---|
| 1030 | self._conf.setDates(datetime(2000,1,1,tzinfo=timezone('UTC')),datetime(2020,1,1,tzinfo=timezone('UTC'))) |
|---|
| 1031 | |
|---|
| 1032 | def testDates(self): |
|---|
| 1033 | session1=Session() |
|---|
| 1034 | #self._conf.setStartDate(datetime(2004,1,1,8,0,tzinfo=timezone('UTC'))) |
|---|
| 1035 | #self._conf.setEndDate(datetime(2005,1,1,8,0,tzinfo=timezone('UTC'))) |
|---|
| 1036 | session1.setStartDate(datetime(2004,2,15,tzinfo=timezone('UTC'))) |
|---|
| 1037 | #self.assertRaises(MaKaCError,session1.setEndDate,datetime(2004,2,14,tzinfo=timezone('UTC'))) |
|---|
| 1038 | session1.setEndDate(datetime(2004,2,16,tzinfo=timezone('UTC'))) |
|---|
| 1039 | self.assert_(session1.getStartDate()==datetime(2004,2,15,tzinfo=timezone('UTC'))) |
|---|
| 1040 | self.assert_(session1.getEndDate()==datetime(2004,2,16,tzinfo=timezone('UTC'))) |
|---|
| 1041 | session1.setDates(datetime(2004,2,10,tzinfo=timezone('UTC')),datetime(2004,2,11,tzinfo=timezone('UTC'))) |
|---|
| 1042 | self.assert_(session1.getStartDate()==datetime(2004,2,10,tzinfo=timezone('UTC'))) |
|---|
| 1043 | self.assert_(session1.getEndDate()==datetime(2004,2,11,tzinfo=timezone('UTC'))) |
|---|
| 1044 | session1.setDates(datetime(2004,2,15,tzinfo=timezone('UTC')),datetime(2004,2,16,tzinfo=timezone('UTC'))) |
|---|
| 1045 | self.assert_(session1.getStartDate()==datetime(2004,2,15,tzinfo=timezone('UTC'))) |
|---|
| 1046 | self.assert_(session1.getEndDate()==datetime(2004,2,16,tzinfo=timezone('UTC'))) |
|---|
| 1047 | session1.setDates(datetime(2004,2,14,tzinfo=timezone('UTC')),datetime(2004,2,17,tzinfo=timezone('UTC'))) |
|---|
| 1048 | self.assert_(session1.getStartDate()==datetime(2004,2,14,tzinfo=timezone('UTC'))) |
|---|
| 1049 | self.assert_(session1.getEndDate()==datetime(2004,2,17,tzinfo=timezone('UTC'))) |
|---|
| 1050 | |
|---|
| 1051 | def testBasicAddAndRemove( self ): |
|---|
| 1052 | session1,session2=Session(),Session() |
|---|
| 1053 | self._conf.addSession(session1) |
|---|
| 1054 | self.assert_(self._conf.getSessionById(session1.getId())==session1) |
|---|
| 1055 | self.assert_(session1 in self._conf.getSessionList()) |
|---|
| 1056 | session1.delete() |
|---|
| 1057 | self.assert_(session1 not in self._conf.getSessionList()) |
|---|
| 1058 | self.assert_(self._conf.getSessionById(session1.getId())==None) |
|---|
| 1059 | |
|---|
| 1060 | def testDateModification(self): |
|---|
| 1061 | self._conf.setDates(datetime(2004,1,1,tzinfo=timezone('UTC')),datetime(2004,1,5,tzinfo=timezone('UTC'))) |
|---|
| 1062 | ##checks that a session cannot be added if its dates are outside the |
|---|
| 1063 | ## schedule boundaries |
|---|
| 1064 | #s1=Session() |
|---|
| 1065 | #s1.setDates(datetime(2003,12,31,tzinfo=timezone('UTC')),datetime(2004,1,31,tzinfo=timezone('UTC'))) |
|---|
| 1066 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 1067 | #s1.setDates(datetime(2004,1,1,11,0,tzinfo=timezone('UTC')),datetime(2004,1,31,tzinfo=timezone('UTC'))) |
|---|
| 1068 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 1069 | #s1.setDates(datetime(2004,1,1,11,0,tzinfo=timezone('UTC')),datetime(2004,1,4,tzinfo=timezone('UTC'))) |
|---|
| 1070 | #self._conf.addSession(s1) |
|---|
| 1071 | #self._conf.removeSession(s1) |
|---|
| 1072 | #self._conf.getSchedule().setDates(datetime(2004,1,2,tzinfo=timezone('UTC')),datetime(2004,1,7,tzinfo=timezone('UTC'))) |
|---|
| 1073 | #s1=Session() |
|---|
| 1074 | #s1.setDates(datetime(2003,12,31,tzinfo=timezone('UTC')),datetime(2004,1,31,tzinfo=timezone('UTC'))) |
|---|
| 1075 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 1076 | #s1.setDates(datetime(2004,1,1,11,0,tzinfo=timezone('UTC')),datetime(2004,1,31,tzinfo=timezone('UTC'))) |
|---|
| 1077 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 1078 | #s1.setDates(datetime(2004,1,1,11,0,tzinfo=timezone('UTC')),datetime(2004,1,4,tzinfo=timezone('UTC'))) |
|---|
| 1079 | #self.assertRaises(MaKaCError,self._conf.addSession,s1) |
|---|
| 1080 | #s1.setDates(datetime(2004,1,2,11,0,tzinfo=timezone('UTC')),datetime(2004,1,6,tzinfo=timezone('UTC'))) |
|---|
| 1081 | #self._conf.addSession(s1) |
|---|
| 1082 | ##checks that when modifying the session dates to ones which are outside |
|---|
| 1083 | ## the conference schedule scope is not allowed |
|---|
| 1084 | #s1.setDates(datetime(2004,1,3,tzinfo=timezone('UTC')),datetime(2004,1,5,tzinfo=timezone('UTC'))) |
|---|
| 1085 | #self.assertRaises(MaKaCError,s1.setDates,datetime(2004,1,3,tzinfo=timezone('UTC')),datetime(2004,1,8,tzinfo=timezone('UTC'))) |
|---|
| 1086 | #self.assertRaises(MaKaCError,s1.setDates,datetime(2005,1,1,11,0,tzinfo=timezone('UTC')),datetime(2004,1,6,tzinfo=timezone('UTC'))) |
|---|
| 1087 | #self.assertRaises(MaKaCError,s1.setDates,datetime(2005,1,1,11,0,tzinfo=timezone('UTC')),datetime(2004,1,8,tzinfo=timezone('UTC'))) |
|---|
| 1088 | |
|---|
| 1089 | def testContributionInclusion(self): |
|---|
| 1090 | session1,session2=Session(),Session() |
|---|
| 1091 | self._conf.addSession(session1) |
|---|
| 1092 | self._conf.addSession(session2) |
|---|
| 1093 | contrib1=Contribution() |
|---|
| 1094 | session1.addContribution(contrib1) |
|---|
| 1095 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 1096 | self.assert_(session1.hasContribution(contrib1)) |
|---|
| 1097 | self.assert_(not session2.hasContribution(contrib1)) |
|---|
| 1098 | session1.removeContribution(contrib1) |
|---|
| 1099 | session2.addContribution(contrib1) |
|---|
| 1100 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 1101 | self.assert_(not session1.hasContribution(contrib1)) |
|---|
| 1102 | self.assert_(session2.hasContribution(contrib1)) |
|---|
| 1103 | session2.removeContribution(contrib1) |
|---|
| 1104 | self.assert_(self._conf.hasContribution(contrib1)) |
|---|
| 1105 | self.assert_(not session1.hasContribution(contrib1)) |
|---|
| 1106 | self.assert_(not session2.hasContribution(contrib1)) |
|---|
| 1107 | |
|---|
| 1108 | def testCoordination(self): |
|---|
| 1109 | session1,session2,session3=Session(),Session(),Session() |
|---|
| 1110 | self._conf.addSession(session1) |
|---|
| 1111 | self._conf.addSession(session2) |
|---|
| 1112 | c1,c2=Avatar(),Avatar() |
|---|
| 1113 | c1.setId("1") |
|---|
| 1114 | c2.setId("2") |
|---|
| 1115 | session1.addCoordinator(c1) |
|---|
| 1116 | self.assert_(c1 in session1.getCoordinatorList()) |
|---|
| 1117 | self.assert_(len(session1.getCoordinatorList())==1) |
|---|
| 1118 | self.assert_(session1.isCoordinator(c1)) |
|---|
| 1119 | self.assert_(not session1.isCoordinator(c2)) |
|---|
| 1120 | self.assert_(not session1.isCoordinator(None)) |
|---|
| 1121 | self.assert_(session1 in self._conf.getCoordinatedSessions(c1)) |
|---|
| 1122 | self.assert_(len(self._conf.getCoordinatedSessions(c1))==1) |
|---|
| 1123 | self.assert_(len(self._conf.getCoordinatedSessions(c2))==0) |
|---|
| 1124 | self._conf.addSessionCoordinator(session1,c1) |
|---|
| 1125 | self.assert_(c1 in session1.getCoordinatorList()) |
|---|
| 1126 | self.assert_(len(session1.getCoordinatorList())==1) |
|---|
| 1127 | self.assert_(session1.isCoordinator(c1)) |
|---|
| 1128 | self.assert_(not session1.isCoordinator(c2)) |
|---|
| 1129 | self.assert_(not session1.isCoordinator(None)) |
|---|
| 1130 | self.assert_(session1 in self._conf.getCoordinatedSessions(c1)) |
|---|
| 1131 | self.assert_(len(self._conf.getCoordinatedSessions(c1))==1) |
|---|
| 1132 | self.assert_(len(self._conf.getCoordinatedSessions(c2))==0) |
|---|
| 1133 | self._conf.addSessionCoordinator(session2,c2) |
|---|
| 1134 | self.assert_(c2 in session2.getCoordinatorList()) |
|---|
| 1135 | self.assert_(not session1.isCoordinator(c2)) |
|---|
| 1136 | self.assert_(session2 in self._conf.getCoordinatedSessions(c2)) |
|---|
| 1137 | self.assert_(len(self._conf.getCoordinatedSessions(c1))==1) |
|---|
| 1138 | self.assert_(len(self._conf.getCoordinatedSessions(c2))==1) |
|---|
| 1139 | self._conf.addSession(session3) |
|---|
| 1140 | session3.addCoordinator(c2) |
|---|
| 1141 | self.assert_(c2 in session3.getCoordinatorList()) |
|---|
| 1142 | self.assert_(not session1.isCoordinator(c2)) |
|---|
| 1143 | self.assert_(session3 in self._conf.getCoordinatedSessions(c2)) |
|---|
| 1144 | self.assert_(session2 in self._conf.getCoordinatedSessions(c2)) |
|---|
| 1145 | self.assert_(len(self._conf.getCoordinatedSessions(c1))==1) |
|---|
| 1146 | self.assert_(len(self._conf.getCoordinatedSessions(c2))==2) |
|---|
| 1147 | self._conf.removeSession(session1) |
|---|
| 1148 | self.assert_(session1 not in self._conf.getCoordinatedSessions(c1)) |
|---|
| 1149 | self.assert_(len(self._conf.getCoordinatedSessions(c1))==0) |
|---|
| 1150 | self.assert_(len(self._conf.getCoordinatedSessions(c2))==2) |
|---|
| 1151 | session2.removeCoordinator(c2) |
|---|
| 1152 | self.assert_(c2 not in session2.getCoordinatorList()) |
|---|
| 1153 | self.assert_(c2 in session3.getCoordinatorList()) |
|---|
| 1154 | self.assert_(session3 in self._conf.getCoordinatedSessions(c2)) |
|---|
| 1155 | self.assert_(session2 not in self._conf.getCoordinatedSessions(c2)) |
|---|
| 1156 | self.assert_(len(self._conf.getCoordinatedSessions(c1))==0) |
|---|
| 1157 | self.assert_(len(self._conf.getCoordinatedSessions(c2))==1) |
|---|
| 1158 | |
|---|
| 1159 | |
|---|
| 1160 | class TestSchedule(unittest.TestCase): |
|---|
| 1161 | """Tests the schedule management functions |
|---|
| 1162 | """ |
|---|
| 1163 | |
|---|
| 1164 | def setUp( self ): |
|---|
| 1165 | from MaKaC.user import Avatar |
|---|
| 1166 | a = Avatar() |
|---|
| 1167 | a.setId("creator") |
|---|
| 1168 | from MaKaC.conference import Conference |
|---|
| 1169 | self._conf = Conference( a ) |
|---|
| 1170 | category=conference.Category() |
|---|
| 1171 | self._conf.addOwner(category) |
|---|
| 1172 | self._conf.setTimezone('UTC') |
|---|
| 1173 | |
|---|
| 1174 | def testTypeSetUp(self): |
|---|
| 1175 | #test setting up the schedule type of a session works correctly |
|---|
| 1176 | self._conf.setDates(datetime(2004,1,1,9,0,tzinfo=timezone('UTC')),datetime(2004,1,5,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1177 | session=Session() |
|---|
| 1178 | session.setStartDate(datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1179 | session.setDuration(hours=10,minutes=0) |
|---|
| 1180 | self._conf.addSession(session) |
|---|
| 1181 | slot1=SessionSlot(session) |
|---|
| 1182 | session.addSlot(slot1) |
|---|
| 1183 | c1,c2,c3=Contribution(),Contribution(),Contribution() |
|---|
| 1184 | session.addContribution(c1) |
|---|
| 1185 | session.addContribution(c2) |
|---|
| 1186 | session.addContribution(c3) |
|---|
| 1187 | slot1.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 1188 | slot1.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 1189 | slot1.getSchedule().addEntry(c3.getSchEntry()) |
|---|
| 1190 | self.assert_(c1.getSchEntry()==slot1.getSchedule().getEntries()[0]) |
|---|
| 1191 | self.assert_(c2.getSchEntry()==slot1.getSchedule().getEntries()[1]) |
|---|
| 1192 | self.assert_(c3.getSchEntry()==slot1.getSchedule().getEntries()[2]) |
|---|
| 1193 | self.assert_(session.getScheduleType()=="standard") |
|---|
| 1194 | self.assert_(slot1.getSchedule().__class__==conference.SlotSchedule) |
|---|
| 1195 | session.setScheduleType("poster") |
|---|
| 1196 | self.assert_(session.getScheduleType()=="poster") |
|---|
| 1197 | self.assert_(slot1.getSchedule().__class__==conference.PosterSlotSchedule) |
|---|
| 1198 | self.assert_(len(slot1.getSchedule().getEntries())==0) |
|---|
| 1199 | |
|---|
| 1200 | def testSessionDates(self): |
|---|
| 1201 | from MaKaC.conference import Session,SessionSlot, Conference |
|---|
| 1202 | self._conf.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1203 | self._conf.setEndDate(datetime(2004,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1204 | session1=Session() |
|---|
| 1205 | session1.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1206 | session1.setEndDate(datetime(2004,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1207 | self._conf.addSession(session1) |
|---|
| 1208 | slot1=SessionSlot(session1) |
|---|
| 1209 | slot1.setDuration(hours=2,minutes=0) |
|---|
| 1210 | slot1.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1211 | session1.addSlot(slot1) |
|---|
| 1212 | # ------- SESSIONS ------- |
|---|
| 1213 | #not true anymore, sessions are automatically extended |
|---|
| 1214 | # # Session start date can not be bigger than the first slot start date |
|---|
| 1215 | # self.assertRaises(MaKaCError, session1.setStartDate, datetime(2004,1,1,12,0,tzinfo=timezone('UTC'))) |
|---|
| 1216 | # # Session end date can not be prior than the last slot end date |
|---|
| 1217 | # self.assertRaises(MaKaCError, session1.setEndDate, datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1218 | # Session duration must be bigger than zero. |
|---|
| 1219 | self.assertRaises(MaKaCError, session1.setDuration, 0,0) |
|---|
| 1220 | # Session start date can not be prior than the conference end date |
|---|
| 1221 | #self.assertRaises(MaKaCError, session1.setStartDate, datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1222 | # Session end date can not be bigger than the conference end date |
|---|
| 1223 | #self.assertRaises(MaKaCError, session1.setEndDate, datetime(2004,1,1,15,1,tzinfo=timezone('UTC'))) |
|---|
| 1224 | # Session end date can not be bigger than the conference end date |
|---|
| 1225 | #self.assertRaises(MaKaCError, session1.setDuration, 6,1) |
|---|
| 1226 | |
|---|
| 1227 | # ------- SESSION SLOTS ------- |
|---|
| 1228 | self._conf.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1229 | self._conf.setEndDate(datetime(2004,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1230 | session1.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1231 | session1.setEndDate(datetime(2004,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1232 | # Session slot duration must be bigger than zero. |
|---|
| 1233 | self.assertRaises(MaKaCError, slot1.setDuration, 0,0,0) |
|---|
| 1234 | # Forbid to create a slot alogn several days |
|---|
| 1235 | self._conf.setEndDate(datetime(2005,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1236 | self.assertRaises(MaKaCError, slot1.setDuration, 1,0,1) |
|---|
| 1237 | # Slot start date has to be between the session ones |
|---|
| 1238 | #self.assertRaises(MaKaCError, slot1.setStartDate, datetime(2004,1,1,9,59,tzinfo=timezone('UTC'))) |
|---|
| 1239 | # Slot end date has to be between the session ones |
|---|
| 1240 | #self.assertRaises(MaKaCError, slot1.setDuration, 0,5,1) |
|---|
| 1241 | # If the duration is modified and any of the slot entries is affected then an excetpion is raised |
|---|
| 1242 | c1,c2,c3=Contribution(),Contribution(),Contribution() |
|---|
| 1243 | session1.addContribution(c1) |
|---|
| 1244 | session1.addContribution(c2) |
|---|
| 1245 | session1.addContribution(c3) |
|---|
| 1246 | c1.setDuration(0,30) |
|---|
| 1247 | c2.setDuration(0,30) |
|---|
| 1248 | c3.setDuration(0,30) |
|---|
| 1249 | from MaKaC.schedule import BreakTimeSchEntry |
|---|
| 1250 | b1=BreakTimeSchEntry() |
|---|
| 1251 | slot1.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 1252 | slot1.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 1253 | slot1.getSchedule().addEntry(c3.getSchEntry()) |
|---|
| 1254 | self.assertRaises(MaKaCError, slot1.setDuration, 0,1,29) |
|---|
| 1255 | # Check that the duration of the entries do not overpass the slot duration |
|---|
| 1256 | slot1.setDuration(hours=1,minutes=30) |
|---|
| 1257 | #self.assertRaises(MaKaCError,c3.setDuration,0,31) |
|---|
| 1258 | c3.setDuration(0,30) |
|---|
| 1259 | slot1.setDuration(hours=2,minutes=0) |
|---|
| 1260 | slot1.getSchedule().addEntry(b1) |
|---|
| 1261 | #self.assertRaises(MaKaCError,b1.setDuration,0,31) |
|---|
| 1262 | #Check that entries start date is not less than owner start date |
|---|
| 1263 | #self.assertRaises(MaKaCError,c1.setStartDate,datetime(2004,1,1,9,59,tzinfo=timezone('UTC'))) |
|---|
| 1264 | #self.assertRaises(MaKaCError,b1.setStartDate,datetime(2004,1,1,9,59,tzinfo=timezone('UTC'))) |
|---|
| 1265 | #Move all the entries |
|---|
| 1266 | slot3=SessionSlot(session1) |
|---|
| 1267 | slot3.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1268 | slot3.setDuration(hours=3,minutes=0) |
|---|
| 1269 | session1.addSlot(slot3) |
|---|
| 1270 | c4,c5=Contribution(),Contribution() |
|---|
| 1271 | session1.addContribution(c4) |
|---|
| 1272 | session1.addContribution(c5) |
|---|
| 1273 | c4.setTitle("campeon") |
|---|
| 1274 | c5.setTitle("campeonisimo") |
|---|
| 1275 | c4.setStartDate(datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1276 | c4.setDuration(0,30) |
|---|
| 1277 | c5.setDuration(0,30) |
|---|
| 1278 | b2=BreakTimeSchEntry() |
|---|
| 1279 | b2.setDuration(0,30) |
|---|
| 1280 | b2.setTitle("breaaaaaaak") |
|---|
| 1281 | slot3.getSchedule().addEntry(c4.getSchEntry()) |
|---|
| 1282 | slot3.getSchedule().addEntry(c5.getSchEntry()) |
|---|
| 1283 | slot3.getSchedule().addEntry(b2) |
|---|
| 1284 | self.assert_(c4.getStartDate() == datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1285 | slot3.setStartDate(datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1286 | #self.assert_(c4.getStartDate() == datetime(2004,1,1,12,0,tzinfo=timezone('UTC'))) |
|---|
| 1287 | |
|---|
| 1288 | |
|---|
| 1289 | # ------- CONFERENCE ------- |
|---|
| 1290 | # Conference should not start after a entry |
|---|
| 1291 | #self.assertRaises(MaKaCError,self._conf.setStartDate,datetime(2004,1,1,10,1,tzinfo=timezone('UTC'))) |
|---|
| 1292 | # Conference should not finish before a entry |
|---|
| 1293 | #self.assertRaises(MaKaCError,self._conf.setEndDate,datetime(2004,1,1,14,59,tzinfo=timezone('UTC'))) |
|---|
| 1294 | # Conference should not start after a entry (TIME) |
|---|
| 1295 | #self.assertRaises(MaKaCError,self._conf.setStartTime,10,1) |
|---|
| 1296 | # Conference should not finish before a entry (TIME) |
|---|
| 1297 | self._conf.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1298 | self._conf.setEndDate(datetime(2005,1,1,18,0,tzinfo=timezone('UTC'))) |
|---|
| 1299 | session2=Session() |
|---|
| 1300 | self._conf.addSession(session2) |
|---|
| 1301 | session2.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1302 | session2.setEndDate(datetime(2005,1,1,18,0,tzinfo=timezone('UTC'))) |
|---|
| 1303 | slot2=SessionSlot(session2) |
|---|
| 1304 | slot2.setDuration(hours=2,minutes=0) |
|---|
| 1305 | slot2.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1306 | session2.addSlot(slot2) |
|---|
| 1307 | #self.assertRaises(MaKaCError,self._conf.setEndTime,17,59) |
|---|
| 1308 | |
|---|
| 1309 | |
|---|
| 1310 | def testSlots(self): |
|---|
| 1311 | self._conf.setDates(datetime(2004,1,1,9,0,tzinfo=timezone('UTC')),datetime(2004,1,5,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1312 | session1=Session() |
|---|
| 1313 | session1.setStartDate(datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1314 | session1.setDuration(hours=10,minutes=0) |
|---|
| 1315 | self._conf.addSession(session1) |
|---|
| 1316 | slot1=SessionSlot(session1) |
|---|
| 1317 | slot1.setDuration(hours=2,minutes=0) |
|---|
| 1318 | session1.addSlot(slot1) |
|---|
| 1319 | self.assert_(slot1.getSessionSchEntry() in session1.getSchedule().getEntries()) |
|---|
| 1320 | self.assert_(slot1.getStartDate()==session1.getStartDate()) |
|---|
| 1321 | self.assert_(slot1.getDuration().seconds==7200) |
|---|
| 1322 | slot2=SessionSlot(session1) |
|---|
| 1323 | slot2.setDuration(hours=2,minutes=0) |
|---|
| 1324 | session1.addSlot(slot2) |
|---|
| 1325 | self.assert_(slot1.getSessionSchEntry()==session1.getSchedule().getEntries()[0]) |
|---|
| 1326 | self.assert_(slot1.getStartDate()==session1.getStartDate()) |
|---|
| 1327 | self.assert_(slot1.getDuration().seconds==7200) |
|---|
| 1328 | self.assert_(slot2.getSessionSchEntry()==session1.getSchedule().getEntries()[1]) |
|---|
| 1329 | self.assert_(slot2.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1330 | self.assert_(slot2.getDuration().seconds==7200) |
|---|
| 1331 | slot2.setStartDate(datetime(2004,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1332 | self.assert_(slot1.getSessionSchEntry()==session1.getSchedule().getEntries()[0]) |
|---|
| 1333 | self.assert_(slot1.getStartDate()==session1.getStartDate()) |
|---|
| 1334 | self.assert_(slot1.getDuration().seconds==7200) |
|---|
| 1335 | self.assert_(slot2.getSessionSchEntry()==session1.getSchedule().getEntries()[1]) |
|---|
| 1336 | self.assert_(slot2.getStartDate()==datetime(2004,1,1,15,0,tzinfo=timezone('UTC'))) |
|---|
| 1337 | self.assert_(slot2.getDuration().seconds==7200) |
|---|
| 1338 | slot1.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1339 | slot2.setStartDate(datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1340 | self.assert_(slot2.getStartDate()==datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1341 | #slot1.setStartDate(datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1342 | #slot2.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1343 | self.assert_(slot1.getSessionSchEntry()==session1.getSchedule().getEntries()[1]) |
|---|
| 1344 | self.assert_(slot1.getDuration().seconds==7200) |
|---|
| 1345 | self.assert_(slot2.getSessionSchEntry()==session1.getSchedule().getEntries()[0]) |
|---|
| 1346 | self.assert_(slot2.getStartDate()==datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1347 | self.assert_(slot2.getDuration().seconds==7200) |
|---|
| 1348 | |
|---|
| 1349 | def testContributions(self): |
|---|
| 1350 | self._conf.setDates(datetime(2004,1,1,9,0,tzinfo=timezone('UTC')),datetime(2004,1,5,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1351 | from MaKaC.conference import Session,Contribution,SessionSlot |
|---|
| 1352 | self._conf.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1353 | self._conf.setEndDate(datetime(2005,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1354 | session1=Session() |
|---|
| 1355 | self._conf.addSession(session1) |
|---|
| 1356 | session1.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1357 | session1.setDuration(hours=5,minutes=0) |
|---|
| 1358 | slot1=SessionSlot(session1) |
|---|
| 1359 | slot1.setDuration(hours=2,minutes=0) |
|---|
| 1360 | session1.addSlot(slot1) |
|---|
| 1361 | slot2=SessionSlot(session1) |
|---|
| 1362 | slot2.setDuration(hours=2,minutes=0) |
|---|
| 1363 | session1.addSlot(slot2) |
|---|
| 1364 | self.assert_(slot2.getStartDate()==datetime(2004,1,1,12,0,tzinfo=timezone('UTC'))) |
|---|
| 1365 | c1,c2,c3=Contribution(),Contribution(),Contribution() |
|---|
| 1366 | session1.addContribution(c1) |
|---|
| 1367 | session1.addContribution(c2) |
|---|
| 1368 | session1.addContribution(c3) |
|---|
| 1369 | c1.setDuration(0,30) |
|---|
| 1370 | c2.setDuration(0,30) |
|---|
| 1371 | c3.setDuration(0,30) |
|---|
| 1372 | from MaKaC.errors import MaKaCError |
|---|
| 1373 | #self.assertRaises(MaKaCError,slot1.getSchedule().addEntry,c1.getSchEntry()) |
|---|
| 1374 | slot1.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 1375 | slot1.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 1376 | slot1.getSchedule().addEntry(c3.getSchEntry()) |
|---|
| 1377 | self.assert_(c1.getStartDate()==datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1378 | self.assert_(c2.getStartDate()==datetime(2004,1,1,10,30,tzinfo=timezone('UTC'))) |
|---|
| 1379 | self.assert_(c3.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1380 | #slot2.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 1381 | #self.assert_(c1.getStartDate()==datetime(2004,1,1,12,0,tzinfo=timezone('UTC'))) |
|---|
| 1382 | #self.assert_(c2.getStartDate()==datetime(2004,1,1,10,30,tzinfo=timezone('UTC'))) |
|---|
| 1383 | #self.assert_(c3.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1384 | from MaKaC.schedule import BreakTimeSchEntry |
|---|
| 1385 | b1=BreakTimeSchEntry() |
|---|
| 1386 | slot1.getSchedule().addEntry(b1) |
|---|
| 1387 | self.assert_(b1 in slot1.getSchedule().getEntries()) |
|---|
| 1388 | #self.assert_(b1.getStartDate()==datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1389 | |
|---|
| 1390 | def testMoveScheduledContribToSession(self): |
|---|
| 1391 | #tests that moving scheduled contributions at conference level into a |
|---|
| 1392 | # session works correctly: removes them from the conference schedule |
|---|
| 1393 | # and includes them into the selected session |
|---|
| 1394 | self._conf.setDates(datetime(2004,1,1,9,0,tzinfo=timezone('UTC')),datetime(2004,1,5,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1395 | session1=Session() |
|---|
| 1396 | session1.setStartDate(datetime(2004,1,1,9,0,tzinfo=timezone('UTC'))) |
|---|
| 1397 | session1.setDuration(hours=1,minutes=0) |
|---|
| 1398 | self._conf.addSession(session1) |
|---|
| 1399 | c1,c2=Contribution(),Contribution() |
|---|
| 1400 | self._conf.addContribution(c1) |
|---|
| 1401 | self._conf.addContribution(c2) |
|---|
| 1402 | self._conf.getSchedule().addEntry(c1.getSchEntry()) |
|---|
| 1403 | self._conf.getSchedule().addEntry(c2.getSchEntry()) |
|---|
| 1404 | self.assert_(c1.isScheduled()) |
|---|
| 1405 | self.assert_(c2.isScheduled()) |
|---|
| 1406 | session1.addContribution(c1) |
|---|
| 1407 | self.assert_(not c1.isScheduled()) |
|---|
| 1408 | self.assert_(c2.isScheduled()) |
|---|
| 1409 | |
|---|
| 1410 | |
|---|
| 1411 | class TestPosterSchedule(unittest.TestCase): |
|---|
| 1412 | """Tests the schedule for posters like schedules management functions |
|---|
| 1413 | """ |
|---|
| 1414 | |
|---|
| 1415 | def setUp( self ): |
|---|
| 1416 | a=Avatar() |
|---|
| 1417 | a.setId("creator") |
|---|
| 1418 | self._conf=Conference(a) |
|---|
| 1419 | category=conference.Category() |
|---|
| 1420 | self._conf.addOwner(category) |
|---|
| 1421 | self._conf.setTimezone('UTC') |
|---|
| 1422 | self._conf.setStartDate(datetime(2004,1,1,10,0,tzinfo=timezone('UTC'))) |
|---|
| 1423 | self._conf.setEndDate(datetime(2004,1,1,13,0,tzinfo=timezone('UTC'))) |
|---|
| 1424 | self._session=Session() |
|---|
| 1425 | self._session.setStartDate(datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1426 | self._session.setEndDate(datetime(2004,1,1,13,0,tzinfo=timezone('UTC'))) |
|---|
| 1427 | self._conf.addSession(self._session) |
|---|
| 1428 | self._slot1=SessionSlot(self._session) |
|---|
| 1429 | self._slot1.setStartDate(datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1430 | self._slot1.setDuration(hours=1) |
|---|
| 1431 | self._session.addSlot(self._slot1) |
|---|
| 1432 | self._session.setScheduleType("poster") |
|---|
| 1433 | self._session.setContribDuration(1,0) |
|---|
| 1434 | |
|---|
| 1435 | def testBasic(self): |
|---|
| 1436 | #tests the basic adding of entries to a poster like timetable |
|---|
| 1437 | p1,p2,p3=Contribution(),Contribution(),Contribution() |
|---|
| 1438 | self._session.addContribution(p1) |
|---|
| 1439 | self._session.addContribution(p2) |
|---|
| 1440 | self._session.addContribution(p3) |
|---|
| 1441 | self._slot1.getSchedule().addEntry(p1.getSchEntry()) |
|---|
| 1442 | self._slot1.getSchedule().addEntry(p2.getSchEntry()) |
|---|
| 1443 | self._slot1.getSchedule().addEntry(p3.getSchEntry()) |
|---|
| 1444 | self.assert_(p1.getDuration()==self._session.getContribDuration()) |
|---|
| 1445 | self.assert_(p2.getDuration()==self._session.getContribDuration()) |
|---|
| 1446 | self.assert_(p3.getDuration()==self._session.getContribDuration()) |
|---|
| 1447 | self.assert_(p1.getStartDate()==self._slot1.getStartDate()) |
|---|
| 1448 | self.assert_(p2.getStartDate()==self._slot1.getStartDate()) |
|---|
| 1449 | self.assert_(p3.getStartDate()==self._slot1.getStartDate()) |
|---|
| 1450 | self.assert_(p1.getSchEntry()==self._slot1.getSchedule().getEntries()[0]) |
|---|
| 1451 | self.assert_(p2.getSchEntry()==self._slot1.getSchedule().getEntries()[1]) |
|---|
| 1452 | self.assert_(p3.getSchEntry()==self._slot1.getSchedule().getEntries()[2]) |
|---|
| 1453 | self._session.removeContribution(p2) |
|---|
| 1454 | self.assert_(p1.getDuration()==self._session.getContribDuration()) |
|---|
| 1455 | self.assert_(p3.getDuration()==self._session.getContribDuration()) |
|---|
| 1456 | self.assert_(p1.getStartDate()==self._slot1.getStartDate()) |
|---|
| 1457 | self.assert_(p3.getStartDate()==self._slot1.getStartDate()) |
|---|
| 1458 | self.assert_(p1.getSchEntry()==self._slot1.getSchedule().getEntries()[0]) |
|---|
| 1459 | self.assert_(p3.getSchEntry()==self._slot1.getSchedule().getEntries()[1]) |
|---|
| 1460 | |
|---|
| 1461 | def testStartDateNotChanging(self): |
|---|
| 1462 | #tests that changing the start date of an entry scheduled within a |
|---|
| 1463 | # poster schedule has no effect |
|---|
| 1464 | p1=Contribution() |
|---|
| 1465 | self._session.addContribution(p1) |
|---|
| 1466 | self._slot1.getSchedule().addEntry(p1.getSchEntry()) |
|---|
| 1467 | self.assert_(p1.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1468 | p1.setStartDate(datetime(2004,1,1,11,25,tzinfo=timezone('UTC'))) |
|---|
| 1469 | self.assert_(p1.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1470 | |
|---|
| 1471 | def testChangeSlotStartDate(self): |
|---|
| 1472 | #checks that changing the start date of a slot changes all the entries' |
|---|
| 1473 | p1,p2=Contribution(),Contribution() |
|---|
| 1474 | self._session.addContribution(p1) |
|---|
| 1475 | self._session.addContribution(p2) |
|---|
| 1476 | self._slot1.getSchedule().addEntry(p1.getSchEntry()) |
|---|
| 1477 | self._slot1.getSchedule().addEntry(p2.getSchEntry()) |
|---|
| 1478 | self.assert_(p1.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1479 | self.assert_(p2.getStartDate()==datetime(2004,1,1,11,0,tzinfo=timezone('UTC'))) |
|---|
| 1480 | self._slot1.setStartDate(datetime(2004,1,1,11,25,tzinfo=timezone('UTC'))) |
|---|
| 1481 | #self.assert_(p1.getStartDate()==datetime(2004,1,1,11,25,tzinfo=timezone('UTC'))) |
|---|
| 1482 | #self.assert_(p2.getStartDate()==datetime(2004,1,1,11,25,tzinfo=timezone('UTC'))) |
|---|
| 1483 | |
|---|
| 1484 | class TestCoordinatorsIndexComponent(unittest.TestCase): |
|---|
| 1485 | """ |
|---|
| 1486 | """ |
|---|
| 1487 | |
|---|
| 1488 | def setUp( self ): |
|---|
| 1489 | pass |
|---|
| 1490 | |
|---|
| 1491 | def test(self): |
|---|
| 1492 | idx=SCIndex() |
|---|
| 1493 | c1=Avatar() |
|---|
| 1494 | c1.setId("1") |
|---|
| 1495 | s1=Session() |
|---|
| 1496 | idx.index(c1,s1) |
|---|
| 1497 | self.assert_(s1 in idx.getSessions(c1)) |
|---|
| 1498 | self.assert_(len(idx.getSessions(c1))==1) |
|---|
| 1499 | c2=Avatar() |
|---|
| 1500 | c2.setId("2") |
|---|
| 1501 | idx.index(c2,s1) |
|---|
| 1502 | self.assert_(s1 in idx.getSessions(c1)) |
|---|
| 1503 | self.assert_(len(idx.getSessions(c1))==1) |
|---|
| 1504 | self.assert_(s1 in idx.getSessions(c2)) |
|---|
| 1505 | self.assert_(len(idx.getSessions(c2))==1) |
|---|
| 1506 | s2=Session() |
|---|
| 1507 | idx.index(c2,s2) |
|---|
| 1508 | self.assert_(s1 in idx.getSessions(c1)) |
|---|
| 1509 | self.assert_(len(idx.getSessions(c1))==1) |
|---|
| 1510 | self.assert_(s1 in idx.getSessions(c2)) |
|---|
| 1511 | self.assert_(s2 in idx.getSessions(c2)) |
|---|
| 1512 | self.assert_(len(idx.getSessions(c2))==2) |
|---|
| 1513 | idx.unindex(c2,s2) |
|---|
| 1514 | self.assert_(s1 in idx.getSessions(c1)) |
|---|
| 1515 | self.assert_(len(idx.getSessions(c1))==1) |
|---|
| 1516 | self.assert_(s1 in idx.getSessions(c2)) |
|---|
| 1517 | self.assert_(s2 not in idx.getSessions(c2)) |
|---|
| 1518 | self.assert_(len(idx.getSessions(c2))==1) |
|---|
| 1519 | |
|---|
| 1520 | |
|---|
| 1521 | #from testWebInterface.py should be renamed to testContributions.py anyway |
|---|
| 1522 | """Contains tests regarding some scenarios related to contribution list display. |
|---|
| 1523 | """ |
|---|
| 1524 | class TestContributionList(unittest.TestCase): |
|---|
| 1525 | """Tests the contribution list functions |
|---|
| 1526 | """ |
|---|
| 1527 | |
|---|
| 1528 | def setUp( self ): |
|---|
| 1529 | from MaKaC.user import Avatar |
|---|
| 1530 | a = Avatar() |
|---|
| 1531 | a.setId("creator") |
|---|
| 1532 | from MaKaC.conference import Conference |
|---|
| 1533 | self._conf=Conference(a) |
|---|
| 1534 | category=conference.Category() |
|---|
| 1535 | self._conf.addOwner(category) |
|---|
| 1536 | self._conf.setTimezone('UTC') |
|---|
| 1537 | self._conf.setDates(datetime(2000,1,1,tzinfo=timezone('UTC')),datetime(2020,1,1,tzinfo=timezone('UTC'))) |
|---|
| 1538 | |
|---|
| 1539 | def testSorting( self ): |
|---|
| 1540 | from MaKaC.conference import Contribution, ContributionType, Session, Track |
|---|
| 1541 | from MaKaC.webinterface.common import contribFilters |
|---|
| 1542 | from MaKaC.common.filters import SimpleFilter |
|---|
| 1543 | contrib1 = Contribution() |
|---|
| 1544 | contrib2 = Contribution() |
|---|
| 1545 | contrib3 = Contribution() |
|---|
| 1546 | self._conf.addContribution( contrib1 ) |
|---|
| 1547 | self._conf.addContribution( contrib2 ) |
|---|
| 1548 | self._conf.addContribution( contrib3 ) |
|---|
| 1549 | # Sorting by ID |
|---|
| 1550 | sortingCrit = contribFilters.SortingCriteria( ["number"] ) |
|---|
| 1551 | f = SimpleFilter( None, sortingCrit ) |
|---|
| 1552 | contribList = f.apply(self._conf.getContributionList()) |
|---|
| 1553 | self.assert_( len(contribList) == 3 ) |
|---|
| 1554 | self.assert_( contribList[0] == contrib1 ) |
|---|
| 1555 | self.assert_( contribList[1] == contrib2 ) |
|---|
| 1556 | self.assert_( contribList[2] == contrib3 ) |
|---|
| 1557 | #Sorting by Date |
|---|
| 1558 | contrib1.setStartDate(datetime(2004, 5, 1, 10, 30,tzinfo=timezone('UTC'))) |
|---|
| 1559 | contrib2.setStartDate(datetime(2003, 5, 1, 10, 30,tzinfo=timezone('UTC'))) |
|---|
| 1560 | sortingCrit = contribFilters.SortingCriteria( ["date"] ) |
|---|
| 1561 | f = SimpleFilter( None, sortingCrit ) |
|---|
| 1562 | contribList = f.apply(self._conf.getContributionList()) |
|---|
| 1563 | self.assert_( len(contribList) == 3 ) |
|---|
| 1564 | self.assert_( contribList[0] == contrib2 ) |
|---|
| 1565 | self.assert_( contribList[1] == contrib1 ) |
|---|
| 1566 | self.assert_( contribList[2] == contrib3 ) |
|---|
| 1567 | # Sorting by Contribution Type |
|---|
| 1568 | contribType1 = ContributionType("oral presentation", "no description", self._conf) |
|---|
| 1569 | contribType2 = ContributionType("poster", "no description", self._conf) |
|---|
| 1570 | contrib1.setType(contribType1) |
|---|
| 1571 | contrib2.setType(contribType2) |
|---|
| 1572 | sortingCrit = contribFilters.SortingCriteria( ["type"] ) |
|---|
| 1573 | f = SimpleFilter( None, sortingCrit ) |
|---|
| 1574 | contribList = f.apply(self._conf.getContributionList()) |
|---|
| 1575 | self.assert_( len(contribList) == 3 ) |
|---|
| 1576 | self.assert_( contribList[0] == contrib1 ) |
|---|
| 1577 | self.assert_( contribList[1] == contrib2 ) |
|---|
| 1578 | self.assert_( contribList[2] == contrib3 ) |
|---|
| 1579 | # Sorting by Session |
|---|
| 1580 | session1 = Session() |
|---|
| 1581 | self._conf.addSession(session1) |
|---|
| 1582 | session2 = Session() |
|---|
| 1583 | self._conf.addSession(session2) |
|---|
| 1584 | contrib1.setSession(session1) |
|---|
| 1585 | contrib2.setSession(session2) |
|---|
| 1586 | sortingCrit = contribFilters.SortingCriteria( ["session"] ) |
|---|
| 1587 | f = SimpleFilter( None, sortingCrit ) |
|---|
| 1588 | contribList = f.apply(self._conf.getContributionList()) |
|---|
| 1589 | self.assert_( len(contribList) == 3 ) |
|---|
| 1590 | self.assert_(contrib1 in contribList) |
|---|
| 1591 | self.assert_(contrib2 in contribList) |
|---|
| 1592 | self.assert_(contrib3 in contribList) |
|---|
| 1593 | # Sorting by Track |
|---|
| 1594 | track1 = Track() |
|---|
| 1595 | track1.setTitle("3") |
|---|
| 1596 | track1.setConference(self._conf) |
|---|
| 1597 | track2 = Track() |
|---|
| 1598 | track2.setTitle("1") |
|---|
| 1599 | track2.setConference(self._conf) |
|---|
| 1600 | contrib1.setTrack(track1) |
|---|
| 1601 | contrib2.setTrack(track2) |
|---|
| 1602 | sortingCrit = contribFilters.SortingCriteria( ["track"] ) |
|---|
| 1603 | f = SimpleFilter( None, sortingCrit ) |
|---|
| 1604 | contribList = f.apply(self._conf.getContributionList()) |
|---|
| 1605 | self.assert_( len(contribList) == 3 ) |
|---|
| 1606 | self.assert_( contribList[0] == contrib2 ) |
|---|
| 1607 | self.assert_( contribList[1] == contrib1 ) |
|---|
| 1608 | self.assert_( contribList[2] == contrib3 ) |
|---|
| 1609 | |
|---|