コード例 #1
0
ファイル: internet_tests.py プロジェクト: SG345/ka-lite
    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")
コード例 #2
0
ファイル: regression_tests.py プロジェクト: Aypak/ka-lite
 def test_not_redirected_when_offline(self):
     self.assertFalse(Device.get_own_device().is_registered(), "The device should be unregistered!")
     self.assertFalse(am_i_online(url=settings.CENTRAL_SERVER_URL), "Central server should be unreachable!")
     updated_videos_url = self.reverse("update_videos")
     response = self.client.get(updated_videos_url, follow=True)
     redirect_chain = response.redirect_chain  # Will be the empty list if there are no redirects
     self.assertFalse(redirect_chain, "Should not be redirected when the central server is not reachable! "
                                      "Redirect chain: {0}".format(redirect_chain))
コード例 #3
0
    def test_online(self):
        try:
            response = requests.get("http://google.com", )
            google_is_online = response.status_code in (200, 301)
        except ConnectionError:
            logger.warning("Running test_online while offline")
            google_is_online = False

        self.assertEqual(am_i_online(), google_is_online)
コード例 #4
0
 def test_online(self):
     try:
         response = requests.get("http://google.com",)
         google_is_online = response.status_code in (200, 301)
     except ConnectionError:
         logger.warning("Running test_online while offline")
         google_is_online = False
     
     self.assertEqual(am_i_online(), google_is_online)
コード例 #5
0
 def real_decorator_wrapper_fn(request, *args, **kwargs):
     if Device.get_own_device().is_registered() or not am_i_online():
         return handler(request, *args, **kwargs)
     else:
         messages.warning(
             request,
             _("In order to access %(resource_name)s, you must register your device first."
               % {"resource_name": unicode(resource_name)}))
         return HttpResponseRedirect(
             set_query_params(reverse('register_public_key'),
                              {'next': request.path}))
コード例 #6
0
 def test_not_redirected_when_offline(self):
     self.assertFalse(Device.get_own_device().is_registered(),
                      "The device should be unregistered!")
     self.assertFalse(am_i_online(url=settings.CENTRAL_SERVER_URL),
                      "Central server should be unreachable!")
     updated_videos_url = self.reverse("update_videos")
     response = self.client.get(updated_videos_url, follow=True)
     redirect_chain = response.redirect_chain  # Will be the empty list if there are no redirects
     self.assertFalse(
         redirect_chain,
         "Should not be redirected when the central server is not reachable! "
         "Redirect chain: {0}".format(redirect_chain))
コード例 #7
0
 def real_decorator_wrapper_fn(request, *args, **kwargs):
     if Device.get_own_device().is_registered() or not am_i_online():
         return handler(request, *args, **kwargs)
     else:
         messages.warning(
             request,
             _("In order to access %(resource_name)s, you must register your device first."
               % {"resource_name": unicode(resource_name)})
         )
         return HttpResponseRedirect(
             set_query_params(reverse('register_public_key'), {'next': request.path})
         )
コード例 #8
0
 def test_not_redirected_when_offline(self):
     self.assertFalse(Device.get_own_device().is_registered(), "The device should be unregistered!")
     
     register_device_url = self.reverse("register_public_key")
     response = self.client.get(register_device_url, follow=False)
     self.assertEqual(response.status_code, 200)
     
     self.assertFalse(am_i_online(), "Central server should be unreachable!")
     updated_videos_url = self.reverse("update_videos")
     response = self.client.get(updated_videos_url, follow=True)
     redirect_chain = response.redirect_chain  # Will be the empty list if there are no redirects
     self.assertFalse(redirect_chain, "Should not be redirected when the central server is not reachable! "
                                      "Redirect chain: {0}".format(redirect_chain))
コード例 #9
0
    def test_not_redirected_when_offline(self):
        self.assertFalse(Device.get_own_device().is_registered(),
                         "The device should be unregistered!")

        register_device_url = self.reverse("register_public_key")
        response = self.client.get(register_device_url, follow=False)
        self.assertEqual(response.status_code, 200)

        self.assertFalse(am_i_online(),
                         "Central server should be unreachable!")
        updated_videos_url = self.reverse("update_videos")
        response = self.client.get(updated_videos_url, follow=True)
        redirect_chain = response.redirect_chain  # Will be the empty list if there are no redirects
        self.assertFalse(
            redirect_chain,
            "Should not be redirected when the central server is not reachable! "
            "Redirect chain: {0}".format(redirect_chain))
コード例 #10
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()

        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)
コード例 #11
0
ファイル: api_views.py プロジェクト: Aypak/ka-lite
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)