Example #1
0
    def test_am_online(self):
        """The only thing I'm guaranteed to have online?  Myself."""

        #
        self.assertTrue(am_i_online(self.live_server_url, timeout=10),
                        "Basic GET on myself")
        self.assertFalse(
            am_i_online(
                "http://this.server.should.never.exist.or.else.we.are.screwed/",
                timeout=10), "Basic failure to GET")

        # expected_val
        self.assertFalse(
            am_i_online(self.live_server_url, expected_val="foo", timeout=10),
            "Test expected_val string fails")

        # search_string
        self.assertTrue(
            am_i_online(self.live_server_url,
                        search_string="KA Lite",
                        timeout=10), "Test search_string should succeed")
        self.assertFalse(
            am_i_online(self.live_server_url,
                        search_string="foofoofoo",
                        timeout=10), "Test search_string fails")
Example #2
0
    def test_am_online(self):
        """The only thing I'm guaranteed to have online?  Myself."""

        #
        self.assertTrue(am_i_online(self.live_server_url, timeout=10), "Basic GET on myself")
        self.assertFalse(am_i_online("http://this.server.should.never.exist.or.else.we.are.screwed/", timeout=10), "Basic failure to GET")

        # expected_val
        self.assertFalse(am_i_online(self.live_server_url, expected_val="foo", timeout=10), "Test expected_val string fails")

        # search_string
        self.assertTrue(am_i_online(self.live_server_url, search_string="KA Lite", timeout=10), "Test search_string should succeed")
        self.assertFalse(am_i_online(self.live_server_url, search_string="foofoofoo", timeout=10), "Test search_string fails")
Example #3
0
def get_server_info(request):
    """This function is used to check connection to central or local server and also to get specific data from server.

    Args:
        The http request.

    Returns:
        A json object containing general data from the server.

    """
    device = None
    zone = None

    device_info = {"status": "OK", "invalid_fields": []}

    for field in request.GET.get("fields", "").split(","):

        if field == "version":
            device = device or Device.get_own_device()
            device_info[field] = device.get_version()

        elif field == "device_name":
            device = device or Device.get_own_device()
            device_info[field] = device.name

        elif field == "device_description":
            device = device or Device.get_own_device()
            device_info[field] = device.description

        elif field == "device_description":
            device = device or Device.get_own_device()
            device_info[field] = device.description

        elif field == "device_id":
            device = device or Device.get_own_device()
            device_info[field] = device.id

        elif field == "zone_name":
            if settings.CENTRAL_SERVER:
                continue
            device = device or Device.get_own_device()
            zone = zone or device.get_zone()
            device_info[field] = zone.name if zone else None

        elif field == "zone_id":
            if settings.CENTRAL_SERVER:
                continue
            device = device or Device.get_own_device()
            zone = zone or device.get_zone()
            device_info[field] = zone.id if zone else None

        elif field == "online":
            if settings.CENTRAL_SERVER:
                device_info[field] =  True
            else:
                device_info[field] = am_i_online(url="%s://%s%s" % (settings.SECURESYNC_PROTOCOL, settings.CENTRAL_SERVER_HOST, reverse("get_server_info")))

        elif field:
            # the field isn't one we know about, so add it to the list of invalid fields
            device_info["invalid_fields"].append(field)

    return JsonResponse(device_info)