diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 8e4c83e9..14787cc7 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -26,4 +26,4 @@ jobs: pip install -r requirements.txt - name: Run Tests run: | - cd bco_api;python3.9 manage.py test + python3.9 manage.py test diff --git a/tests/test_views/test_api_objects_drafts_create.py b/tests/test_views/test_api_objects_drafts_create.py index 249f1f87..a9537fd7 100644 --- a/tests/test_views/test_api_objects_drafts_create.py +++ b/tests/test_views/test_api_objects_drafts_create.py @@ -1,31 +1,46 @@ -from django.test import TestCase, Client -from django.contrib.auth.models import User + + import json +from django.test import TestCase +from django.contrib.auth.models import User +from rest_framework.authtoken.models import Token +from rest_framework.test import APIClient class BcoDraftCreateTestCase(TestCase): - def setUp(self): - self.client = Client() - self.url = '/api/objects/drafts/create' # The URL for the create draft endpoint - self.user = User.objects.create_user(username='bco_api_user', password='biocompute') + fixtures = ['tests/fixtures/test_data'] + + # def setUp(self): + # self.client = Client() + # self.url = '/api/objects/drafts/create' # The URL for the create draft endpoint + # self.user = User.objects.create_user(username='bco_api_user', password='biocompute') def test_successful_creation(self): - # force logging - self.client.force_login(self.user) + """200: Creation of BCO draft is successful. + """ + + client = APIClient() + token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key + client.credentials(HTTP_AUTHORIZATION='Token ' + token) - # Test case for successful creation (response code 200) data = { - 'prefix': 'string', - 'owner_group': 'string', - 'object_id': 'string', - 'schema': 'string', - 'contents': { - "additionalProp1": {} - } + 'POST_api_objects_draft_create': [ + { + 'prefix': 'BCO', + 'owner_group': 'bco_drafter', + 'schema': 'IEEE', + 'contents': {} + }, + { + 'prefix': 'Hadley', + 'owner_group': 'bco_drafter', + 'schema': 'IEEE', + 'contents': {} + } + ] } - response = self.client.post(self.url, data=json.dumps(data), content_type='application/json', follow=True) + response = client.post('/api/objects/drafts/create/',data, format='json') + import pdb; pdb.set_trace() self.assertEqual(response.status_code, 200) - # Checking the response. I believe it's JSON) - response_data = json.loads(response.content) def test_partial_failure(self): # Test case for partial failure (response code 300)