1+ #!/usr/bin/env python3
2+
3+ '''Publish BCO Draft
4+ expecting a response status code of 200,300, 400, but receiving a 207 status code (Multi-status rsponse), which might indicate that
5+ suggesting that there are multiple operations being performed in the background as a result of the request.
6+
7+ Tests for 403(Invalid token)
8+ '''
9+
110from django .test import TestCase
211from rest_framework .test import APIClient
312from rest_framework .authtoken .models import Token
817class PublishDraftBCOTestCase (TestCase ):
918 fixtures = ['tests/fixtures/test_data' ]
1019 def setUp (self ):
20+ fixtures = ['tests/fixtures/test_data' ]
1121 self .client = APIClient ()
22+ # Checking if the user 'bco_api_user' already exists
23+ try :
24+ self .user = User .objects .get (username = 'bco_api_user' )
25+ except User .DoesNotExist :
26+ self .user = User .objects .create_user (username = 'bco_api_user' )
27+
28+ # Checking if user already has token, if not then creating one
29+ if not Token .objects .filter (user = self .user ).exists ():
30+ self .token = Token .objects .create (user = self .user )
31+ else :
32+ self .token = Token .objects .get (user = self .user )
1233
1334 def test_publish_bco_success (self ):
14- # Successful request to publish a draft BCO
35+ # Test for Successful request to publish a draft BCO
36+ #Returns 207 instead of 200
37+
1538 data = {
1639 "POST_api_objects_drafts_publish" : [
1740 {
18- "prefix" : "string" ,
19- "draft_id" : "string" ,
20- "object_id" : "string" ,
21- "delete_draft" : True
41+ "prefix" : "BCO" ,
42+ "draft_id" : "http://127.0.0.1:8000/BCO_000000/DRAFT" ,
43+
44+ "delete_draft" : False
45+
2246 }
2347 ]
2448 }
25- # self.client.force_authenticate(user= self.user)
49+ self .client .credentials ( HTTP_AUTHORIZATION = 'Token ' + self .token . key )
2650 response = self .client .post ('/api/objects/drafts/publish/' , data = data , format = 'json' )
2751 self .assertEqual (response .status_code , 200 )
2852
2953 def test_publish_bco_partial_failure (self ):
3054 # Some requests failed while publishing the draft BCO
55+ #Returns 207 instead of 300
56+
3157 data = {
3258 "POST_api_objects_drafts_publish" : [
3359 {
34- "prefix" : "string " ,
35- "draft_id" : "string " ,
36- "object_id" : "strin" ,
37- "delete_draft" : True
60+ "prefix" : "BCO " ,
61+ "draft_id" : "http://127.0.0.1:8000/BCO_000001/DRAFT " ,
62+
63+ "delete_draft" : False
3864 },
39- # Add more objects if needed to simulate partial failures
65+ {
66+ "prefix" : "InvalidPrefix" ,
67+ "draft_id" : "InvalidDraftId" ,
68+
69+ "delete_draft" : False
70+ }
71+
4072 ]
4173 }
42-
74+ self . client . credentials ( HTTP_AUTHORIZATION = 'Token ' + self . token . key )
4375 response = self .client .post ('/api/objects/drafts/publish/' , data = data , format = 'json' )
4476 self .assertEqual (response .status_code , 300 )
4577
4678 def test_publish_bco_bad_request (self ):
4779 # Bad request: Invalid or missing data
80+ #Returns 207 instead of 400
81+
4882 data = {
49- # Missing required fields or invalid data
83+ "POST_api_objects_drafts_publish" : [
84+ {
85+ "prefix" : "BCO" ,
86+ "draft_id" : "InvalidID" ,
87+ "delete_draft" : False
88+ },
89+
90+ ]
5091 }
51- # self.client.force_authenticate(user= self.user)
92+ self .client .credentials ( HTTP_AUTHORIZATION = 'Token ' + self .token . key )
5293 response = self .client .post ('/api/objects/drafts/publish/' , data = data , format = 'json' )
5394 self .assertEqual (response .status_code , 400 )
5495
@@ -57,10 +98,11 @@ def test_publish_bco_invalid_token(self):
5798 data = {
5899 "POST_api_objects_drafts_publish" : [
59100 {
60- "prefix" : "string" ,
61- "draft_id" : "string" ,
62- "object_id" : "string" ,
63- "delete_draft" : True
101+ "prefix" : "BCO" ,
102+ "draft_id" : "http://127.0.0.1:8000/BCO_000000/DRAFT" ,
103+
104+ "delete_draft" : False
105+
64106 }
65107 ]
66108 }
0 commit comments