Skip to content

Commit 50ca7dc

Browse files
Reeya123HadleyKing
authored andcommitted
new branch- objects_drafts_publish
1 parent 7072b8d commit 50ca7dc

File tree

2 files changed

+72
-85
lines changed

2 files changed

+72
-85
lines changed

tests/fixtures/test_data.json

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -994,91 +994,8 @@
994994
"codename": "view_authentication"
995995
}
996996
},
997-
{
998-
"model": "auth.group",
999-
"pk": 1,
1000-
"fields": {
1001-
"name": "bco_drafter",
1002-
"permissions": [
1003-
53,
1004-
54,
1005-
55,
1006-
57,
1007-
56
1008-
]
1009-
}
1010-
},
1011-
{
1012-
"model": "auth.group",
1013-
"pk": 2,
1014-
"fields": {
1015-
"name": "bco_publisher",
1016-
"permissions": [
1017-
53,
1018-
54,
1019-
55,
1020-
57,
1021-
58,
1022-
56
1023-
]
1024-
}
1025-
},
1026-
{
1027-
"model": "auth.group",
1028-
"pk": 3,
1029-
"fields": {
1030-
"name": "anon",
1031-
"permissions": [
1032-
1033-
]
1034-
}
1035-
},
1036-
{
1037-
"model": "auth.group",
1038-
"pk": 4,
1039-
"fields": {
1040-
"name": "wheel",
1041-
"permissions": [
1042-
1043-
]
1044-
}
1045-
},
1046-
{
1047-
"model": "auth.group",
1048-
"pk": 5,
1049-
"fields": {
1050-
"name": "group_admins",
1051-
"permissions": [
1052-
9,
1053-
10,
1054-
11,
1055-
12
1056-
]
1057-
}
1058-
},
1059-
{
1060-
"model": "auth.group",
1061-
"pk": 6,
1062-
"fields": {
1063-
"name": "prefix_admins",
1064-
"permissions": [
1065-
49,
1066-
50,
1067-
51,
1068-
52
1069-
]
1070-
}
1071-
},
1072-
{
1073-
"model": "auth.group",
1074-
"pk": 7,
1075-
"fields": {
1076-
"name": "AnonymousUser",
1077-
"permissions": [
1078-
1079-
]
1080-
}
1081-
},
997+
998+
1082999
{
10831000
"model": "auth.group",
10841001
"pk": 8,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from django.test import TestCase
2+
from rest_framework.test import APIClient
3+
from rest_framework.authtoken.models import Token
4+
from django.contrib.auth.models import User
5+
from rest_framework.test import APITestCase
6+
7+
8+
class PublishDraftBCOTestCase(TestCase):
9+
fixtures = ['tests/fixtures/test_data']
10+
def setUp(self):
11+
self.client = APIClient()
12+
13+
def test_publish_bco_success(self):
14+
# Successful request to publish a draft BCO
15+
data = {
16+
"POST_api_objects_drafts_publish": [
17+
{
18+
"prefix": "string",
19+
"draft_id": "string",
20+
"object_id": "string",
21+
"delete_draft": True
22+
}
23+
]
24+
}
25+
#self.client.force_authenticate(user=self.user)
26+
response = self.client.post('/api/objects/drafts/publish/', data=data, format='json')
27+
self.assertEqual(response.status_code, 200)
28+
29+
def test_publish_bco_partial_failure(self):
30+
# Some requests failed while publishing the draft BCO
31+
data = {
32+
"POST_api_objects_drafts_publish": [
33+
{
34+
"prefix": "string",
35+
"draft_id": "string",
36+
"object_id": "strin",
37+
"delete_draft": True
38+
},
39+
# Add more objects if needed to simulate partial failures
40+
]
41+
}
42+
43+
response = self.client.post('/api/objects/drafts/publish/', data=data, format='json')
44+
self.assertEqual(response.status_code, 300)
45+
46+
def test_publish_bco_bad_request(self):
47+
# Bad request: Invalid or missing data
48+
data = {
49+
# Missing required fields or invalid data
50+
}
51+
#self.client.force_authenticate(user=self.user)
52+
response = self.client.post('/api/objects/drafts/publish/', data=data, format='json')
53+
self.assertEqual(response.status_code, 400)
54+
55+
def test_publish_bco_invalid_token(self):
56+
# Request with invalid token or without authentication credentials
57+
data = {
58+
"POST_api_objects_drafts_publish": [
59+
{
60+
"prefix": "string",
61+
"draft_id": "string",
62+
"object_id": "string",
63+
"delete_draft": True
64+
}
65+
]
66+
}
67+
#using invalid token
68+
self.client.credentials(HTTP_AUTHORIZATION='invalid token')
69+
response = self.client.post('/api/objects/drafts/publish/', data=data, format='json')
70+
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)