Exemple #1
0
    def testSanitisePassHTTP(self):
        """
        Same as testSanitisePass but do it over http and check the returned http
        codes.
        """
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'list/123/abc'
        response = makeRequest(url=url)
        assert response[1] == 200, \
             'list with 2 positional args failed: ' +\
             '. Got a return code != 200 (got %s)' % response[1] +\
             '. Returned data: %s' % response[0]
              # 2 query string args (e.g. url?int=arg1&str=arg2)
        url = self.urlbase + 'list/'
        response = makeRequest(url=url, values={'input_int':'123', 'input_str':'abc'})
        assert response[1] == 200, \
                 'list with 2 query string args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]

        # 1 positional, 1 keyword  (e.g. url/arg1/?str=arg2)
        url = self.urlbase + 'list/123/'
        response = makeRequest(url=url,
                                     values={'input_str':'abc'})
        assert response[1] == 200, \
                 'list with 1 positional, 1 keyword failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
Exemple #2
0
    def testSanitiseFailHTTP(self):
        """
        Same as testSanitisePass but do it over http and check the returned http
        codes.
        """
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'list/123/'
        response = makeRequest(url=url, accept='text/json')
        assert response[1] == 400, \
                 'list with 2 positional args failed: ' +\
                 '. Got a return code != 400 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]

        self.assertEqual(response[2], 'text/json', 'type is not text/json : %s' % type)
        # 2 query string args (e.g. url?int=arg1&str=arg2)
        url = self.urlbase + 'list'
        response = makeRequest(url=url, values={'int':'abc', 'str':'abc'})
        assert response[1] == 400, \
                 'list with 2 query string args failed: ' +\
                 '. Got a return code != 400 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]

        # 1 positional, 1 keyword  (e.g. url/arg1/?str=arg2)
        url = self.urlbase + 'list/abc'
        response = makeRequest(url=url, values={'str':'abc'})
        assert response[1] == 400, \
                 'list with 1 positional, 1 keyword failed: ' +\
                 '. Got a return code != 400 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
Exemple #3
0
    def testListTypeArgs(self):
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'listTypeArgs?aList=1'
        response = makeRequest(url=url)
        assert response[1] == 200 and response[0] == "[1]", \
                 'list args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]

        # 2 values with the same keywords (e.g. url/arg1/arg2)
        url = self.urlbase + 'listTypeArgs?aList=1&aList=2'
        response = makeRequest(url=url)
        assert response[1] == 200 and response[0] == "[1, 2]", \
                 'list args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
Exemple #4
0
 def testA(self):
     # This test doesn't actually use the type, just the same thing 5 times.
     for t in ['GET', 'POST', 'PUT', 'DELETE', 'UPDATE']:
         response = makeRequest(url=self.urlbase + '/',
                                values={'value': 1234})
         assert response[
             1] == 200, 'Got a return code != 200 (got %s)' % response[1]
Exemple #5
0
    def testListTypeArgs(self):
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'listTypeArgs?aList=1'
        response = makeRequest(url=url)
        assert response[1] == 200 and response[0] == "[1]", \
                 'list args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]


        # 2 values with the same keywords (e.g. url/arg1/arg2)
        url = self.urlbase + 'listTypeArgs?aList=1&aList=2'
        response = makeRequest(url=url)
        assert response[1] == 200 and response[0] == "[1, 2]", \
                 'list args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
Exemple #6
0
    def testDAOBasedHTTP(self):
        """
        Same as testSanitisePass but do it over http and check the returned http
        codes.
        """
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'data1/'
        response = makeRequest(url=url)
        assert response[1] == 200, \
                 'dao without args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
        self.assertEqual(response[0], '123', response[0])

        # 2 query string args (e.g. url?int=arg1&str=arg2)
        url = self.urlbase + 'data2'
        response = makeRequest(url=url, values={'num': 456})

        assert response[1] == 200, \
                 'dao with 1 args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
        #Warning quotation type matters
        #Should use encoded and decoded format
        self.assertEqual(response[0], "{'num': '456'}",
                         "should be {'num': '456'} but got %s" % response[0])

        # 1 positional, 1 keyword  (e.g. url/arg1/?str=arg2)
        url = self.urlbase + 'data3/123'
        response = makeRequest(url=url, values={'thing': 'abc'})

        assert response[1] == 200, \
                 'dao with 1 positional, 1 keyword failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
        #Warning quotation type and order matters
        #Should use encoded and decoded format
        self.assertEqual(
            response[0], "{'thing': 'abc', 'num': '123'}",
            "should be {'thing': 'abc', 'num': '123'} but got %s" %
            response[0])
Exemple #7
0
    def testDAOBasedHTTP(self):
        """
        Same as testSanitisePass but do it over http and check the returned http
        codes.
        """
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'data1/'
        response = makeRequest(url=url)
        assert response[1] == 200, \
                 'dao without args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
        self.assertEqual( response[0] ,  '123', response[0])

        # 2 query string args (e.g. url?int=arg1&str=arg2)
        url = self.urlbase + 'data2'
        response = makeRequest(url=url, values={'num':456})

        assert response[1] == 200, \
                 'dao with 1 args failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
        #Warning quotation type matters
        #Should use encoded and decoded format
        self.assertEqual( response[0] ,  "{'num': '456'}", "should be {'num': '456'} but got %s" % response[0]          )

        # 1 positional, 1 keyword  (e.g. url/arg1/?str=arg2)
        url = self.urlbase + 'data3/123'
        response = makeRequest(url=url, values={'thing':'abc'})

        assert response[1] == 200, \
                 'dao with 1 positional, 1 keyword failed: ' +\
                 '. Got a return code != 200 (got %s)' % response[1] +\
                 '. Returned data: %s' % response[0]
        #Warning quotation type and order matters
        #Should use encoded and decoded format
        self.assertEqual( response[0] ,  "{'thing': 'abc', 'num': '123'}", "should be {'thing': 'abc', 'num': '123'} but got %s" % response[0] )
    "series": series,
    "shadow": True,
    "percentage": False,
    "labels": False, # don't print labels when having legend
    "legend": "topright",
    "sort": "value"
}
plotDefinition["title"] = "Element status - hard-coded"
hardCodedPlotData = urllib.quote(json.dumps(plotDefinition, ensure_ascii = True))




# retrieve data from the system
# URL http://localhost:8888/workqueue/elementsinfo
data, _, _, _ = makeRequest(DATA_SOURCE_URL, verb = "GET", accept = "text/json+das",
                            contentType = "application/json")
data = JsonWrapper.loads(data)

systemSeries = series[:]
states = {}
for s in STATES:
    states[s] = 0 # status labels tuple
for elements in data["results"]:
    states[elements["status"]] = states[elements["status"]] + 1
for s in systemSeries:
    s["value"] = states[s["label"]]

plotDefinition["title"] = "Element status - WorkQueue"
plotDefinition["series"] = systemSeries
systemData = urllib.quote(json.dumps(plotDefinition, ensure_ascii = True))
Exemple #9
0
 def testA(self):
     for t in ['GET', 'POST', 'PUT', 'DELETE', 'UPDATE']:
         response = makeRequest(url=self.urlbase + '/', values={'value':1234})
         assert response[1] == 200, 'Got a return code != 200 (got %s)' % response[1]
Exemple #10
0
 def testA(self):
     # This test doesn't actually use the type, just the same thing 5 times.
     for t in ['GET', 'POST', 'PUT', 'DELETE', 'UPDATE']:
         response = makeRequest(url=self.urlbase + '/', values={'value':1234})
         assert response[1] == 200, 'Got a return code != 200 (got %s)' % response[1]
Exemple #11
0
 def testA(self):
     for t in ['GET', 'POST', 'PUT', 'DELETE', 'UPDATE']:
         response = makeRequest(url=self.urlbase + '/',
                                values={'value': 1234})
         assert response[
             1] == 200, 'Got a return code != 200 (got %s)' % response[1]
Exemple #12
0
{
    "title": "Element status",
    "series": series,
    "shadow": True,
    "percentage": False,
    "labels": False, # don't print labels when having legend
    "legend": "topright",
    "sort": "value"
}
plotDefinition["title"] = "Element status - hard-coded"
hardCodedPlotData = urllib.quote(json.dumps(plotDefinition, ensure_ascii=True))

# retrieve data from the system
# URL http://localhost:8888/workqueue/elementsinfo
data, _, _, _ = makeRequest(DATA_SOURCE_URL,
                            verb="GET",
                            accept="text/json+das",
                            contentType="application/json")
data = json.loads(data)

systemSeries = series[:]
states = {}
for s in STATES:
    states[s] = 0  # status labels tuple
for elements in data["results"]:
    states[elements["status"]] = states[elements["status"]] + 1
for s in systemSeries:
    s["value"] = states[s["label"]]

plotDefinition["title"] = "Element status - WorkQueue"
plotDefinition["series"] = systemSeries
systemData = urllib.quote(json.dumps(plotDefinition, ensure_ascii=True))