def test_encode_valid_registration_request(self): ''' Test the encoding of a valid registration request. ''' username = '******' hostname = 'bar' request = requests.RegistrationRequest(hostname, username) command = parser.encode(request) # Expected output similar to: # requesttypeid=1;hostname=bar;username=foo! self.assertTrue(command.endswith(packets.TERMINATOR)) self.assertEqual(1, command.count(packets.TERMINATOR)) self.assertEqual(2, command.count(packets.COMMAND_SEPARATOR)) self.assertEqual(3, command.count(packets.FIELD_SEPARATOR)) self.assertEqual(1, command.count('{0}={1}'. format(fields.REQUEST_TYPE_ID, request_types.REGISTER))) self.assertEqual(1, command.count('{0}={1}'. format(fields.HOSTNAME, hostname))) self.assertEqual(1, command.count('{0}={1}'. format(fields.USERNAME, username)))
def _encode_valid_status_request_status(self, status): ''' Helper. :param status: True if server or client is up ''' request = requests.StatusRequest(status) command = parser.encode(request) # Expected output similar to: self.assertTrue(command.endswith(packets.TERMINATOR)) self.assertEqual(1, command.count(packets.TERMINATOR)) self.assertEqual(1, command.count(packets.COMMAND_SEPARATOR)) self.assertEqual(2, command.count(packets.FIELD_SEPARATOR)) self.assertEqual(1, command.count('{0}={1}'. format(fields.REQUEST_TYPE_ID, request_types.SERVER_STATUS))) self.assertEqual(1, command.count('{0}={1}'. format(fields.SERVER_STATUS, int(status))))