Exemplo n.º 1
0
 def test_stat__updates_on_successful_poll(self, mock_fetch):
     poll_node('example.com')
     assert Stat.objects.filter(node__host='example.com').exists()
     response = FETCH_NODE_RESPONSE
     response['activity']['users']['total'] = 10
     mock_fetch.return_value = response
     poll_node('example.com')
     stat = Stat.objects.get(node__host='example.com')
     self.assertEqual(stat.date, now().date())
     self.assertEqual(stat.users_total, 10)
Exemplo n.º 2
0
 def test_stat__updates_on_successful_poll(self, mock_fetch):
     poll_node('example.com')
     assert Stat.objects.filter(node__host='example.com').exists()
     response = FETCH_NODE_RESPONSE
     response['activity']['users']['total'] = 10
     mock_fetch.return_value = response
     poll_node('example.com')
     stat = Stat.objects.get(node__host='example.com')
     self.assertEqual(stat.date, now().date())
     self.assertEqual(stat.users_total, 10)
Exemplo n.º 3
0
 def test_stat__creates_on_successful_poll__no_stats_exposed(self, mock_fetch):
     poll_node('example.com')
     stat = Stat.objects.get(node__host='example.com')
     self.assertEqual(stat.date, now().date())
     self.assertIsNone(stat.platform)
     self.assertIsNone(stat.protocol)
     self.assertIsNone(stat.users_total)
     self.assertIsNone(stat.users_half_year)
     self.assertIsNone(stat.users_monthly)
     self.assertIsNone(stat.users_weekly)
     self.assertIsNone(stat.local_posts)
     self.assertIsNone(stat.local_comments)
Exemplo n.º 4
0
 def test_stat__creates_on_successful_poll(self, mock_fetch):
     poll_node('example.com')
     stat = Stat.objects.get(node__host='example.com')
     self.assertEqual(stat.date, now().date())
     self.assertIsNone(stat.platform)
     self.assertIsNone(stat.protocol)
     self.assertEqual(stat.users_total, 4)
     self.assertEqual(stat.users_half_year, 3)
     self.assertEqual(stat.users_monthly, 2)
     self.assertEqual(stat.users_weekly, 1)
     self.assertEqual(stat.local_posts, 5)
     self.assertEqual(stat.local_comments, 6)
Exemplo n.º 5
0
def register_view(request, host):
    # TODO rate limit this view per caller ip?
    if not is_valid_hostname:
        return redirect("/")
    if poll_node(host):
        # Success!
        return redirect(f"/node/{host}")
    # TODO show an error or something
    return redirect("/")
Exemplo n.º 6
0
def register_view(request, host):
    # TODO rate limit this view per caller ip?
    if not is_valid_hostname:
        return redirect("/")
    if poll_node(host):
        # Success!
        return redirect(f"/nodes/{host}")
    # TODO show an error or something
    return redirect("/")
Exemplo n.º 7
0
def register_view(request, host):
    json = True if request.content_type == "application/json" else False
    # TODO rate limit this view per caller ip?
    if is_valid_hostname and poll_node(host):
        if json:
            return JsonResponse({'error': None})
        return redirect(f"/node/{host}")
    if json:
        return JsonResponse({'error': 'Invalid hostname or broken nodeinfo!'})
    # TODO show an error or something
    return redirect("/")
Exemplo n.º 8
0
def register_view(request, host):
    json = True if request.content_type == "application/json" else False
    # TODO rate limit this view per caller ip?
    if is_valid_hostname and poll_node(host):
        if json:
            return JsonResponse({'error': None})
        return redirect(f"/node/{host}")
    if json:
        return JsonResponse({'error': 'Invalid hostname or broken nodeinfo!'})
    # TODO show an error or something
    return redirect("/")