Skip to content

Commit

Permalink
Moving the request to edentest lib, removing rb http lib
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavsharma93 committed Jun 27, 2014
1 parent 1f80b68 commit d25c6c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
13 changes: 9 additions & 4 deletions controllers/default.py
Expand Up @@ -1203,9 +1203,10 @@ def audit():
return s3_rest_controller("s3", "audit")

def edentest():

"""
Special function to respond to get requests made by EdenTest
"""
arg = request.args(0)
print request.args
if arg == "deployment_settings":
asked = request.args[1:]

Expand All @@ -1215,12 +1216,16 @@ def edentest():
func_name = "get_" + setting
function = getattr(settings, func_name)
# eg value of function - settings.get_template()
value = function()
try:
value = function()
except TypeError:
continue

return_settings[setting] = value

return response.json(return_settings)

return response.json()
return response.json({})


# END =========================================================================
60 changes: 22 additions & 38 deletions tests/execution/libs/edentest_robot.py
@@ -1,57 +1,41 @@
# -*- coding: utf-8 -*-

from robot.libraries.OperatingSystem import OperatingSystem
import ast
from robot.api import logger
import os
import requests

class edentest_robot:

def __init__(self, web2py, eden_path):
logger.debug("Got arguments %s %s" % (web2py, eden_path), html=True)
self.web2py = web2py
self.eden_path = eden_path
def __init__(self, server, appname):
"""
Initialize the class variables
"""
logger.debug("Arguments %s %s" % (server, appname), html=True)

self.base_url = "http://" + server + "/" + appname

def get_deployment_settings(self, *asked):
"""
Takes the required settings as arguments eg: Template Base Public Url
Returns a list of values if len(list) > 1 else returns the first value as a
string.
Raises a warning if a setting is not found.
Returns the deployment settings asked in a dict where key is the
asked setting. It makes a get request to eden/default/edentest
and uses s3cfg to get the settings.
It uses env. proxy settings
"""
self._setcwd()

logger.info("Getting values for - %s" % " ".join(asked), html=True)
cmd = "python " + self.web2py + " --no-banner -S eden -M -R " + self.eden_path +"/tests/execution/libs/eden_interface.py -A -S"
logger.console("base_url %s" % (self.base_url))

request_url = self.base_url + "/default/edentest/deployment_settings"
for key in asked:
cmd = cmd + " " + key

rc, output = OperatingSystem().run_and_return_rc_and_output(cmd)

logger.debug("Return code for the cmd %s is %d" % (cmd, rc))
logger.info("Returned Settings %s" % output)

self._resetcwd()
request_url += "/" + key
logger.console("request_url %s" % (request_url))

output = ast.literal_eval(output)
response = requests.get(request_url)
if response.status_code != requests.codes.ok:
logger.warn("Could not contact the Eden server")
return {}
output = response.json()

for key in asked:
if key not in output.keys():
if key not in output:
logger.warn("Could not fetch the setting %s" % key)

return output

def _setcwd(self):
"""
Sets the CWD to the root of eden
"""
self._oldcwd = os.getcwd()
self._newcwd = self._oldcwd.split("/eden/")[0] + "/eden/"
os.chdir(self._newcwd)

def _resetcwd(self):
"""
Resets the CWD to the directory from which tests were run
"""
os.chdir(self._oldcwd)
3 changes: 1 addition & 2 deletions tests/implementation/resources/main.txt
@@ -1,10 +1,9 @@
*** Settings ***
Documentation Main resource file for Eden Tests
Library Selenium2Library
Library HttpLibrary.HTTP
Library Collections
Variables ../../execution/settings/config.py
Library ../../execution/libs/edentest_robot.py ${WEB2PY} ${EDEN_PATH}
Library ../../execution/libs/edentest_robot.py ${SERVER} ${APPNAME}
Resource auth.txt
Resource base.txt
Resource crud.txt
Expand Down

1 comment on commit d25c6c4

@nursix
Copy link

@nursix nursix commented on d25c6c4 Jul 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful! This can hardly be merged as-is - some settings may be sensitive (passwords!) and this controller is entirely open (no access control at all). Either you require ADMIN permissions to access this controller (preferred) or you restrict which settings can be requested through it.

Please sign in to comment.