88# This is copied from https://github.com/nexB/scancode.io/commit/eab8eeb13989c26a1600cc64e8b054f171341063
99#
1010
11+
1112from django .conf import settings
1213from django .contrib .auth import get_user_model
1314from django .contrib .auth .models import AnonymousUser
1415from django .test import TestCase
15- from django .test import override_settings
1616from django .urls import reverse
1717
18- from vulnerablecode .auth import is_authenticated_when_required
19-
2018TEST_PASSWORD = "secret"
2119
2220User = get_user_model ()
@@ -33,17 +31,6 @@ def setUp(self):
3331 self .anonymous_user = AnonymousUser ()
3432 self .basic_user = User .objects .create_user (username = "basic_user" , password = TEST_PASSWORD )
3533
36- def test_vulnerablecode_auth_is_authenticated_when_required (self ):
37- with override_settings (VULNERABLECODEIO_REQUIRE_AUTHENTICATION = True ):
38- self .assertFalse (self .anonymous_user .is_authenticated )
39- self .assertFalse (is_authenticated_when_required (user = self .anonymous_user ))
40-
41- self .assertTrue (self .basic_user .is_authenticated )
42- self .assertTrue (is_authenticated_when_required (user = self .basic_user ))
43-
44- with override_settings (VULNERABLECODEIO_REQUIRE_AUTHENTICATION = False ):
45- self .assertTrue (is_authenticated_when_required (user = None ))
46-
4734 def test_vulnerablecode_auth_login_view (self ):
4835 data = {"username" : self .basic_user .username , "password" : "" }
4936 response = self .client .post (login_url , data )
@@ -81,12 +68,10 @@ def test_vulnerablecode_account_profile_view(self):
8168 response = self .client .get (profile_url )
8269 expected = '<label class="label">API Key</label>'
8370 self .assertContains (response , expected , html = True )
84- expected = '<label class="label">API Key</label>'
8571 self .assertContains (response , self .basic_user .auth_token .key )
8672
8773 def test_vulnerablecode_auth_api_required_authentication (self ):
88- with override_settings (VULNERABLECODEIO_REQUIRE_AUTHENTICATION = True ):
89- response = self .client .get (api_package_url )
90- expected = {"detail" : "Authentication credentials were not provided." }
91- self .assertEqual (expected , response .json ())
92- self .assertEqual (401 , response .status_code )
74+ response = self .client .get (api_package_url )
75+ expected = {"detail" : "Authentication credentials were not provided." }
76+ self .assertEqual (expected , response .json ())
77+ self .assertEqual (401 , response .status_code )
0 commit comments