def test_validation_OK(): A, B, subject, obj, predicate = _generate_message_params() msg = Message(sender=A, receiver=B, subject=subject, obj=obj, predicate=predicate) assert msg.is_valid()
def test_validation_invalid_predicate(): A, B, subject, obj, predicate = _generate_message_params() for x in _generate_invalid_uri_list(): predicate = x msg = Message(sender=A, receiver=B, subject=subject, obj=obj, predicate=predicate) assert not msg.is_valid()
def post_message(self, msg): # pragma: no cover # Warning: seems not to be used anywhere except the tests # need to convert from domain message to PG message sender = str(msg.sender) receiver = str(msg.receiver) subject = str(msg.subject) obj = str(msg.obj) predicate = str(msg.predicate) m = Message(sender=sender, receiver=receiver, subject=subject, obj=obj, predicate=predicate, status='pending', sender_ref=msg.sender_ref) print(m) # TODO: figure out the path # path = m.path() # TODO: ensure the path exists # TODO: serialise the message and save it in the path # TODO: return some int # (is returning an int really a smart API? # why not a string) # print(self.client.list_buckets()) return len(self.client.list_buckets())
def test_serialise_message(): tx = "AU" rx = "CN" s = str(uuid.uuid4()) t = str(uuid.uuid4()) p = str(uuid.uuid4()) msg = Message(sender=Country(tx), receiver=Country(rx), subject=URI(s), obj=URI(t), predicate=URI(p)) expected_json = """ {{ "sender": "{}", "receiver": "{}", "subject": "{}", "obj": "{}", "predicate": "{}" }} """.format(tx, rx, s, t, p) msg_json = json.dumps(msg, cls=MessageJSONEncoder) assert json.loads(msg_json) == json.loads(expected_json)
def test_repository_post_returns_truithy( docker_setup, elasticmq_client): repo = REPO_CLASS(docker_setup['elasticmq']) msg_dict = test_generic_message._generate_msg_dict() msg = Message.from_dict(msg_dict) assert repo.post(msg)
def test_elasticmq_post_after_clear(docker_setup): repo = REPO_CLASS(docker_setup['elasticmq']) for i in range(5): message = Message.from_dict(test_generic_message._generate_msg_dict()) repo._unsafe_method__clear() assert repo.post(message) assert repo.get()
def test_elasticmq_post_creates_a_message( docker_setup, elasticmq_client): repo = REPO_CLASS(docker_setup['elasticmq']) msg_dict = test_generic_message._generate_msg_dict() msg = Message.from_dict(msg_dict) elasticmq_client.purge_queue(QueueUrl=repo.queue_url) assert not repo.get() assert repo.post(msg) assert repo.get()
def test_elasticmq_get_returns_a_message_and_id( docker_setup, elasticmq_client): repo = REPO_CLASS(docker_setup['elasticmq']) msg_dict = test_generic_message._generate_msg_dict() msg = Message.from_dict(msg_dict) elasticmq_client.purge_queue(QueueUrl=repo.queue_url) assert repo.post(msg) msg_id, msg = repo.get() assert isinstance(msg, Message)
def test_elasticmq_delete_actually_does( docker_setup, elasticmq_client): repo = REPO_CLASS(docker_setup['elasticmq']) msg_dict = test_generic_message._generate_msg_dict() msg = Message.from_dict(msg_dict) elasticmq_client.purge_queue(QueueUrl=repo.queue_url) assert repo.post(msg) msg_id, msg = repo.get() assert repo.delete(msg_id) assert not repo.get()
def _create_message_object(self, data): try: return Message(sender=data["sender"], receiver=data["receiver"], subject=data["subject"], obj=data["obj"], predicate=data["predicate"], sender_ref=data.get('sender_ref'), status=data.get('status')) except Exception: logger.error("Unable to deserealize data %s to Message object", data) raise
def test_message_from_dict(): adict = _generate_msg_dict() msg = Message.from_dict(adict) assert msg.is_valid()
def _generate_msg_object(**kwargs): return Message.from_dict(_generate_msg_dict(**kwargs))
def test_validation_bogus_parameter(): A, B, subject, obj, predicate = _generate_message_params() msg = Message(bogus=True, sender=A, receiver=B, subject=subject, obj=obj) assert not msg.is_valid()
def test_validation_invalid_no_reciever(): A, B, subject, obj, predicate = _generate_message_params() msg = Message(sender=A, subject=subject, obj=obj, predicate=predicate) assert not msg.is_valid()
def test_message_comparison(): adict = _generate_msg_dict() m1 = Message.from_dict(adict) m2 = Message.from_dict(adict) assert m1 == m2
def test_message_to_dict(): adict = _generate_msg_dict() msg = Message.from_dict(adict) assert msg.to_dict() == adict