Skip to content

Commit

Permalink
Merge pull request #499 from bounswe/node-update
Browse files Browse the repository at this point in the history
Implement return of random node
  • Loading branch information
Simurgan authored Nov 26, 2023
2 parents dce8906 + 5701edb commit b72d2d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions project/backend/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,25 @@ def test_get_removed_node(self):
response = self.client.get(self.node_url, data=data, format="json")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_get_random_node(self):
response = self.client.get(self.node_url)

self.assertEqual(response.status_code, 200)

self.assertContains(response, 'node_id')
self.assertContains(response, 'node_title')
self.assertContains(response, 'publish_date')
self.assertContains(response, 'is_valid')
self.assertContains(response, 'num_visits')
self.assertContains(response, 'theorem')
self.assertContains(response, 'contributors')
self.assertContains(response, 'reviewers')
self.assertContains(response, 'from_referenced_nodes')
self.assertContains(response, 'to_referenced_nodes')
self.assertContains(response, 'proofs')
self.assertContains(response, 'question_set')
self.assertContains(response, 'semantic_tags')
self.assertContains(response, 'annotations')
def test_get_random_node_id(self):
url = reverse('get_random_node_id')
response = self.client.get(url , {'count':2})
Expand Down
6 changes: 5 additions & 1 deletion project/backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def get_object(self):
class NodeAPIView(APIView):

def get(self, request):
id = int(request.GET.get("node_id"))
id = request.GET.get("node_id")
if not id:
node_list = Node.objects.all()
return Response(NodeSerializer(node_list[random.randint(0, len(node_list)-1)]).data)
id = int(id)
node = Node.objects.filter(node_id=id)
if node.count() == 0:
return JsonResponse(
Expand Down

0 comments on commit b72d2d3

Please sign in to comment.