def test_am_online(self): """The only thing I'm guaranteed to have online? Myself.""" # self.assertTrue(am_i_online(self.live_server_url), "Basic GET on myself") self.assertFalse(am_i_online("http://this.server.should.never.exist.or.else.we.are.screwed/"), "Basic failure to GET") # expected_val self.assertFalse(am_i_online(self.live_server_url, expected_val="foo"), "Test expected_val string fails") # search_string self.assertTrue(am_i_online(self.live_server_url, search_string="KA Lite"), "Test search_string should succeed") self.assertFalse(am_i_online(self.live_server_url, search_string="foofoofoo"), "Test search_string fails")
def easy_admin(request): context = { "wiki_url" : settings.CENTRAL_WIKI_URL, "central_server_host" : settings.CENTRAL_SERVER_HOST, "am_i_online": am_i_online(settings.CENTRAL_WIKI_URL, allow_redirects=False), "in_a_zone": Device.get_own_device().get_zone() is not None, } return context
def easy_admin(request): context = { "wiki_url": settings.CENTRAL_WIKI_URL, "central_server_host": settings.CENTRAL_SERVER_HOST, "am_i_online": am_i_online(settings.CENTRAL_WIKI_URL, allow_redirects=False), "in_a_zone": Device.get_own_device().get_zone() is not None, } return context
def test_am_online(self): """The only thing I'm guaranteed to have online? Myself.""" # self.assertTrue(am_i_online(self.live_server_url), "Basic GET on myself") self.assertFalse( am_i_online( "http://this.server.should.never.exist.or.else.we.are.screwed/" ), "Basic failure to GET") # expected_val self.assertFalse(am_i_online(self.live_server_url, expected_val="foo"), "Test expected_val string fails") # search_string self.assertTrue( am_i_online(self.live_server_url, search_string="KA Lite"), "Test search_string should succeed") self.assertFalse( am_i_online(self.live_server_url, search_string="foofoofoo"), "Test search_string fails")
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)
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_info[field] = version.VERSION elif field == "video_count": from main.models import VideoFile device_info[field] = VideoFile.objects.filter(percent_complete=100).count() if not settings.CENTRAL_SERVER else 0 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)