def test_UserSystemRole_creation(self): with self.subTest("No Arguments"): user_system_role = UserSystemRole() self.assertIsNone(user_system_role.user) self.assertIsNone(user_system_role.system) self.assertIsNone(user_system_role.role) with self.subTest("User Only"): user = User(name="Fred") user_system_role = UserSystemRole(user=user) self.assertIs(user_system_role.user, user) self.assertIsNone(user_system_role.system) self.assertIsNone(user_system_role.role) with self.subTest("System Only"): system = System(name="Fred's Computer") user_system_role = UserSystemRole(system=system) self.assertIsNone(user_system_role.user) self.assertIs(user_system_role.system, system) self.assertIsNone(user_system_role.role) with self.subTest("Role Only"): role = Role(name="Fred's Role") user_system_role = UserSystemRole(role=role) self.assertIsNone(user_system_role.user) self.assertIsNone(user_system_role.system) self.assertIs(user_system_role.role, role) with self.subTest("All"): user = User(name="Fred") system = System(name="Fred's Computer") role = Role(name="Fred's Role") user_system_role = UserSystemRole(user=user, system=system, role=role) self.assertIs(user_system_role.user, user) self.assertIs(user_system_role.system, system) self.assertIs(user_system_role.role, role)
def test_SystemComponent_creation(self): with self.subTest("No Arguments"): system_component = SystemComponent() self.assertEqual(system_component.count, 1) self.assertIsNone(system_component.component) self.assertIsNone(system_component.system) with self.subTest("Component Only"): component = Component() system_component = SystemComponent(component=component) self.assertIs(system_component.component, component) self.assertIsNone(system_component.system) with self.subTest("System Only"): system = System(name="Fred's Computer") system_component = SystemComponent(system=system) self.assertIsNone(system_component.component) self.assertIs(system_component.system, system) with self.subTest("All"): component = Component() system = System(name="Fred's Computer") system_component = SystemComponent(system=system, component=component) self.assertIs(system_component.component, component) self.assertIs(system_component.system, system) self.assertIn(system_component, component.system_components) self.assertIn(system, component.systems) self.assertIn(system_component, system.system_components) self.assertIn((1, component), system.components)
def fake_systems_generator(max_systems=None): count = 0 while not max_systems or count < max_systems: cpu = CPU( manufacturer="AMD", model="Ryzen 3800X", isa="x86-64", tdp=105, core_count=8, threads_per_core=2, nominal_frequency=3.9, maximum_frequency=4.5, ) gpu = GPU( manufacturer="NVIDIA", model="1070", architecture="CUDA", tdp=105, core_count=1920, memory=8.0, ) memory = Memory( manufacturer="G-Skill", model="Trident", standard="DDR4", capacity=16.0, frequency=3600, cas_latency=16, t_rcd=19, t_rp=19, t_ras=39, ) storage = Storage( manufacturer="Sabrent", model="Rocket", standard="NVMe PCIe 4.0", capacity=500.0, max_read=5000, max_write=2500, ) os = OperatingSystem( developer="Microsoft", name="Windows 10", ) system = System(name=f"System {count}") system.add_component(cpu) system.add_component(gpu) system.add_component(memory) system.add_component(memory) system.add_component(storage) system.add_component(os) yield system count += 1
def test_query_UserSystemRole(self): # Put some data into the db with get_session(bind=get_engine("sqlite:///:memory:")) as session: user = User(name="Fred") system = System(name="Fred's Computer") administrator = Role(name="Administrator") reporter = Role(name="Reporter") observer = Role(name="Observer") UserSystemRole(user=user, system=system, role=administrator) UserSystemRole(user=user, system=system, role=reporter) UserSystemRole(user=user, system=system, role=observer) session.add(user) # Query the db and make sure everything lines up with get_session(bind=get_engine("sqlite:///:memory:")) as session: users = session.query(User) systems = session.query(System) self.assertEqual(len(users[0].system_roles), 3) self.assertEqual(len(systems[0].user_roles), 3) for role in users[0].system_roles: self.assertIn(role, systems[0].user_roles) self.assertIs(role.user, users[0]) for role in systems[0].user_roles: self.assertIn(role, users[0].system_roles) self.assertIs(role.system, systems[0]) self.assertIn(systems[0], [role.system for role in users[0].system_roles]) self.assertIn(users[0], [role.user for role in systems[0].user_roles])
def test_SystemComponent_user_property(self): system = System(name="Fred's Computer") component = Component() system_component = SystemComponent(system=system) system_component.component = component self.assertIn(system_component, component.system_components) self.assertIn(system, component.systems)
def test_SystemComponent_system_property(self): system = System(name="Fred's Computer") component = Component() system_component = SystemComponent(component=component) system_component.system = system self.assertIn(system_component, system.system_components) self.assertIn((1, component), system.components)
def test_add_component(self): # Put some data into the db with get_session(bind=get_engine("sqlite:///:memory:")) as session: cpu = CPU( manufacturer="AMD", model="Ryzen 3800X", isa="x86-64", tdp=105, core_count=8, threads_per_core=2, nominal_frequency=3.9, maximum_frequency=4.5, ) gpu = GPU( manufacturer="NVIDIA", model="1070", architecture="CUDA", tdp=105, core_count=1920, memory=8.0, ) memory = Memory( manufacturer="G-Skill", model="Trident", standard="DDR4", capacity=16.0, frequency=3600, cas_latency=16, t_rcd=19, t_rp=19, t_ras=39, ) storage = Storage( manufacturer="Sabrent", model="Rocket", standard="NVMe PCIe 4.0", capacity=500.0, max_read=5000, max_write=2500, ) os = OperatingSystem( developer="Microsoft", name="Windows 10", ) system = System(name="Some System") system.add_component(cpu) system.add_component(gpu) system.add_component(memory) system.add_component(memory) system.add_component(storage) system.add_component(os) session.add(system) with get_session(bind=get_engine("sqlite:///:memory:")) as session: systems = session.query(System) self.assertEqual(len(list(systems)), 1) system = systems[0] cpu = session.query(CPU).first() gpu = session.query(GPU).first() memory = session.query(Memory).first() storage = session.query(Storage).first() os = session.query(OperatingSystem).first() # Check that our system object is composed correctly self.assertEqual(system.name, "Some System") self.assertEqual(len(list(system.components)), 6) self.assertIn((1, cpu), system.components) self.assertIn((1, gpu), system.components) self.assertIn((2, memory), system.components) self.assertIn((1, storage), system.components) self.assertIn((1, os), system.components)
def test_UserSystemRole_system_property(self): user_system_role = UserSystemRole() system = System(name="Fred's Computer") user_system_role.system = system self.assertIn(user_system_role, system.user_roles)