[FIX] Compute starting year value
[cds-indico.git] / indico / tests / default_actions.py
blob7fe00f7b58a81a5544c47d3c34d22dc06c719219
1 # -*- coding: utf-8 -*-
2 ##
3 ##
4 ## This file is part of Indico
5 ## Copyright (C) 2002 - 2012 European Organization for Nuclear Research (CERN)
6 ##
7 ## Indico is free software: you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation, either version 3 of the
10 ## License, or (at your option) any later version.
12 ## Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with Indico. If not, see <http://www.gnu.org/licenses/>.
21 from MaKaC.common import HelperMaKaCInfo
22 from MaKaC.conference import CategoryManager, DefaultConference
23 from MaKaC.user import Avatar, AvatarHolder, LoginInfo
24 from MaKaC.authentication import AuthenticatorMgr
27 def initialize_new_db(root):
28 """
29 Initializes a new DB in debug mode
30 """
32 # Reset everything
33 for e in root.keys():
34 del root[e]
36 # initialize db root
37 cm = CategoryManager()
38 cm.getRoot()
40 home = cm.getById('0')
42 # set debug mode on
43 minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
44 minfo.setDebugActive(True)
46 return home
49 def create_dummy_user():
50 """
51 Creates a dummy user for testing purposes
52 """
53 avatar = Avatar()
55 avatar.setName("fake")
56 avatar.setSurName("fake")
57 avatar.setOrganisation("fake")
58 avatar.setLang("en_GB")
59 avatar.setEmail("fake@fake.fake")
61 # registering user
62 ah = AvatarHolder()
63 ah.add(avatar)
65 # setting up the login info
66 li = LoginInfo("dummyuser", "dummyuser")
67 ih = AuthenticatorMgr()
68 userid = ih.createIdentity(li, avatar, "Local")
69 ih.add(userid)
71 # activate the account
72 avatar.activateAccount()
74 # since the DB is empty, we have to add dummy user as admin
75 minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
77 al = minfo.getAdminList()
78 al.grant(avatar)
80 dc = DefaultConference()
81 HelperMaKaCInfo.getMaKaCInfoInstance().setDefaultConference(dc)
82 return avatar