Updated setup to allow adding collections.
[mediagoblin-automation:mediagoblin-selenium.git] / scripts / setupTests.py
1 #!/usr/bin/env python
2
3 # GNU MediaGoblin Selenium Automation
4 # Copyright (C) 2013 Emily O'Leary
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 import ConfigParser, getopt, os, subprocess, sys
20  
21 try:
22     opts, args = getopt.getopt(sys.argv[1:], "w:d:", ["working=", "data="])
23 except getopt.GetoptError as err:
24     print(err)
25     sys.exit(2)
26 data = None
27 working = None
28
29 for o, a in opts:
30     if o in ("-w", "--working"):
31         working = a
32     elif o in ("-d", "--data"):
33         data = a
34     else:
35         print ("Unhandled option")
36         sys.exit(3)
37 if (data == None or working == None):
38     print("Mandatory arguments not present.")
39     sys.exit(4)
40
41 sys.path.append(os.path.join(working,"tests/util"))
42 from util import upload
43
44 try:
45     config = ConfigParser.ConfigParser()
46     config.read(data)
47 except ConfigParser.Error as err:
48     print(err)
49 for user in config.options("users"):
50     ''' This loop creates new users from the config '''
51     newuser = config.get("users", user)
52     username,password,email = newuser.split(",")
53     subprocess.call([os.path.join(working, "mediagoblin/bin/gmg"), 
54         "-cf", os.path.join(working,"mediagoblin/mediagoblin.ini"), 
55         "adduser", 
56         "--username", username, 
57         "--password", password, 
58         "--email", email])
59 for media in config.options("media"):
60     ''' This loop uploads media from the config '''
61     newmedia = config.get("media", media)
62     username,password,uri,title,description,tags,license = newmedia.split(",")
63     mDict = {"username": username, "password": password,"uri": uri,
64             "title": title,"description": description,"tags": tags,
65             "license": license}
66     tUpload = upload.UploadFile()
67     tUpload.upload(mDict)
68
69 for collection in config.options("collections"):
70     '''This loop creates collections from the config'''
71     newcollection = config.get("collection", collection)
72     username,password,mediatitle,collectiontitle,description,note = newmedia.split(",")
73     mDict = {"username": username, "password": password, 
74             "mediatitle": mediatitle, "collectiontitle": collectiontitle, 
75             "description": description, "note": note}
76     tCollection = collection.Collection()
77     tCollection.create_by_adding(mDict)