def test_from_nested_json_list(self):
     json_text = '{"member1": "value1", "member2": [{"member1": 345, "member2": "value2"}]}'
     actual = from_json(json_text)
     self.assertEquals("value1", actual.member1)
     self.assertEquals(1, len(actual.member2))
     self.assertEquals(345, actual.member2[0].member1)
     self.assertEquals("value2", actual.member2[0].member2)
Beispiel #2
0
    def send_log(self, user_update_token, logs):

        url = urljoin(self.user_platform_config.get_redirect_api_url(), "/user/log")
        response = requests.post(url, {'token': user_update_token, 'data': logs})
        util.check_http_error(response)
        user = convertible.from_json(response.text)

        return user
    def send_log(self, user_update_token, logs):

        url = urljoin(self.user_platform_config.get_redirect_api_url(), "/user/log")
        response = requests.post(url, {'token': user_update_token, 'data': logs})
        util.check_http_error(response)
        user = convertible.from_json(response.text)

        return user
 def test_from_list_json(self):
     json_text = '[{"member1": "value1", "member2": 123}, {"member1": "value2", "member2": 345}]'
     actual = from_json(json_text)
     self.assertEquals(2, len(actual))
     self.assertEquals("value1", actual[0].member1)
     self.assertEquals(123, actual[0].member2)
     self.assertEquals("value2", actual[1].member1)
     self.assertEquals(345, actual[1].member2)
Beispiel #5
0
 def get_user(self, email, password):
     url = urljoin(self.user_platform_config.get_redirect_api_url(),
                   "/user/get")
     response = requests.get(url,
                             params={
                                 'email': email,
                                 'password': password
                             })
     util.check_http_error(response)
     user = convertible.from_json(response.text).data
     return user
Beispiel #6
0
def wait_for_sam(public_web_session):
    sam_running = True
    while sam_running:
        try:
            response = public_web_session.get(
                'http://localhost/rest/settings/sam_status')
            if response.status_code == 200:
                json = convertible.from_json(response.text)
                sam_running = json.is_running
        except Exception, e:
            print(e.message)
        time.sleep(1)
Beispiel #7
0
def test_public_web_platform_upgrade(public_web_session):

    public_web_session.get('http://localhost/rest/settings/system_upgrade')
    sam_running = True
    while sam_running:
        try:
            response = public_web_session.get('http://localhost/rest/settings/sam_status')
            if response.status_code == 200:
                json = convertible.from_json(response.text)
                sam_running = json.is_running
        except Exception, e:
            pass
        time.sleep(1)
def test_pre_protocol_support():

    old_json = '[{"external_port": 81, "local_port": 80}]'

    port_config = get_port_config(convertible.from_json(old_json))

    assert port_config.get(80, 'TCP').external_port == 81
    port_config.add_or_update(Port(80, 10000, 'UDP'))
    assert port_config.get(80, 'UDP').external_port == 10000

    print(open(port_config.filename, 'r').read())

    assert len(port_config.load()) == 2
Beispiel #9
0
def test_public_web_platform_upgrade(public_web_session):

    public_web_session.get('http://localhost/rest/settings/system_upgrade')
    sam_running = True
    while sam_running:
        try:
            response = public_web_session.get(
                'http://localhost/rest/settings/sam_status')
            if response.status_code == 200:
                json = convertible.from_json(response.text)
                sam_running = json.is_running
        except Exception, e:
            pass
        time.sleep(1)
Beispiel #10
0
 def acquire(self, email, password, user_domain):
     device_id = id.id()
     data = {
         'email': email,
         'password': password,
         'user_domain': user_domain,
         'device_mac_address': device_id.mac_address,
         'device_name': device_id.name,
         'device_title': device_id.title,
     }
     url = urljoin(self.user_platform_config.get_redirect_api_url(), "/domain/acquire")
     response = requests.post(url, data)
     util.check_http_error(response)
     response_data = convertible.from_json(response.text)
     return response_data
 def acquire(self, email, password, user_domain):
     device_id = id.id()
     data = {
         'email': email,
         'password': password,
         'user_domain': user_domain,
         'device_mac_address': device_id.mac_address,
         'device_name': device_id.name,
         'device_title': device_id.title,
     }
     url = urljoin(self.user_platform_config.get_redirect_api_url(), "/domain/acquire")
     response = requests.post(url, data)
     util.check_http_error(response)
     response_data = convertible.from_json(response.text)
     return response_data
Beispiel #12
0
 def get_user(self, email, password):
     url = urljoin(self.user_platform_config.get_redirect_api_url(), "/user/get")
     response = requests.get(url, params={'email': email, 'password': password})
     util.check_http_error(response)
     user = convertible.from_json(response.text).data
     return user
Beispiel #13
0
def check_http_error(response):
    log = logger.get_logger('util')
    if not response.status_code == 200:
        log.error(response.text)
        error = convertible.from_json(response.text)
        raise PassthroughJsonError(error.message, response.text)
Beispiel #14
0
 def test_from_nested_json(self):
     json_text = '{"member1": "value1", "member2": {"member1": 345, "member2": "value2"}}'
     actual = from_json(json_text)
     self.assertEquals("value1", actual.member1)
     self.assertEquals(345, actual.member2.member1)
     self.assertEquals("value2", actual.member2.member2)
Beispiel #15
0
 def test_from_object_json(self):
     json_text = '{"member1": "value", "member2": 345}'
     actual = from_json(json_text)
     self.assertEquals("value", actual.member1)
     self.assertEquals(345, actual.member2)
Beispiel #16
0
 def check_http_error(self, response):
     if not response.status_code == 200:
         self.logger.error(response.text)
         error = convertible.from_json(response.text)
         raise Exception(error.message)