def test_make_message_missing_fields(self): """ The correct fields must all exist in the provided data dictionary. """ with self.assertRaises(ValueError) as cm: make_message(OK, {'foo': 1, 'bar': 2}) ex = cm.exception details = ex.args[0] self.assertEqual(6, len(details)) self.assertEqual('Missing field.', details['uuid']) self.assertEqual('Missing field.', details['recipient']) self.assertEqual('Missing field.', details['sender']) self.assertEqual('Missing field.', details['reply_port']) self.assertEqual('Missing field.', details['version']) self.assertEqual('Missing field.', details['seal'])
def test_make_message_bad_values(self): """ The values to be used to instantiate the class should be valid. If not the correct exception is raised. """ with self.assertRaises(ValueError) as cm: make_message(OK, {'uuid': 1, 'recipient': 2, 'sender': 3, 'reply_port': '1908', 'version': 4, 'seal': 5}) ex = cm.exception details = ex.args[0] self.assertEqual(6, len(details)) self.assertEqual('Invalid value.', details['uuid']) self.assertEqual('Invalid value.', details['recipient']) self.assertEqual('Invalid value.', details['sender']) self.assertEqual('Invalid value.', details['reply_port']) self.assertEqual('Invalid value.', details['version']) self.assertEqual('Invalid value.', details['seal'])
def test_make_message(self): """ The good case returns an instance of the given class based upon the data provided. """ uuid = str(uuid4()) node = PUBLIC_KEY reply_port = 1908 version = get_version() result = make_message(OK, {'uuid': uuid, 'recipient': node, 'sender': node, 'reply_port': reply_port, 'version': version, 'seal': 'fakeseal'}) self.assertIsInstance(result, OK) self.assertEqual(uuid, result.uuid) self.assertEqual(node, result.recipient) self.assertEqual(node, result.sender) self.assertEqual(reply_port, result.reply_port) self.assertEqual(version, result.version) self.assertEqual('fakeseal', result.seal)