def setUp(self): self.generator = SeqdiagGenerator()
class TestSeqdiagGenerator(TestCase): def setUp(self): self.generator = SeqdiagGenerator() def test_request_response(self): self.assertEquals(self.generator.generate(['Sender', 'Receiver'], [['Sender', 'Receiver', 'Protocol:Msg', '', 'received'], ['Receiver', 'Sender', 'Protocol:Msg', '', 'received']]), """diagram { Sender -> Receiver [label = "Protocol:Msg"]; Sender <- Receiver [label = "Protocol:Msg"]; } """) def test_failure(self): self.assertEquals(self.generator.generate(['Sender', 'Receiver'], [['Sender', 'Receiver', 'Protocol:Msg', 'This failed', 'received']]), """diagram { Sender -> Receiver [label = "Protocol:Msg - This failed", color = red]; } """) def test_several_operators(self): self.assertEquals(self.generator.generate(['Client', 'Server', 'DB'], [['Client', 'Server', 'Protocol:Req', '', 'received'], ['Server', 'Client', 'Protocol:Resp', '', 'received'], ['Client', 'DB', 'msg', '', 'received'], ['DB', 'Client', 'another', '', 'received'], ['Server', 'DB', 'HTTP:background', '', 'received'], ['DB', 'Server', 'HTTP:response', '', 'received']]), """diagram { Client -> Server [label = "Protocol:Req"]; Client <- Server [label = "Protocol:Resp"]; Client -> DB [label = "msg"]; Client <- DB [label = "another"]; Server -> DB [label = "HTTP:background"]; Server <- DB [label = "HTTP:response"]; } """) def test_cutoff_at_15_operations(self): self.assertEquals(self.generator.generate(['Client', 'Server', 'DB'], [['Client', 'Server', 'Protocol:Req', '', 'received'], ['Server', 'Client', 'Protocol:Resp', '', 'received'], ['Client', 'DB', 'msg', '', 'received'], ['DB', 'Client', 'another', '', 'received'], ['Server', 'DB', 'HTTP:background', '', 'received'], ['DB', 'Server', 'HTTP:response', '', 'received']] * 10), """diagram { Client <- DB [label = "another"]; Server -> DB [label = "HTTP:background"]; Server <- DB [label = "HTTP:response"]; Client -> Server [label = "Protocol:Req"]; Client <- Server [label = "Protocol:Resp"]; Client -> DB [label = "msg"]; Client <- DB [label = "another"]; Server -> DB [label = "HTTP:background"]; Server <- DB [label = "HTTP:response"]; Client -> Server [label = "Protocol:Req"]; Client <- Server [label = "Protocol:Resp"]; Client -> DB [label = "msg"]; Client <- DB [label = "another"]; Server -> DB [label = "HTTP:background"]; Server <- DB [label = "HTTP:response"]; } """)
class TestSeqdiagGenerator(TestCase): def setUp(self): self.generator = SeqdiagGenerator() def test_request_response(self): self.assertEquals( self.generator.generate( ['Sender', 'Receiver'], [['Sender', 'Receiver', 'Protocol:Msg', '', 'received'], ['Receiver', 'Sender', 'Protocol:Msg', '', 'received']]), """diagram { "Sender" -> "Receiver" [label = "Protocol:Msg"]; "Sender" <- "Receiver" [label = "Protocol:Msg"]; } """) def test_failure(self): self.assertEquals( self.generator.generate(['Sender', 'Receiver'], [[ 'Sender', 'Receiver', 'Protocol:Msg', 'This failed', 'received' ]]), """diagram { "Sender" -> "Receiver" [label = "Protocol:Msg - This failed", color = red]; } """) def test_several_operators(self): self.assertEquals( self.generator.generate( ['Client', 'Server', 'DB'], [['Client', 'Server', 'Protocol:Req', '', 'received'], ['Server', 'Client', 'Protocol:Resp', '', 'received'], ['Client', 'DB', 'msg', '', 'received'], ['DB', 'Client', 'another', '', 'received'], ['Server', 'DB', 'HTTP:background', '', 'received'], ['DB', 'Server', 'HTTP:response', '', 'received']]), """diagram { "Client" -> "Server" [label = "Protocol:Req"]; "Client" <- "Server" [label = "Protocol:Resp"]; "Client" -> "DB" [label = "msg"]; "Client" <- "DB" [label = "another"]; "Server" -> "DB" [label = "HTTP:background"]; "Server" <- "DB" [label = "HTTP:response"]; } """) def test_cutoff_at_15_operations(self): self.assertEquals( self.generator.generate( ['Client', 'Server', 'DB'], [['Client', 'Server', 'Protocol:Req', '', 'received'], ['Server', 'Client', 'Protocol:Resp', '', 'received'], ['Client', 'DB', 'msg', '', 'received'], ['DB', 'Client', 'another', '', 'received'], ['Server', 'DB', 'HTTP:background', '', 'received'], ['DB', 'Server', 'HTTP:response', '', 'received']] * 10), """diagram { "Client" <- "DB" [label = "another"]; "Server" -> "DB" [label = "HTTP:background"]; "Server" <- "DB" [label = "HTTP:response"]; "Client" -> "Server" [label = "Protocol:Req"]; "Client" <- "Server" [label = "Protocol:Resp"]; "Client" -> "DB" [label = "msg"]; "Client" <- "DB" [label = "another"]; "Server" -> "DB" [label = "HTTP:background"]; "Server" <- "DB" [label = "HTTP:response"]; "Client" -> "Server" [label = "Protocol:Req"]; "Client" <- "Server" [label = "Protocol:Resp"]; "Client" -> "DB" [label = "msg"]; "Client" <- "DB" [label = "another"]; "Server" -> "DB" [label = "HTTP:background"]; "Server" <- "DB" [label = "HTTP:response"]; } """)