def setUpTestData(cls): cls.unavailable_status = ServerStatusFactory( server_status="Unavailable") cls.server = StaticServerFactory() cls.unavailable_server = StaticServerFactory( server_status=cls.unavailable_status) cls.project = ProjectFactory()
def setUpTestData(cls): cls.server = StaticServerFactory() cls.server_dict = cls.server.__dict__ cls.aux_addy_1 = AuxServerAddressFactory(static_server=cls.server, primary=False) cls.aux_addy_2 = AuxServerAddressFactory(static_server=cls.server, primary=False) cls.to_be_deleted = AuxServerAddressFactory( static_server=cls.server, primary=False )
def test_prop_count_status(self): provider = ServerProviderFactory(server_provider="AWS") StaticServerFactory(server_provider=provider) try: count = provider.count self.assertEqual(count, 1) except Exception: self.fail( "ServerProvider model `count` property failed unexpectedly!")
def test_prop_count_status(self): status = ServerStatusFactory(server_status="Enabled") StaticServerFactory(server_status=status) try: count = status.count self.assertEqual(count, 1) except Exception: self.fail( "ServerStatus model `count` property failed unexpectedly!")
def test_property_server_name(self): entry = ServerHistoryFactory(server=StaticServerFactory( name="teamserver.local")) try: self.assertEqual(entry.server_name, "teamserver.local") entry.server.name = "new-server.local" entry.server.save() self.assertEqual(entry.server_name, "new-server.local") except Exception: self.fail( "ServerHistory model `server_name` property failed unexpectedly!" )
def test_property_ip_address(self): entry = ServerHistoryFactory(server=StaticServerFactory( ip_address="192.168.1.100")) try: self.assertEqual(entry.ip_address, "192.168.1.100") entry.server.ip_address = "192.168.2.200" entry.server.save() self.assertEqual(entry.ip_address, "192.168.2.200") except Exception: self.fail( "ServerHistory model `ip_address` property failed unexpectedly!" )
def setUpTestData(cls): cls.ProjectObjective = ProjectObjectiveFactory._meta.model cls.project = ProjectFactory() for x in range(3): ProjectObjectiveFactory(project=cls.project) cls.server = StaticServerFactory() cls.aux_address_1 = AuxServerAddressFactory( static_server=cls.server, ip_address="1.1.1.1", primary=True ) cls.aux_address_2 = AuxServerAddressFactory( static_server=cls.server, ip_address="1.1.1.2", primary=False ) cls.scope = ProjectScopeFactory( project=cls.project, scope="1.1.1.1\r\n1.1.1.2\r\n1.1.1.3\r\n1.1.1.4\r\n1.1.1.5", )
def test_crud(self): # Create entry = ServerHistoryFactory(server=StaticServerFactory( name="teamserver.local")) # Read self.assertEqual(entry.server.name, "teamserver.local") self.assertEqual(entry.pk, entry.id) self.assertQuerysetEqual( self.ServerHistory.objects.all(), [ f"<ServerHistory: {entry.server.ip_address} ({entry.server.name}) [{entry.activity_type}]>" ], ) # Update entry.end_date = date.today() entry.save() self.assertEqual(entry.end_date, date.today()) # Delete entry.delete() assert not self.ServerHistory.objects.all().exists()
def test_crud(self): # Create server = StaticServerFactory(ip_address="192.168.1.100") # Read self.assertEqual(server.ip_address, "192.168.1.100") self.assertEqual(server.pk, server.id) self.assertQuerysetEqual( self.StaticServer.objects.all(), [ f"<StaticServer: {server.ip_address} ({server.name}) [{server.server_provider}]>" ], ) # Update server.ip_address = "192.168.2.200" server.save() self.assertEqual(server.ip_address, "192.168.2.200") # Delete server.delete() assert not self.StaticServer.objects.all().exists()
def test_delete_signal(self): server = StaticServerFactory(server_status=self.unavailable_status) today = date.today() tomorrow = today + timedelta(days=1) next_week = today + timedelta(days=7) two_weeks = today + timedelta(days=14) history_1 = ServerHistoryFactory(start_date=today, end_date=tomorrow, server=server) history_2 = ServerHistoryFactory(start_date=next_week, end_date=two_weeks, server=server) # Deleting this older checkout should not impact the server's status history_1.delete() server.refresh_from_db() self.assertTrue(server.server_status == self.unavailable_status) # Deleting this newer checkout should impact the server's status history_2.delete() server.refresh_from_db() self.assertTrue(server.server_status == self.available_status)
def setUpTestData(cls): cls.server = StaticServerFactory() cls.server_dict = cls.server.__dict__
def test_get_absolute_url(self): server = StaticServerFactory() try: server.get_absolute_url() except: self.fail("StaticServer.get_absolute_url() raised an exception")