def test_install(self):
     hard = Hardware('h1', 'test', 100, 100)
     s1 = Software('win', 'Express', 120, 120)
     with self.assertRaises(Exception) as context:
         hard.install(s1)
     self.assertEqual(str(context.exception),
                      'Software cannot be installed')
Exemplo n.º 2
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware("Intel", "Power", 100, 200)

    def test_init(self):
        self.assertEqual("Intel", self.hardware.name)
        self.assertEqual("Power", self.hardware.type)
        self.assertEqual(100, self.hardware.capacity)
        self.assertEqual(200, self.hardware.memory)
        self.assertEqual([], self.hardware.software_components)

    def test_install_valid(self):
        software = ExpressSoftware("Nero", 20, 50)
        self.hardware.install(software)
        self.assertEqual([software], self.hardware.software_components)

    def test_install_dont_have_memory_and_capacity(self):
        software = ExpressSoftware("Nero", 150, 250)
        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)

        self.assertEqual("Software cannot be installed", str(ex.exception))
        self.assertEqual([], self.hardware.software_components)

    def test_uninstall(self):
        software = ExpressSoftware("Nero", 20, 50)
        self.hardware.software_components = [software]
        self.assertEqual([software], self.hardware.software_components)
        self.hardware.uninstall(software)
        self.assertEqual([], self.hardware.software_components)
 def test_uninstall_method(self):
     hardware = Hardware('test', 'SSD', 512, 16)
     software = LightSoftware('test', 10, 5)
     hardware.install(software)
     self.assertEqual(len(hardware.software_components), 1)
     hardware.uninstall(software)
     self.assertEqual(len(hardware.software_components), 0)
    def test_install_soft_raise_ex_when_capacity_or_memory_not_enough(self):
        with self.assertRaises(Exception) as ex:
            hardware = Hardware('test', 'SSD', 512, 16)
            software = LightSoftware('test', 550, 20)
            hardware.install(software)

        self.assertIsNotNone(ex.exception)
Exemplo n.º 5
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.hw = Hardware("Test", "Power", 100, 100)
        self.hw2 = Hardware("Test2", "Hevy", 200, 200)
        self.sw = ExpressSoftware("Sw", 10, 10)
        self.sw2 = ExpressSoftware("Sw1", 1, 1000)
        self.sw3 = ExpressSoftware("Sw2", 100000, 1)
        self.sw4 = ExpressSoftware("Sw3", 1000000, 1000000)

    def test_create_hardware(self):
        self.assertEqual(self.hw.name, "Test")
        self.assertEqual(self.hw.type, "Power")

    def test_create_ExpressSoftware(self):
        self.assertEqual(self.sw.name, "Sw")
        self.assertEqual(self.sw.memory_consumption, 20)
        self.assertEqual(self.sw.capacity_consumption, 10)

    def test_install(self):
        result = self.hw.install(self.sw)
        self.assertEqual(result, None)
        self.assertListEqual(self.hw.software_components, [self.sw])
        with self.assertRaises(Exception) as ex:
            self.hw.install(self.sw4)
        self.assertEqual(str(ex.exception), "Software cannot be installed")

    def test_uninstall(self):
        result1 = self.hw.install(self.sw)
        result = self.hw.uninstall(self.sw)
        self.assertEqual(result, None)
        self.assertListEqual(self.hw.software_components, [])
Exemplo n.º 6
0
 def test_uninstall(self):
     hw = Hardware('name', 'type', 1000, 512)
     sw = ExpressSoftware('test', 100, 100)
     hw.install(sw)
     self.assertEqual(1, len(hw.software_components))
     hw.uninstall(sw)
     self.assertEqual(0, len(hw.software_components))
 def test_uninstall(self):
     hard = Hardware('h1', 'test', 100, 100)
     s1 = Software('win', 'Express', 10, 10)
     hard.install(s1)
     hard.uninstall(s1)
     self.assertEqual([], hard.software_components)
     self.assertListEqual([], hard.software_components)
Exemplo n.º 8
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.kompiutur = Hardware('Pentium', 'Heavy', 1000, 1000)

    def test_one(self):
        result = (self.kompiutur.name, self.kompiutur.type,
                  self.kompiutur.memory, self.kompiutur.capacity)
        expected = ('Pentium', 'Heavy', 1000, 1000)

        self.assertEqual(result, expected)

    def test_two(self):
        programa = Software('Test', 'Express', 2000, 2000)

        with self.assertRaises(Exception) as ex:
            self.kompiutur.install(programa)
        self.assertEqual(str(ex.exception), 'Software cannot be installed')

    def test_three(self):
        programa = Software('Test', 'Express', 5, 5)

        self.kompiutur.install(programa)
        self.kompiutur.uninstall(programa)

        self.assertListEqual([], self.kompiutur.software_components)
Exemplo n.º 9
0
class TestHardware(unittest.TestCase):
    # def setUp(self):
    #     self.heavy_hd = Hardware("tejuk", "Heavy", 100, 100)
    #     self.power_hd = Hardware("silen", "Power", 300, 300)
    #     self.software = Software('Sf', 'Light', 200, 200)
    #
    # def test_attributes(self):
    #     for attr in ['name', 'type', 'capacity', 'memory']:
    #         self.assertTrue(hasattr(self.heavy_hd, attr))
    #
    # def test_initialization(self):
    #     self.assertEqual('tejuk', self.heavy_hd.name)
    #     self.assertEqual('Heavy', self.heavy_hd.type)
    #     self.assertEqual(100, self.heavy_hd.capacity)
    #     self.assertEqual(100, self.heavy_hd.memory)
    #     self.assertEqual([], self.heavy_hd.software_components)
    #
    #     self.assertEqual('silen', self.power_hd.name)
    #     self.assertEqual('Power', self.power_hd.type)
    #     self.assertEqual(300, self.power_hd.capacity)
    #     self.assertEqual(300, self.power_hd.memory)
    #     self.assertEqual([], self.power_hd.software_components)
    #
    # # def test_installation_should_be_successful(self):
    # #     self.power_hd.install(self.software)
    # #     self.assertEqual(1, len(self.power_hd.software_components))
    #
    # def test_installation_should_raise_exception(self):
    #     with self.assertRaises(Exception) as exc:
    #         self.heavy_hd.install(self.software)
    #         self.assertEqual("Software cannot be installed", exc)
    #
    # def test_uninstalling_software(self):
    #     self.power_hd.install(self.software)
    #     self.assertEqual(1, len(self.power_hd.software_components))
    #     self.power_hd.uninstall(self.software)
    #     self.assertEqual(0, len(self.power_hd.software_components))

    def setUp(self):
        self.hw = Hardware('Test hw', 'Power', 100, 50)
        self.sw = Software('Test sw', 'Light', 20, 10)

    def test_init_when_valid_arguments_should_implement(self):
        self.assertEqual(self.hw.name, 'Test hw')
        self.assertEqual(self.hw.type, 'Power')
        self.assertEqual(self.hw.capacity, 100)
        self.assertEqual(self.hw.memory, 50)
        self.assertEqual(self.hw.software_components, [])

    def test_install_when_not_enough_memory_or_capacity_should_raise_exception(
            self):
        self.sw = Software('Test sw', 'Light', 101, 51)
        with self.assertRaises(Exception) as ex:
            self.hw.install(self.sw)
        self.assertEqual(str(ex.exception), 'Software cannot be installed')

    def test_uninstall_when_software_in_components_should_remove_it(self):
        self.hw.software_components.append(self.sw)
        self.hw.uninstall(self.sw)
        self.assertEqual(self.hw.software_components, [])
class testHardware(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware("Intel", "Heavy", 100, 100)

    def test_hardware_initialized(self):
        self.assertEqual(self.hardware.name, "Intel")
        self.assertEqual(self.hardware.type, "Heavy")
        self.assertEqual(self.hardware.memory, 100)
        self.assertEqual(self.hardware.capacity, 100)
        self.assertEqual(self.hardware.software_components, [])

    def test_install_method_should_raise_exception(self):
        software = LightSoftware("Yes", 100, 200)
        with self.assertRaises(Exception) as cm:
            self.hardware.install(software)
        self.assertEqual(str(cm.exception), "Software cannot be installed")

    def test_install_method_should_add_components(self):
        software = LightSoftware("Yes", 10, 10)
        self.hardware.install(software)
        self.assertEqual(len(self.hardware.software_components), 1)

    def test_uninstall_method_delete_successfully(self):
        software = LightSoftware("Yes", 10, 20)
        self.hardware.install(software)
        self.hardware.uninstall(software)
        self.assertEqual(len(self.hardware.software_components), 0)

    def test_uninstall_method(self):
        software = LightSoftware("Yes", 1000000, 200000)
        self.hardware.install(software)
        self.hardware.uninstall(software)
        self.assertEqual(len(self.hardware.software_components), 0)
Exemplo n.º 11
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.hw = Hardware('hw', "Heavy", 100, 100)

    def test_init_state(self):
        self.assertEqual('hw', self.hw.name)
        self.assertEqual('Heavy', self.hw.type)
        self.assertEqual(100, self.hw.capacity)
        self.assertEqual(100, self.hw.memory)
        self.assertEqual([], self.hw.software_components)

    def test_install_sw_successfully(self):
        sw = Software('name','Light', 20, 20)
        self.hw.install(sw)
        self.assertEqual([sw], self.hw.software_components)

    def test_install_sw_unsuccessful(self):
        sw = Software('name', 'Light', 110, 20)
        with self.assertRaises(Exception) as exc1:
            self.hw.install(sw)
        self.assertEqual('Software cannot be installed', str(exc1.exception))
        sw1 = Software('name', 'Light', 20, 120)
        with self.assertRaises(Exception) as exc2:
            self.hw.install(sw1)
        self.assertEqual('Software cannot be installed', str(exc2.exception))

    def test_uninstall_sw_successful(self):
        sw = Software('name', 'Light', 20, 20)
        self.hw.install(sw)
        self.assertEqual([sw], self.hw.software_components)
        self.hw.uninstall(sw)
        self.assertEqual([], self.hw.software_components)
Exemplo n.º 12
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.hardware = Hardware('SSD', 'Storage', 512, 128)

    def test_init_method__expect_correct_initialization(self) -> None:
        self.assertEqual(self.hardware.name, 'SSD')
        self.assertEqual(self.hardware.type, 'Storage')
        self.assertEqual(self.hardware.capacity, 512)
        self.assertEqual(self.hardware.memory, 128)
        self.assertEqual(self.hardware.software_components, [])

    def test_install__when_capacity_valid_and_memory_valid__expect_software_installed(
            self) -> None:
        software = Software('Manjaro', 'OS', 256, 64)
        self.hardware.install(software)
        self.assertEqual(self.hardware.software_components, [software])

    def test_install__when_capacity_invalid_and_memory_valid__expect_exception(
            self) -> None:
        software = Software('Manjaro', 'OS', 1024, 64)
        with self.assertRaises(Exception) as context:
            self.hardware.install(software)

        self.assertEqual(context.exception.args[0],
                         'Software cannot be installed')

    def test_install__when_capacity_valid_and_memory_invalid__expect_exception(
            self) -> None:
        software = Software('Manjaro', 'OS', 256, 256)
        with self.assertRaises(Exception) as context:
            self.hardware.install(software)

        self.assertEqual(context.exception.args[0],
                         'Software cannot be installed')

    def test_install__when_capacity_invalid_and_memory_invalid__expect_exception(
            self) -> None:
        software = Software('Manjaro', 'OS', 1024, 256)
        with self.assertRaises(Exception) as context:
            self.hardware.install(software)

        self.assertEqual(context.exception.args[0],
                         'Software cannot be installed')

    def test_uninstall__expect_software_uninstalled(self) -> None:
        software = Software('Manjaro', 'OS', 256, 64)
        self.hardware.install(software)
        self.hardware.uninstall(software)
        self.assertEqual(self.hardware.software_components, [])
Exemplo n.º 13
0
class TestHardware(TestCase):
    def setUp(self):
        self.hardware = Hardware("TestHardware", "TestType", 10, 10)
        self.software = Software("TestSoftware", "TestType", 10, 10)

    def test_hardware_install__when_software_capacity_is_above_hardware_capacity__expept_exception(
            self):
        self.software.capacity_consumption += 1
        with self.assertRaises(Exception) as context:
            self.hardware.install(self.software)

        self.assertEqual("Software cannot be installed",
                         str(context.exception))

    def test_hardware_install__when_software_memory_is_above_hardware_memory__expept_exception(
            self):
        self.software.memory_consumption += 1
        with self.assertRaises(Exception) as context:
            self.hardware.install(self.software)

        self.assertEqual("Software cannot be installed",
                         str(context.exception))

    def test_hardware_install__when_software_memory_and_capacity_is_above_hardware_memory_and_capacity_expect_exception(
            self):
        self.software.memory_consumption += 1
        self.software.capacity_consumption += 1

        with self.assertRaises(Exception) as context:
            self.hardware.install(self.software)

        self.assertEqual("Software cannot be installed",
                         str(context.exception))

    def test_hardware_install__when_software_consumption_is_valid__expect_to_add_it_in_software_components(
            self):
        self.hardware.install(self.software)
        self.assertEqual([self.software], self.hardware.software_components)

    def test_hardware_uninstall__expect_software_to_be_removed_from_software_components(
            self):
        self.hardware.install(self.software)
        self.hardware.uninstall(self.software)
        self.assertEqual([], self.hardware.software_components)
Exemplo n.º 14
0
class TestHardware(TestCase):
    def setUp(self) -> None:
        self.hardware = Hardware('HDD', 'Heavy', 1000, 1000)

    def test_init_expect_correct_attrs(self):
        self.assertEqual('HDD', self.hardware.name)
        self.assertEqual('Heavy', self.hardware.type)
        self.assertEqual(1000, self.hardware.capacity)
        self.assertEqual(1000, self.hardware.memory)
        self.assertEqual([], self.hardware.software_components)

    def test_install__when_max_capacity_and_memory_usage__expect_installed(
            self):
        software = ExpressSoftware('Linux', 1000, 500)
        self.hardware.install(software)
        self.assertEqual(1, len(self.hardware.software_components))

    def test_install__when_low_capacity__expect_exception(self):
        software = ExpressSoftware('Linux', 1001, 500)
        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)
        self.assertEqual('Software cannot be installed', str(ex.exception))

    def test_install__when_low_memory__expect_exception(self):
        software = ExpressSoftware('Linux', 1000, 501)
        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)
        self.assertEqual('Software cannot be installed', str(ex.exception))

    def test_uninstall__when_software_in_list__expect_software_removerd(self):
        software = ExpressSoftware('Linux', 200, 200)
        self.hardware.install(software)
        self.assertEqual(1, len(self.hardware.software_components))
        self.hardware.uninstall(software)
        self.assertEqual(0, len(self.hardware.software_components))

    def test_uninstall__when_invalid_software__expect_NONE(self):
        software = ExpressSoftware('Linux', 200, 200)
        software2 = ExpressSoftware('Linux', 1, 1)
        self.hardware.install(software)
        self.assertEqual(1, len(self.hardware.software_components))
        self.assertIsNone(self.hardware.uninstall(software2))
        self.assertEqual(1, len(self.hardware.software_components))
Exemplo n.º 15
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.test_hardware = Hardware('Test_name', 'Heavy', 100, 100)

    def test_init_hardware(self):
        attrs = ['name', 'type', 'capacity', 'memory', 'software_components']
        for attr in attrs:
            self.assertTrue(hasattr(self.test_hardware, attr))

        self.assertEqual('Test_name', self.test_hardware.name)
        self.assertEqual('Heavy', self.test_hardware.type)
        self.assertEqual(100, self.test_hardware.capacity)
        self.assertEqual(100, self.test_hardware.memory)
        self.assertEqual([], self.test_hardware.software_components)

    def test_hardware_install_with_valid_software_obj__should_add_it_to_software_components(
            self):
        light_software = Software('test', 'Light', 10, 10)
        test_software = Software('test_express', 'Express', 10, 10)
        self.test_hardware.install(light_software)
        self.assertEqual(1, len(self.test_hardware.software_components))
        self.test_hardware.install(test_software)
        self.assertEqual(2, len(self.test_hardware.software_components))

    def test_hardware_install_when_not_enough_memory__should_raise(self):
        light_software = Software('test', 'Light', 10, 1000)
        with self.assertRaises(Exception) as ex:
            self.test_hardware.install(light_software)

        self.assertEqual("Software cannot be installed", str(ex.exception))

    def test_hardware_install_when_not_enough_capacity__should_raise(self):
        light_software = Software('test', 'Light', 1000, 10)
        with self.assertRaises(Exception) as ex:
            self.test_hardware.install(light_software)

        self.assertEqual("Software cannot be installed", str(ex.exception))

    def test_hardware_uninstall__should_remove_from_software_components(self):
        light_software = Software('test', 'Light', 10, 10)
        self.test_hardware.install(light_software)
        self.test_hardware.uninstall(light_software)
        self.assertEqual(0, len(self.test_hardware.software_components))
Exemplo n.º 16
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware("SSD", "Heavy", 100, 120)

    def test_set_attr(self):
        self.assertEqual(self.hardware.name, "SSD")
        self.assertEqual(self.hardware.type, "Heavy")
        self.assertEqual(self.hardware.memory, 120)
        self.assertEqual(self.hardware.capacity, 100)
        self.assertEqual(self.hardware.software_components, [])

    def test_successful_install(self):
        soft = Software("Skype", "Express", 60, 40)
        self.hardware.install(soft)
        self.assertEqual(len(self.hardware.software_components), 1)

    def test_unsuccessful_install(self):
        soft = Software("NotSkype", "Express", 200, 240)
        with self.assertRaises(Exception) as ex:
            self.hardware.install(soft)
            self.assertEqual(str(ex), "Software cannot be installed")

    def test_uninstall(self):
        soft = Software("Skype", "Express", 60, 40)
        self.hardware.install(soft)
        self.hardware.uninstall(soft)
        self.assertEqual(self.hardware.software_components, [])

    def test_unsuccessful_uninstall(self):
        soft = Software("Skype", "Express", 60, 40)
        softy = Software("Discord", "Express", 20, 20)
        self.hardware.install(soft)
        with self.assertRaises(Exception) as ex:
            self.hardware.uninstall(softy)
            self.assertEqual(str(ex), "Some of the components do not exist")

    def test_not_working_install_message(self):
        software = Software("Skype", "Express", 100, 10)
        self.hardware = Hardware("SSD", "Heavy", 10, 12)
        try:
            self.hardware.install(software)
        except Exception as ex:
            self.assertEqual(str(ex), "Software cannot be installed")
Exemplo n.º 17
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hw = Hardware('name', 'type', 100, 1000)

    def test_init(self):
        self.assertEqual('name', self.hw.name)
        self.assertEqual('type', self.hw.type)
        self.assertEqual(100, self.hw.capacity)
        self.assertEqual(1000, self.hw.memory)
        self.assertListEqual([], self.hw.software_components)
        self.assertEqual(0, len(self.hw.software_components))

    def test_install_proper(self):
        sw = ExpressSoftware('test', 1, 1)
        self.hw.install(sw)
        self.assertIn(sw, self.hw.software_components)
        self.assertEqual(1, len(self.hw.software_components))

    def test_install_raises(self):
        sw = ExpressSoftware('test', 9999, 9999)
        with self.assertRaises(Exception) as ex:
            self.hw.install(sw)
        self.assertEqual("Software cannot be installed", str(ex.exception))

    def test_uninstall(self):
        sw = ExpressSoftware('test', 1, 1)
        self.hw.install(sw)
        self.hw.uninstall(sw)
        self.assertTrue(sw not in self.hw.software_components)
        self.assertEqual(0, len(self.hw.software_components))
Exemplo n.º 18
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware('NVD', 'type', 10, 10)

    def test_init(self):
        self.assertEqual('NVD', self.hardware.name)
        self.assertEqual('type', self.hardware.type)
        self.assertEqual(10, self.hardware.capacity)
        self.assertEqual(10, self.hardware.memory)
        self.assertEqual([], self.hardware.software_components)

    def test_install(self):
        software = Software('MS', 'type', 5, 5)
        self.hardware.install(software)
        self.assertEqual(self.hardware.software_components, [software])

        software = Software('MS', 'type', 15, 15)
        with self.assertRaises(Exception) as cm:
            self.hardware.install(software)
        self.assertEqual(str(cm.exception), "Software cannot be installed")

    def test_uninstall(self):
        software = Software('MS', 'type', 5, 5)
        self.hardware.install(software)
        self.assertEqual(self.hardware.software_components, [software])
        self.hardware.uninstall(software)
        self.assertEqual(self.hardware.software_components, [])
Exemplo n.º 19
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware('Test', 'Power', 100, 100)

    def test_correct_initialization(self):
        self.assertEqual(self.hardware.name, 'Test')
        self.assertEqual(self.hardware.type, 'Power')
        self.assertEqual(self.hardware.capacity, 100)
        self.assertEqual(self.hardware.memory, 100)
        self.assertEqual(self.hardware.software_components, [])

    def test_install_should_add_software_to_the_software_components(self):
        software = Software('Windows', 'Light', 50, 50)
        self.hardware.install(software)
        self.assertEqual(len(self.hardware.software_components), 1)
        # self.assertEqual(len(self.hardware.software_components), 1)

    def test_install_should_raise_error_if_capacity_or_memory_are_more_than_the_hardware_ones(
            self):
        software = Software('Windows', 'OS', 150, 150)

        with self.assertRaises(Exception) as cm:
            self.hardware.install(software)
        self.assertEqual(str(cm.exception), "Software cannot be installed")

    def test_uninstall_should_remove_software_from_the_software_components(
            self):
        software = Software('Windows', 'OS', 25, 25)
        self.hardware.install(software)
        self.hardware.uninstall(software)
        self.assertEqual(len(self.hardware.software_components), 0)
Exemplo n.º 20
0
class HardwareTests(TestCase):
    def setUp(self) -> None:
        self.hardware = Hardware("SSD", "Heavy", 500, 500)

    def test_init_attrs_are_set(self):
        self.assertEqual("SSD", self.hardware.name)
        self.assertEqual("Heavy", self.hardware.type)
        self.assertEqual(500, self.hardware.capacity)
        self.assertEqual(500, self.hardware.memory)
        self.assertEqual([], self.hardware.software_components)

    def test_hardware__no_memory_when_software_is_installed__expect_exception(
            self):
        software = Software("Win10", "Light", 501, 501)
        with self.assertRaises(Exception) as context:
            self.hardware.install(software)
        self.assertEqual("Software cannot be installed",
                         str(context.exception))

    def test_hardware_equal_capacity_and_memory_when_software_is_installed(
            self):
        software = Software("Win10", "Light", 500, 500)
        self.hardware.install(software)
        self.assertEqual(1, len(self.hardware.software_components))

    def test_hardware_uninstall__expect_software_to_be_removed_from_software_components(
            self):
        software = Software("Win10", "Light", 500, 500)
        self.hardware.install(software)
        self.hardware.uninstall(software)
        self.assertEqual([], self.hardware.software_components)
Exemplo n.º 21
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware(name='HDD',
                                 type='PowerHardware',
                                 capacity=200,
                                 memory=200)
        self.software = Software("HDD", "LightSoftware", 0, 10)

    def test_hardware_if_all_attributes_are_set(self):
        self.assertEqual('HDD', self.hardware.name)
        self.assertEqual('PowerHardware', self.hardware.type)
        self.assertEqual(200, self.hardware.capacity)
        self.assertEqual(200, self.hardware.memory)

    def test_hardware_install_if_there_is_enough_capacity_and_memory(self):
        self.hardware.install(self.software)
        self.assertTrue(self.software in self.hardware.software_components)

    def test_hardware_install_if_there_is_NOT_enough_capacity_and_memory(self):
        self.software.memory_consumption = 250
        with self.assertRaises(Exception) as ex:
            self.hardware.install(self.software)
        self.assertEqual('Software cannot be installed', str(ex.exception))

    def test_hardware_uninstall_if_software_is_in_software_components(self):
        self.hardware.install(self.software)
        self.assertTrue(self.software in self.hardware.software_components)
        self.hardware.uninstall(self.software)
        self.assertTrue(self.software not in self.hardware.software_components)
Exemplo n.º 22
0
class HardwareTest(unittest.TestCase):
    def setUp(self):
        self.hardware = Hardware('Hardware 1', 'Heavy', 500, 500)

    def test_attributes(self):
        self.assertEqual('Hardware 1', self.hardware.name)
        self.assertEqual('Heavy', self.hardware.type)
        self.assertEqual(500, self.hardware.memory)
        self.assertEqual(500, self.hardware.capacity)
        self.assertEqual([], self.hardware.software_components)

    def test_install__expect_success(self):
        software = ExpressSoftware('Express', 200, 100)
        self.hardware.install(software)
        self.assertEqual(1, len(self.hardware.software_components))

    def test_install__expect_raise__exception(self):
        software = ExpressSoftware('Express', 300, 300)
        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)
        self.assertEqual('Software cannot be installed', str(ex.exception))

    def test_uninstall__when_software_in_components__expect_to_uninstall_it(
            self):
        software = ExpressSoftware('Express', 200, 100)
        self.hardware.install(software)
        self.assertEqual(1, len(self.hardware.software_components))
        self.hardware.uninstall(software)
        self.assertEqual([], self.hardware.software_components)
Exemplo n.º 23
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.hardware = Hardware("SSD", "Light", 1000, 1000)

    def test_init(self):
        self.assertEqual("SSD", self.hardware.name)
        self.assertEqual("Light", self.hardware.type)
        self.assertEqual(1000, self.hardware.capacity)
        self.assertEqual(1000, self.hardware.memory)

    def test_install(self):
        self.assertEqual([], self.hardware.software_components)
        software = Software("Mozilla", "browser", 200, 200)
        self.hardware.install(software)
        self.assertEqual([software], self.hardware.software_components)

    def test_install_raises_error(self):
        with self.assertRaises(Exception) as e:
            software1 = Software("Ciberpunk 2077", "game", 2000, 500)
            self.hardware.install(software1)
        self.assertEqual("Software cannot be installed", str(e.exception))

    def test_uninstall(self):
        software = Software("Mozilla", "browser", 200, 200)
        self.hardware.install(software)
        self.hardware.uninstall(software)
        self.assertEqual([], self.hardware.software_components)
Exemplo n.º 24
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.h = Hardware("Lenovo", "Power", 800, 32)
        self.s = Software("Win", "Light", 10, 20)
        self.e = Software("Win", "Express", 1000, 2000)

    def test_init(self):  # 0 test
        self.assertEqual(self.h.name, "Lenovo")
        self.assertEqual(self.h.type, "Power")
        self.assertEqual(self.h.capacity, 800)
        self.assertEqual(self.h.memory, 32)

    def test_empty_software_components(self):  # 1 test
        self.assertEqual(self.h.software_components, [])

    def test_add_to_software_components(self):  # 2 test
        self.h.install(self.s)
        self.assertEqual(self.h.software_components, [self.s])

    def test(self):
        self.h.install(self.s)  # 3 test
        self.assertEqual(self.h.software_components, [self.s])
        self.h.uninstall(self.s)
        self.assertEqual(self.h.software_components, [])

    def test_cannot_add_due_to_high_requirements(self):  # 4 test
        with self.assertRaises(Exception) as ex:
            self.h.install(self.e)
        self.assertEqual("Software cannot be installed", str(ex.exception))
        self.assertEqual(self.h.software_components, [])
Exemplo n.º 25
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hw = Hardware('NVIDIA', 'video card', 4, 4)

    def test_hardware_init_method(self):
        self.assertEqual(self.hw.name, 'NVIDIA')
        self.assertEqual(self.hw.type, 'video card')
        self.assertEqual(self.hw.capacity, 4)
        self.assertEqual(self.hw.memory, 4)

    def test_install_method_when_capacity_and_memory_not_enough_for_software_should_raises(
            self):
        sw = Software('Linux', 'os', 5, 4)
        with self.assertRaises(Exception) as ex:
            self.hw.install(sw)

        self.assertIsNotNone(str(ex.exception))

    def test_install_method_when_capacity_and_memory_enough(self):
        sw = Software('Linux', 'os', 4, 4)
        self.hw.install(sw)
        result = self.hw.software_components[0]
        expected = 'Linux'

        self.assertEqual(result.name, expected)

    def test_uninstall_method(self):
        sw = Software('Linux', 'os', 4, 4)
        self.hw.install(sw)
        self.hw.uninstall(sw)

        self.assertEqual(self.hw.software_components, [])
Exemplo n.º 26
0
class TestHardware(unittest.TestCase):
    def setUp(self):
        self.hw = Hardware("HDD", 'Power', 200, 200)

    def test_set_attr(self):
        self.assertEqual(self.hw.name, 'HDD')
        self.assertEqual(self.hw.type, 'Power')
        self.assertEqual(self.hw.capacity, 200)
        self.assertEqual(self.hw.memory, 200)
        self.assertEqual(len(self.hw.software_components), 0)

    def test_install_raises(self):
        with self.assertRaises(Exception) as ex:
            sw = Software('Desktop', 'Light', 3000, 1000)
            self.hw.install(sw)
        self.assertEqual(str(ex.exception), "Software cannot be installed")

    def test_install_sw(self):
        sw = Software('Desktop', 'Light', 100, 100)
        self.hw.install(sw)
        self.assertEqual(self.hw.software_components, [sw])

    def test_uninstall_sw(self):
        sw = Software('Desktop', 'Light', 100, 100)
        self.hw.install(sw)
        self.hw.uninstall(sw)
        self.assertEqual(len(self.hw.software_components), 0)
Exemplo n.º 27
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.hardware = Hardware('name', 'type', 1000, 512)

    def test_init(self):
        self.assertEqual('name', self.hardware.name)
        self.assertEqual('type', self.hardware.type)
        self.assertEqual(1000, self.hardware.capacity)
        self.assertEqual(512, self.hardware.memory)
        self.assertListEqual([], self.hardware.software_components)

    def test_install_proper(self):
        software = ExpressSoftware('test',
                                   capacity_consumption=100,
                                   memory_consumption=100)
        self.hardware.install(software)
        self.assertListEqual([software], self.hardware.software_components)

    def test_install_raises(self):
        with self.assertRaises(Exception) as ex:
            software = ExpressSoftware('test',
                                       capacity_consumption=10000,
                                       memory_consumption=10000)
            self.hardware.install(software)
        self.assertEqual("Software cannot be installed", str(ex.exception))

    def test_uninstall(self):
        software = ExpressSoftware('test',
                                   capacity_consumption=100,
                                   memory_consumption=100)
        self.hardware.install(software)
        self.assertListEqual([software], self.hardware.software_components)
        self.hardware.uninstall(software)
        self.assertListEqual([], self.hardware.software_components)
Exemplo n.º 28
0
class TestHardware(unittest.TestCase):
    def test_hhardware__init__(self):
        self.hardware = Hardware("Server", "Heavy", 5000, 3500)
        self.assertEqual(self.hardware.name, "Server")
        self.assertEqual(self.hardware.type, "Heavy")
        self.assertEqual(self.hardware.capacity, 5000)
        self.assertEqual(self.hardware.memory, 3500)
        self.assertEqual(self.hardware.software_components, [])

    def test_phardware__init__(self):
        self.hardware = Hardware("Docking Station", "Power", 3000, 5500)
        self.assertEqual(self.hardware.name, "Docking Station")
        self.assertEqual(self.hardware.type, "Power")
        self.assertEqual(self.hardware.capacity, 3000)
        self.assertEqual(self.hardware.memory, 5500)
        self.assertEqual(self.hardware.software_components, [])

    def test_install_method_raising_exception_memory_failure(
            self):  # Memory failure
        self.hardware = Hardware("Server", "Heavy", 50, 200)
        self.software = Software("Linux", "Express", 100, 200)
        with self.assertRaises(Exception,
                               msg="Software cannot be installed") as exc:
            self.hardware.install(self.software)

        self.assertEqual(str(exc.exception), exc.msg)

    def test_install_method_raising_exception_capacity_failure(
            self):  # Capacity failure
        self.hardware = Hardware("Server", "Heavy", 250, 100)
        self.software = Software("Linux", "Express", 100, 200)
        with self.assertRaises(Exception,
                               msg="Software cannot be installed") as exc:
            self.hardware.install(self.software)

        self.assertEqual(str(exc.exception), exc.msg)

    def test_successful_software_install(self):
        self.hardware = Hardware("Server", "Heavy", 250, 200)
        self.software = Software("Linux", "Express", 50, 100)
        self.hardware.install(self.software)
        self.assertEqual(self.hardware.software_components, [self.software])

    def test_uninstall_software(self):
        self.hardware = Hardware("Server", "Heavy", 250, 200)
        self.software = Software("Linux", "Express", 50, 100)
        self.hardware.install(self.software)
        self.hardware.uninstall(self.software)
        self.assertEqual(self.hardware.software_components, [])
Exemplo n.º 29
0
class TestHardware(TestCase):
    def setUp(self):
        self.hardware = Hardware('Test hardware', 'Heavy', 100, 10)

    def test_init__expect_to_set_attributes_correct(self):
        self.assertEqual('Test hardware', self.hardware.name)
        self.assertEqual('Heavy', self.hardware.hard_type)
        self.assertEqual(100, self.hardware.capacity)
        self.assertEqual(10, self.hardware.memory)
        self.assertEqual([], self.hardware.software_components)

    def test_install__when_enough_memory_and_capacity__expect_to_add_it_to_the_list(
            self):
        software = LightSoftware('Test software', 5, 2)
        self.hardware.install(software)

        self.assertEqual(1, len(self.hardware.software_components))
        self.assertListEqual([software], self.hardware.software_components)

    def test_install__when_not_enough_memory_and_capacity__expect_exception(
            self):
        software = ExpressSoftware('Test ex software', 350, 500)

        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)

        self.assertEqual("Software cannot be installed", str(ex.exception))

    def test_uninstall__when_software_exist__expect_to_remove_it_from_the_list(
            self):
        software = LightSoftware('Test software', 5, 2)
        self.hardware.install(software)

        self.assertEqual(1, len(self.hardware.software_components))

        self.hardware.uninstall(software)
        self.assertEqual(0, len(self.hardware.software_components))

    def test_uninstall__when_software_not_exist__expect_to_remove_it_from_the_list(
            self):
        software_l = LightSoftware('Test software', 5, 2)
        self.hardware.install(software_l)
        self.assertEqual(1, len(self.hardware.software_components))

        software_ex = ExpressSoftware('Test ex software', 350, 500)
        self.hardware.uninstall(software_ex)
        self.assertEqual(1, len(self.hardware.software_components))
Exemplo n.º 30
0
class TestHardware(unittest.TestCase):
    def setUp(self) -> None:
        self.hardware = Hardware('test_hardware', 'Power', 100, 200)

    def test_HardwareInitialization(self):
        hardware = Hardware('Test', 'Heavy', 100, 200)
        self.assertEqual(hardware.name, 'Test')
        self.assertEqual(hardware.type, 'Heavy')
        self.assertEqual(hardware.capacity, 100)
        self.assertEqual(hardware.memory, 200)
        self.assertEqual(len(hardware.software_components), 0)

    def test_HardwareInitialization_with_wrong_type_shouldRaise(self):
        with self.assertRaises(Exception) as context:
            Hardware('Test', 'Big', 100, 200)
        self.assertIsNotNone(context.exception)

    def test_HardwareInstall(self):
        test_software = Software('TestSoftware', 'Light', 20, 30)
        self.hardware.install(test_software)
        self.assertEqual(len(self.hardware.software_components), 1)

    def test_HardwareInstall_whenNotEnoughCapacityAndMemory_shouldRaise(self):
        test_software = Software('TestSoftware', 'Light', 200, 300)

        with self.assertRaises(Exception) as context:
            self.hardware.install(test_software)

        self.assertIsNotNone(context.exception)
        self.assertEqual(context.exception.__str__(),
                         "Software cannot be installed")

    def test_HardwareUninstall(self):
        test_software = Software('TestSoftware', 'Light', 20, 30)
        test_software2 = Software('TestSoftware2', 'Light', 10, 30)

        self.hardware.install(test_software)
        self.hardware.install(test_software2)
        self.hardware.uninstall(test_software)
        self.assertEqual(len(self.hardware.software_components), 1)
        self.hardware.uninstall(test_software2)
        self.assertEqual(len(self.hardware.software_components), 0)