예제 #1
0
 def test_hard_drive_id_numbers_unique(self):
     """
     Verify that two HardDrive objects are not created with the same ID
     """
     hd_1 = models.HardDrive()
     hd_1.save()
     hd_2 = models.HardDrive()
     hd_2.save()
     self.assertNotEqual(hd_1.id, hd_2.id)
 def test_serializing_empty_hard_drive(self):
     """Verify that an empty HardDrive provides only the id"""
     hd = models.HardDrive()
     hd.save()
     expected_value = {
         'status': 'Unknown',
         'service_end_date': None,
         'position': '',
         'capacity': '',
         'in_use': 'Unknown',
         'notes': '',
         'warranty_date': None,
         'service_start_date': None,
         'host': None,
         'purchase_date': None,
         'form_factor': '',
         'interface': 'Unknown',
         'media_type': '',
         'model': None,
         'rpm': None,
         'id': 9523044409L,
         'serial': '',
         'manufacturer': None
     }
     expected_value.pop('id', None)
     actual_value = HardDriveSerializer(hd).data
     actual_value.pop('id', None)
     self.assertEqual(actual_value, expected_value)
예제 #3
0
 def test_hard_drive_host_foreignkey_nullable(self):
     """
     Verify that a HardDrive object can have a null link to Host object
     """
     hd = models.HardDrive()
     hd.save()
     self.assertEqual(hd.host, None)
예제 #4
0
 def test_hard_drive_with_no_details(self):
     """
     Verify that a HardDrive object can be created with no information
     provided
     """
     hd = models.HardDrive()
     hd.save()
예제 #5
0
 def test_get_interface_representation_set(self):
     """
     Verifies that the value for the set interface is passed straight
     through
     """
     hd = models.HardDrive(interface='SAS')
     self.assertEqual(hd.get_interface_representation(), 'SAS')
예제 #6
0
 def test_get_capacity_representation_non_blank(self):
     """
     Verifies that the capacity is correctly converted from bytes to the
     correct unit
     """
     hd = models.HardDrive(capacity=120000000000)
     self.assertEqual(hd.get_capacity_representation(), '120.0 GB')
 def test_serializing_with_capacity_and_context(self):
     """
     Verify that a HardDrive with a capacity and the original context flag
     shows the capacity correctly in bytes
     """
     hd = models.HardDrive(capacity=120000000000)
     hd.save()
     expected_value = {
         'status': 'Unknown',
         'service_end_date': None,
         'position': '',
         'capacity': 120000000000L,
         'in_use': 'Unknown',
         'notes': '',
         'warranty_date': None,
         'service_start_date': None,
         'host': None,
         'purchase_date': None,
         'form_factor': '',
         'interface': 'Unknown',
         'media_type': '',
         'model': None,
         'rpm': None,
         'id': 9523044409L,
         'serial': '',
         'manufacturer': None
     }
     context = {'representation': 'original'}
     expected_value.pop('id', None)
     actual_value = HardDriveSerializer(hd, context=context).data
     actual_value.pop('id', None)
     self.assertEqual(actual_value, expected_value)
 def test_serializing_with_manufacturer(self):
     """
     Verify that a HardDrive attached to a Manufacturer shows the
     Manufacturer's name
     """
     manufacturer = models.Manufacturer(name='Test Manufacturer')
     manufacturer.save()
     hd = models.HardDrive(manufacturer=manufacturer)
     hd.save()
     expected_value = {
         'status': 'Unknown',
         'service_end_date': None,
         'position': '',
         'capacity': '',
         'in_use': 'Unknown',
         'notes': '',
         'warranty_date': None,
         'service_start_date': None,
         'host': None,
         'purchase_date': None,
         'form_factor': '',
         'interface': 'Unknown',
         'media_type': '',
         'model': None,
         'rpm': None,
         'id': 9523044409L,
         'serial': '',
         'manufacturer': 'Test Manufacturer'
     }
     expected_value.pop('id', None)
     actual_value = HardDriveSerializer(hd).data
     actual_value.pop('id', None)
     self.assertEqual(actual_value, expected_value)
 def test_serializing_with_interface(self):
     """
     Verify that a HardDrive with an interface set displays it correctly
     """
     hd = models.HardDrive(interface='SAS')
     hd.save()
     expected_value = {
         'status': 'Unknown',
         'service_end_date': None,
         'position': '',
         'capacity': '',
         'in_use': 'Unknown',
         'notes': '',
         'warranty_date': None,
         'service_start_date': None,
         'host': None,
         'purchase_date': None,
         'form_factor': '',
         'interface': 'SAS',
         'media_type': '',
         'model': None,
         'rpm': None,
         'id': 9523044409L,
         'serial': '',
         'manufacturer': None
     }
     expected_value.pop('id', None)
     actual_value = HardDriveSerializer(hd).data
     actual_value.pop('id', None)
     self.assertEqual(actual_value, expected_value)
예제 #10
0
 def test_get_capacity_representation_blank(self):
     """
     Verifies that the capacity is represented as an empty string instead
     of a None object
     """
     blank_hd = models.HardDrive()
     self.assertEqual(blank_hd.get_capacity_representation(), '')
예제 #11
0
 def test_generate_id_mock_randint(self):
     """
     Tests the generate_id function to make sure the fail condition leads
     to the while loop
     """
     hd = models.HardDrive()
     hd.save()
     self.assertTrue(models.generate_id(), hd.id)
예제 #12
0
 def test_hard_drive_manufacturer_foreignkey_nullable(self):
     """
     Verify that a HardDrive object can have a null link to a Manufacturer
     object
     """
     hd = models.HardDrive()
     hd.save()
     self.assertEqual(hd.manufacturer, None)
예제 #13
0
 def test_hard_drive_host_foreignkey_settable(self):
     """Verify that a HardDrive object can be linked to a Host object"""
     host = models.Host(name='Test Host')
     host.save()
     hd = models.HardDrive()
     hd.host = host
     hd.save()
     hd_id = hd.id
     # reload from db to make sure the object has changed
     hd = models.HardDrive.objects.get(id=hd_id)
     self.assertEqual(hd.host, host)
예제 #14
0
 def test_hard_drive_manufacturer_foreignkey_settable(self):
     """
     Verify that a HardDrive object can be linked to a Manufacturer object
     """
     manufacturer = models.Manufacturer(name='Test Manufacturer')
     manufacturer.save()
     hd = models.HardDrive()
     hd.manufacturer = manufacturer
     hd.save()
     hd_id = hd.id
     # reload from db to make sure the object has changed
     hd = models.HardDrive.objects.get(id=hd_id)
     self.assertEqual(hd.manufacturer, manufacturer)
예제 #15
0
 def test_hard_drive_model_foreignkey_settable(self):
     """
     Verify that a HardDrive object can be linked to a Model object
     """
     model = models.Model(name='Test Model')
     model.save()
     hd = models.HardDrive()
     hd.model = model
     hd.save()
     hd_id = hd.id
     # reload from db to make sure the object has changed
     hd = models.HardDrive.objects.get(id=hd_id)
     self.assertEqual(hd.model, model)
예제 #16
0
 def test_hard_drive_host_delete_foreignkey(self):
     """
     Verify that a HardDrive object will not be deleted when the linked Host
     object is deleted
     """
     host = models.Host(name='Test Host')
     host.save()
     hd = models.HardDrive(host=host)
     hd.save()
     hd_id = hd.id
     host.delete()
     # reload from db to make sure the object has changed
     hd = models.HardDrive.objects.get(id=hd_id)
     self.assertEqual(hd.host, None)
예제 #17
0
 def test_hard_drive_model_delete_foreignkey(self):
     """
     Verify that a HardDrive object will not be deleted when the linked
     Model object is deleted
     """
     model = models.Model(name='Test model')
     model.save()
     hd = models.HardDrive()
     hd.model = model
     hd.save()
     hd_id = hd.id
     model.delete()
     # reload from db to make the object has change
     hd = models.HardDrive.objects.get(id=hd_id)
     self.assertEqual(hd.model, None)
예제 #18
0
 def test_hard_drive_manufacturer_delete_foreignkey(self):
     """
     Verify that a HardDrive object will not be deleted when the linked
     Manufacturer object is deleted
     """
     manufacturer = models.Manufacturer(name='Test Manufacturer')
     manufacturer.save()
     hd = models.HardDrive()
     hd.manufacturer = manufacturer
     hd.save()
     hd_id = hd.id
     manufacturer.delete()
     # reload from db to make the object has change
     hd = models.HardDrive.objects.get(id=hd_id)
     self.assertEqual(hd.manufacturer, None)
 def test_serializing_with_filled_hard_drive(self):
     """
     Verify that a HardDrive with many fields filled displays them all
     """
     host = models.Host(name='Test Host')
     host.save()
     manufacturer = models.Manufacturer(name='Test Manufacturer')
     manufacturer.save()
     model = models.Model(name='Test Model')
     model.save()
     hd = models.HardDrive(host=host, manufacturer=manufacturer,
                           model=model, serial='123456789',
                           capacity=120000000000, media_type='SSD',
                           interface='SAS', form_factor='2.5',
                           rpm=10000, position='3', in_use=True,
                           status=True)
     hd.save()
     expected_value = {
         'status': 'Good',
         'service_end_date': None,
         'position': '3',
         'capacity': '120.0 GB',
         'in_use': 'Yes',
         'notes': '',
         'warranty_date': None,
         'service_start_date': None,
         'host': 'Test Host',
         'purchase_date': None,
         'form_factor': '2.5',
         'interface': 'SAS',
         'media_type': 'SSD',
         'model': 'Test Model',
         'rpm': 10000,
         'id': 9523044409L,
         'serial': '123456789',
         'manufacturer': 'Test Manufacturer'
     }
     expected_value.pop('id', None)
     actual_value = HardDriveSerializer(hd).data
     actual_value.pop('id', None)
     self.assertEqual(actual_value, expected_value)
예제 #20
0
 def test_get_status_representation_none(self):
     """
     Verifies that an unset status flag (None) is converted to 'Unknown'
     """
     hd = models.HardDrive()
     self.assertEqual(hd.get_status_representation(), 'Unknown')
예제 #21
0
 def test_get_status_representation_false(self):
     """Verifies that a False status flag is converted to 'Dead'"""
     hd = models.HardDrive(status=False)
     self.assertEqual(hd.get_status_representation(), 'Dead')
예제 #22
0
 def test_get_in_use_representation_true(self):
     """Verifies that a True in_use flag is converted to 'Yes'"""
     hd = models.HardDrive(in_use=True)
     self.assertEqual(hd.get_in_use_representation(), 'Yes')
예제 #23
0
 def test_get_interface_representation_none(self):
     """Verifies that an unset interface is converted to 'Unknown'"""
     hd = models.HardDrive()
     self.assertEqual(hd.get_interface_representation(), 'Unknown')
예제 #24
0
 def test_get_in_use_representation_false(self):
     """Verifies that a False in_use flag is converted to 'No'"""
     hd = models.HardDrive(in_use=False)
     self.assertEqual(hd.get_in_use_representation(), 'No')
예제 #25
0
 def test_get_status_representation_true(self):
     """Verifies that a True status flag is converted to 'Good'"""
     hd = models.HardDrive(status=True)
     self.assertEqual(hd.get_status_representation(), 'Good')