33# SPDX-License-Identifier: AGPL-3.0-or-later
44
55import logging
6+ from http import HTTPStatus
67
78from django .test import TestCase
89from django .urls import reverse
@@ -193,6 +194,51 @@ def test_allocationchangeview_post_no_change(self):
193194 self .assertEqual (len (AllocationChangeRequest .objects .all ()), 0 )
194195
195196
197+ class AllocationAttributeEditViewTest (AllocationViewBaseTest ):
198+ """Tests for AllocationAttributeEditView"""
199+
200+ def setUp (self ):
201+ self .client .force_login (self .admin_user , backend = BACKEND )
202+ self .url = f"/allocation/{ self .allocation .pk } /allocationattribute/edit"
203+ self .post_data = {
204+ "attributeform-0-value" : self .allocation .get_attribute ("Storage Quota (TB)" ),
205+ "attributeform-INITIAL_FORMS" : "1" ,
206+ "attributeform-MAX_NUM_FORMS" : "1" ,
207+ "attributeform-MIN_NUM_FORMS" : "0" ,
208+ "attributeform-TOTAL_FORMS" : "1" ,
209+ }
210+
211+ def test_allocationattributeeditview_access (self ):
212+ """Test get request"""
213+ self .allocation_access_tstbase (self .url )
214+ utils .test_user_cannot_access (self , self .pi_user , self .url )
215+ utils .test_user_cannot_access (self , self .allocation_user , self .url )
216+
217+ def test_allocationattributeeditview_post_change_attr (self ):
218+ """Test post request to change attribute"""
219+ quota_orig = 100
220+ quota_new = 200
221+
222+ self .assertEqual (self .allocation .get_attribute ("Storage Quota (TB)" ), quota_orig )
223+
224+ self .post_data ["attributeform-0-value" ] = quota_new
225+ response = self .client .post (self .url , data = self .post_data , follow = True )
226+ self .assertEqual (response .status_code , HTTPStatus .OK )
227+
228+ self .assertEqual (self .allocation .get_attribute ("Storage Quota (TB)" ), quota_new )
229+
230+ def test_allocationattributeeditview_post_no_change (self ):
231+ """Test post request with no change"""
232+ quota_orig = 100
233+
234+ self .assertEqual (self .allocation .get_attribute ("Storage Quota (TB)" ), quota_orig )
235+
236+ response = self .client .post (self .url , data = self .post_data , follow = True )
237+ self .assertEqual (response .status_code , HTTPStatus .OK )
238+
239+ self .assertEqual (self .allocation .get_attribute ("Storage Quota (TB)" ), quota_orig )
240+
241+
196242class AllocationDetailViewTest (AllocationViewBaseTest ):
197243 """Tests for AllocationDetailView"""
198244
@@ -214,12 +260,15 @@ def test_allocationdetail_requestchange_button(self):
214260 def test_allocationattribute_button_visibility (self ):
215261 """Test visibility of "Add Attribute" button for different user types"""
216262 # admin
263+ utils .page_contains_for_user (self , self .admin_user , self .url , "Edit Allocation Attribute" )
217264 utils .page_contains_for_user (self , self .admin_user , self .url , "Add Allocation Attribute" )
218265 utils .page_contains_for_user (self , self .admin_user , self .url , "Delete Allocation Attribute" )
219266 # pi
267+ utils .page_does_not_contain_for_user (self , self .pi_user , self .url , "Edit Allocation Attribute" )
220268 utils .page_does_not_contain_for_user (self , self .pi_user , self .url , "Add Allocation Attribute" )
221269 utils .page_does_not_contain_for_user (self , self .pi_user , self .url , "Delete Allocation Attribute" )
222270 # allocation user
271+ utils .page_does_not_contain_for_user (self , self .allocation_user , self .url , "Edit Allocation Attribute" )
223272 utils .page_does_not_contain_for_user (self , self .allocation_user , self .url , "Add Allocation Attribute" )
224273 utils .page_does_not_contain_for_user (self , self .allocation_user , self .url , "Delete Allocation Attribute" )
225274
0 commit comments