1+ #!/usr/bin/env python3
2+
3+ """Get ObjectID
4+ Tests for 'Successful request with valid object id' (200),
5+ 'Request with a non-existent object ID' (404), 'unauthorized- Request without authentication credentials' (401),
6+ 'Forbidden- Request with valid object ID but unauthorized user' (403)
7+ """
8+
9+
10+ from django .test import TestCase
11+ from rest_framework .test import APIClient
12+
13+ class BCOViewTestCase (TestCase ):
14+ fixtures = ['tests/fixtures/test_data' ]
15+ def setUp (self ):
16+ self .client = APIClient ()
17+
18+ def test_view_published_bco_success (self ):
19+ # Successful request with valid object ID
20+ object_id = "TEST_000001"
21+ response = self .client .get (f'/api/{ object_id } /' )
22+ self .assertEqual (response .status_code , 200 )
23+
24+ def test_view_published_bco_not_found (self ):
25+ # Request with a non-existent object ID
26+ object_id = "invalid_object_id"
27+ response = self .client .get (f'/api/{ object_id } /' )
28+ self .assertEqual (response .status_code , 404 )
29+
30+ def test_view_published_bco_unauthorized (self ):
31+ # Request without authentication credentials
32+ response = self .client .get ('/api/TEST_000001/' )
33+ self .assertEqual (response .status_code , 401 )
34+
35+ def test_view_published_bco_forbidden (self ):
36+ # Request with valid object ID but unauthorized user
37+ # (ie-user without sufficient permissions to access the BCO)
38+ object_id = "TEST_000001"
39+ # Authenticate as a user without sufficient permissions ??
40+ # self.client.credentials(HTTP_AUTHORIZATION='Token your_invalid_token_here')
41+ response = self .client .get (f'/api/{ object_id } /' )
42+ self .assertEqual (response .status_code , 403 )
0 commit comments