Fixed uploading! (Yay!)
[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,"run"))
42 from util import upload,collection
43
44 print data
45 try:
46     config = ConfigParser.ConfigParser()
47     config.read(os.path.join(working,data))
48 except ConfigParser.Error as err:
49     print(err)
50 phantomjs = os.path.join(working, "ext/phantomjs")
51 print "Loading phantomjs at " + phantomjs
52 print "Creating users from config file"
53 for user in config.options("users"):
54     ''' This loop creates new users from the config '''
55     newuser = config.get("users", user)
56     username,password,email = newuser.split("|")
57     subprocess.call([os.path.join(working, "mediagoblin/bin/gmg"), 
58         "-cf", os.path.join(working,"mediagoblin/mediagoblin.ini"), 
59         "adduser", 
60         "--username", username, 
61         "--password", password, 
62         "--email", email])
63 print "Uploading media from config file"
64 for media in config.options("media"):
65     ''' This loop uploads media from the config '''
66     newmedia = config.get("media", media)
67     username,password,uri,title,description,tags,license = newmedia.split("|")
68     mDict = {"username": username, "password": password,"uri": uri,
69             "title": title,"description": description,"tags": tags,
70             "license": license}
71     tUpload = upload.UploadFile()
72     tUpload.upload(mDict,phantomjs)
73 print "Creating collections from config file"
74 for collectionitem in config.options("collections"):
75     '''This loop creates collections from the config'''
76     newcollection = config.get("collections", collectionitem)
77     username,password,mediatitle,collectiontitle,description,note = newcollection.split("|")
78     mDict = {"username": username, "password": password, 
79             "mediatitle": mediatitle, "collectiontitle": collectiontitle, 
80             "description": description, "note": note}
81     tCollection = collection.Collection()
82     tCollection.create_by_adding(mDict, phantomjs)