Skip to content

Commit

Permalink
Merge pull request #500 from bounswe/WorkspaceUpdate
Browse files Browse the repository at this point in the history
Workspace GET API Update
  • Loading branch information
hakanaktas0 authored Nov 26, 2023
2 parents 7156442 + c51f4ff commit df32a06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions project/backend/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ 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_id(self):
url = reverse('get_random_node_id')
response = self.client.get(url , {'count':2})
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertIn('node_ids', data)
self.assertEqual(len(data['node_ids']), 2)

class TheoremGETAPITestCase(TestCase):
def setUp(self):
# Create a sample Theorem instance for testing
Expand Down Expand Up @@ -571,6 +579,7 @@ def test_get_workspace_from_id(self):
self.assertEqual(response.json()['workspace_title'], self.workspace.workspace_title)
self.assertEqual(response.json()['status'], 'workable')
self.assertEqual(response.json()['references'], [])
self.assertEqual(response.json()['semantic_tags'], [])
self.assertEqual(response.json()['pending_contributors'], [])
self.assertEqual(response.json()['num_approvals'], 0)
# self.assertEqual(response.json()['created_at'], self.workspace.created_at)
Expand Down
8 changes: 5 additions & 3 deletions project/backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def get_workspace_from_id(request):
'workspace_entries': entries,
'status':status,
'num_approvals':workspace.num_approvals,
'semantic_tags':semantic_tags,
'contributors':contributors,
'pending_contributors':pending,
'references':references,
Expand Down Expand Up @@ -592,11 +593,12 @@ def create_workspace(request):
@csrf_exempt
def get_random_node_id(request):
count = int(request.GET.get("count"))
node_ids = Node.node_id.all()
node_ids = [node['node_id'] for node in Node.objects.values('node_id')]
node_list = []
if count > len(node_ids):
return JsonResponse({'message': 'There are less nodes than requested number.'}, status=200)
for i in range(count):
while node_ids[index] not in node_list:
index = random.randint(0,len(node_ids))
index = random.randint(0,len(node_ids)-1)
node_list.append(node_ids[index])
return JsonResponse({'node_ids': node_list}, status=200)

Expand Down

0 comments on commit df32a06

Please sign in to comment.