|
1 | 1 | import logging
|
2 | 2 |
|
| 3 | +from coldfront.core.allocation.views import GENERAL_RESOURCE_NAME |
| 4 | +from coldfront.core.resource.models import Resource, ResourceType |
3 | 5 | from coldfront.core.project.models import Project
|
4 | 6 | from coldfront.core.school.models import School
|
5 | 7 | from coldfront.core.user.models import UserProfile, ApproverProfile
|
|
24 | 26 | )
|
25 | 27 | from coldfront.core.allocation.models import (
|
26 | 28 | AllocationChangeRequest,
|
27 |
| - AllocationChangeStatusChoice, Allocation, AllocationStatusChoice, AllocationAttributeChangeRequest, |
| 29 | + AllocationChangeStatusChoice, |
| 30 | + AllocationStatusChoice, |
| 31 | + AllocationAttributeChangeRequest, |
| 32 | + Allocation, |
| 33 | + AllocationAttribute, |
| 34 | + AllocationAttributeType, |
| 35 | + AttributeType, |
28 | 36 | )
|
29 | 37 |
|
30 | 38 | logging.disable(logging.CRITICAL)
|
@@ -415,6 +423,59 @@ def setUp(self):
|
415 | 423 | 'resource': f'{self.allocation.resources.first().pk}',
|
416 | 424 | }
|
417 | 425 |
|
| 426 | + # Create resources |
| 427 | + self.resource_standard = Resource.objects.create(name="Tandon", |
| 428 | + resource_type=ResourceType.objects.create(name="Generic")) |
| 429 | + self.resource_hpc = Resource.objects.create(name=GENERAL_RESOURCE_NAME, |
| 430 | + resource_type=ResourceType.objects.create(name="Cluster")) |
| 431 | + |
| 432 | + # Create AllocationAttributeType for slurm_account_name |
| 433 | + self.slurm_account_attr_type, _ = AllocationAttributeType.objects.get_or_create( |
| 434 | + name='slurm_account_name', attribute_type=AttributeType.objects.create(name='Text'), |
| 435 | + has_usage=False, is_private=False) |
| 436 | + |
| 437 | + def test_allocationcreateview_post_standard_resource(self): |
| 438 | + """Test POST to the AllocationCreateView with a standard resource and check slurm_account_name""" |
| 439 | + self.post_data['resource'] = str(self.resource_standard.pk) |
| 440 | + initial_count = self.project.allocation_set.count() |
| 441 | + |
| 442 | + response = self.client.post(self.url, data=self.post_data, follow=True) |
| 443 | + |
| 444 | + self.assertEqual(response.status_code, 200) |
| 445 | + self.assertContains(response, "Allocation requested.") |
| 446 | + self.assertEqual(self.project.allocation_set.count(), initial_count + 1) |
| 447 | + |
| 448 | + # Verify AllocationAttribute for slurm_account_name |
| 449 | + allocation = self.project.allocation_set.latest('id') |
| 450 | + expected_slurm_name = f"pr_{self.project.pk}_{self.resource_standard.name}" |
| 451 | + |
| 452 | + slurm_attr = AllocationAttribute.objects.get( |
| 453 | + allocation_attribute_type=self.slurm_account_attr_type, |
| 454 | + allocation=allocation |
| 455 | + ) |
| 456 | + self.assertEqual(slurm_attr.value, expected_slurm_name) |
| 457 | + |
| 458 | + def test_allocationcreateview_post_hpc_resource(self): |
| 459 | + """Test POST to the AllocationCreateView with University HPC resource and check slurm_account_name""" |
| 460 | + self.post_data['resource'] = str(self.resource_hpc.pk) |
| 461 | + initial_count = self.project.allocation_set.count() |
| 462 | + |
| 463 | + response = self.client.post(self.url, data=self.post_data, follow=True) |
| 464 | + |
| 465 | + self.assertEqual(response.status_code, 200) |
| 466 | + self.assertContains(response, "Allocation requested.") |
| 467 | + self.assertEqual(self.project.allocation_set.count(), initial_count + 1) |
| 468 | + |
| 469 | + # Verify AllocationAttribute for slurm_account_name |
| 470 | + allocation = self.project.allocation_set.latest('id') |
| 471 | + expected_slurm_name = f"pr_{self.project.pk}_general" |
| 472 | + |
| 473 | + slurm_attr = AllocationAttribute.objects.get( |
| 474 | + allocation_attribute_type=self.slurm_account_attr_type, |
| 475 | + allocation=allocation |
| 476 | + ) |
| 477 | + self.assertEqual(slurm_attr.value, expected_slurm_name) |
| 478 | + |
418 | 479 | def test_allocationcreateview_access(self):
|
419 | 480 | """Test access to the AllocationCreateView"""
|
420 | 481 | self.allocation_access_tstbase(self.url)
|
|
0 commit comments