Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace GET API Update #500

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions project/backend/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,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 @@ -486,6 +494,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 @@ -346,6 +346,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 @@ -430,11 +431,12 @@ def create_workspace(request):

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