Commit 0f2e66b788d8d6ff824c3a75f1ba597409a93779

Authored by Macieski
1 parent 558c4cac
Exists in master

test e alterações feitas no wscserver

wscserver/tests/__init__.py 0 → 100644
... ... @@ -0,0 +1 @@
  1 +#
... ...
wscserver/tests/test_conect.py 0 → 100644
... ... @@ -0,0 +1,89 @@
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*
  3 +import unittest
  4 +import requests
  5 +import json
  6 +#import hashlib
  7 +#from pyramid_restler.view import RESTfulView
  8 +#from collections import defaultdict
  9 +
  10 +class TestConect(unittest.TestCase):
  11 + """
  12 + Testando WSCserver
  13 + """
  14 + def setUp(self):
  15 + self.rest_url = 'http://10.1.0.121/wscserver'
  16 + pass
  17 +
  18 +
  19 + def test_carrega_classe(self):
  20 + """
  21 + Testa carregar instanciar classe do REST
  22 + """
  23 + url = self.rest_url + '/rest/coleta'
  24 + r = requests.get(url)
  25 + coleta = r.json()
  26 + coleta_str = r.text
  27 + fd = open('/tmp/coleta.json', 'w+')
  28 + fd.write(coleta_str)
  29 + fd.close()
  30 +
  31 + assert(coleta)
  32 +
  33 + def test_carrega_resultados(self):
  34 + """
  35 + Carrega resultados em uma variavel
  36 + """
  37 + url = self.rest_url + '/rest/coleta'
  38 + r = requests.get(url)
  39 + coleta = r.json()
  40 + results = coleta.get('results')
  41 +
  42 + assert(results)
  43 +
  44 +
  45 + def test_carrega_computador(self):
  46 + """
  47 + Carrega resultados para um computador
  48 + """
  49 + url = self.rest_url + '/rest/coleta'
  50 + r = requests.get(url)
  51 + coleta = r.json()
  52 + results = coleta.get('results')
  53 + computador = results[0]
  54 +
  55 + assert(computador)
  56 +
  57 +
  58 + def test_carrega_elemento(self):
  59 + """
  60 + Carrega um elemento de um computador
  61 + """
  62 + url = self.rest_url + '/rest/coleta'
  63 + r = requests.get(url)
  64 + coleta = r.json()
  65 + results = coleta.get('results')
  66 + computador = results[0]
  67 + software = computador.get('SoftwareList')
  68 +
  69 + assert(software)
  70 +
  71 + def test_url_rest(self):
  72 + """
  73 + Testa URL do rest
  74 + """
  75 + url = self.rest_url +'/rest/coleta'
  76 + get_url = requests.get(url)
  77 + assert(get_url)
  78 +
  79 + def test_url_zip(self):
  80 + """
  81 + Testa URL do zip
  82 + """
  83 + url = self.rest_url +'/zip/coleta'
  84 + get_url = requests.get(url)
  85 + assert(get_url)
  86 +
  87 + def tearDown(self):
  88 + pass
  89 +
... ...
wscserver/view/restfulview.py
... ... @@ -17,6 +17,7 @@ class CustomRESTfulView(RESTfulView):
17 17  
18 18 saida = {}
19 19 results = []
  20 +
20 21 for computador in dados_banco:
21 22 # Cria as chaves dos computadores
22 23 saida[computador['id_computador']] = {}
... ... @@ -27,8 +28,9 @@ class CustomRESTfulView(RESTfulView):
27 28  
28 29 for x in dados_banco:
29 30 # cria as chaves de propriedades nas classes
  31 + class_name = x['nm_class_name']
30 32 saida[x['id_computador']][x['nm_class_name']][
31   - x['nm_property_name']] = x['te_class_property_value']
  33 + class_name +'_'+ x['nm_property_name']] = x['te_class_property_value']
32 34  
33 35 # Ordena os objetos json
34 36 for computador in saida:
... ... @@ -49,12 +51,28 @@ class CustomRESTfulView(RESTfulView):
49 51  
50 52 results.append(classes)
51 53  
52   -
53 54 valores = {
54 55 'results': results,
55 56 'result_count': len(results)
56 57 }
57 58  
  59 + results = valores['results']
  60 + for computador in results:
  61 +
  62 + SoftwareList = computador['SoftwareList']
  63 + new_SoftwareList = [ ]
  64 +
  65 + for soft_key, soft_value in SoftwareList.items():
  66 +
  67 + new_SoftwareList_element = {
  68 + 'name': soft_key,
  69 + 'value': soft_value
  70 + }
  71 + new_SoftwareList.append(new_SoftwareList_element)
  72 +
  73 + computador['SoftwareList'] = new_SoftwareList
  74 +
  75 +
58 76 response_data = dict(
59 77 body=json.dumps(valores),
60 78 content_type='application/json'
... ...