Hello, I have written a POC for Java Pactflow. One...
# general
r
Hello, I have written a POC for Java Pactflow. One service is sending a message to another service and I would like to compare the messages. I am trying to do the same in Python. Is that possible in Python? here is my Java code: My Consumer class:
Copy code
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "ProviderCDCT",
        providerType = ProviderType.ASYNCH,
        pactVersion = PactSpecVersion.V3)
public class ConsumerContractTest {

    @Pact(consumer = "ConsumerCDCT")
    public MessagePact createMyPact(MessagePactBuilder builder) {
        Map<String, String> metadata = new HashMap<>();
        metadata.put("content-type", "application/json");

        DslPart sqsBody = new PactDslJsonBody()
                .stringType("messageId", "1")
                .stringValue("receiptHandle", "testRadek")
                .stringType("eventSource", "aws:sqs")
                .stringType("awsRegion", "us-east-1")
                .object("messageAttributes")
                .closeObject();

        return builder
                .expectsToReceive("a message with information")
                .withMetadata(metadata)
                .withContent(sqsBody)
                .toPact();

    }

    //This method is needed to create the pact files.
    @Test
    @PactTestFor(pactMethod = "createMyPact")
    public void testMyMethod(List<Message> messages) {
    }
}
My Provider Class:
Copy code
@PactBroker(scheme = "https", host = "",
        authentication = @PactBrokerAuth(token = ""))
@Provider("ProviderCDCT")
@Consumer("ConsumerCDCT")
public class ProviderContractTest {
    private final ObjectMapper objectMapper = new ObjectMapper();

    @BeforeEach
    public void setUp(PactVerificationContext context) {
        context.setTarget(new MessageTestTarget(List.of("Provider")));
        System.setProperty("pact.verifier.publishResults",
                System.getenv("PACT_BROKER_PUBLISH_VERIFICATION_RESULTS") == null ? "true" : "true");
    }

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void testTemplate(PactVerificationContext context) {
        context.verifyInteraction();
    }

    @PactVerifyProvider("a message with information")
    public MessageAndMetadata providerMessage() throws Exception {
        Map<String, String> metadata = new HashMap<>();
        metadata.put("content-type", "application/json");

        Map<String, Object> mainMessage = new HashMap<>();
        mainMessage.put("messageId", "");
        mainMessage.put("receiptHandle", "testRadek");
        mainMessage.put("eventSource", "aws:sqs");
        mainMessage.put("awsRegion", "us-east-1");
        mainMessage.put("messageAttributes", new HashMap<>());

        return new MessageAndMetadata(objectMapper.writeValueAsBytes(mainMessage), metadata);
    }
}
m
hey there! Probably best asking in the language specific channel. Are you wanting to know how to do message pact with Python? Perhaps start with https://github.com/pact-foundation/pact-python/blob/master/examples/tests/test_02_message_consumer.py and https://github.com/pact-foundation/pact-python/blob/master/examples/tests/test_03_message_provider.py
See also #C9VECUP6E
🙌 1