Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Message Consumer Example #430

Closed
4 tasks done
JP-Ellis opened this issue Oct 24, 2023 · 0 comments · Fixed by #448
Closed
4 tasks done

Fix Message Consumer Example #430

JP-Ellis opened this issue Oct 24, 2023 · 0 comments · Fixed by #448
Assignees
Labels
area:examples Relating to the examples difficulty:easy A simple task appropriate for newcomers to the codebase good first issue Good for newcomers type:bug Something isn't working

Comments

@JP-Ellis
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of pact-python.
  • I have read the console error message carefully (if applicable).

Description

The current master branch has a bug in one of the examples. See for example the result of this job done against ab02630.

Reproducible demo

No response

Steps to reproduce

See master branch

Expected behavior

Test should succeed

Actual behavior

=================================== FAILURES ===================================
_______________________________ test_write_file ________________________________

pact = <pact.message_pact.MessagePact object at 0x7f595b22ba90>
handler = <examples.src.message.Handler object at 0x7f595b2290d0>

    def test_write_file(pact: MessagePact, handler: Handler) -> None:
        """
        Test write file.
    
        This test will be run against the mock provider. The mock provider will
        expect to receive a request to write a file, and will respond with a 200
        status code.
        """
        msg = {"action": "WRITE", "path": "test.txt", "contents": "Hello world!"}
        (
            pact.given("a request to write test.txt")
            .expects_to_receive("empty filesystem")
            .with_content(msg)
            .with_metadata({"Content-Type": "application/json"})
        )
    
>       result = handler.process(msg)

examples/tests/test_02_message_consumer.py:119: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <examples.src.message.Handler object at 0x7f[59](https://github.com/pact-foundation/pact-python/actions/runs/6619870924/job/17981208903#step:7:60)5b2290d0>
event = {'action': 'WRITE', 'contents': 'Hello world!', 'path': 'test.txt'}

    def process(self, event: Dict[str, Any]) -> Union[str, None]:
        """
        Process an event from the queue.
    
        The event is expected to be a dictionary with the following mandatory
        keys:
    
        - `action`: The action to be performed, either `READ` or `WRITE`.
        - `path`: The path to the file to be read or written.
    
        The event may also contain an optional `contents` key, which is the
        contents to be written to the file. If the `contents` key is not
        present, an empty file will be written.
        """
        self.validate_event(event)
    
        if event["action"] == "WRITE":
            self.fs.write(event["path"], event.get("contents", ""))
        if event["action"] == "READ":
            return self.fs.read(event["path"])
    
        msg = "Invalid action."
>       raise ValueError(msg)
E       ValueError: Invalid action.

examples/src/message.py:[68](https://github.com/pact-foundation/pact-python/actions/runs/6619870924/job/17981208903#step:7:69): ValueError

Your environment

Pact Python CI

Self-service

  • I'd be willing to fix this bug myself.
@JP-Ellis JP-Ellis added type:bug Something isn't working status:triage An item which has been recently created and needs to be triaged labels Oct 24, 2023
@JP-Ellis JP-Ellis self-assigned this Oct 24, 2023
@JP-Ellis JP-Ellis removed the status:triage An item which has been recently created and needs to be triaged label Oct 24, 2023
@JP-Ellis JP-Ellis moved this to 🚀 To-Do in Pact Python Oct 24, 2023
@JP-Ellis JP-Ellis added good first issue Good for newcomers difficulty:easy A simple task appropriate for newcomers to the codebase area:examples Relating to the examples labels Oct 25, 2023
@JP-Ellis JP-Ellis moved this from 🚀 To-Do to 👀 In Review in Pact Python Oct 31, 2023
@github-project-automation github-project-automation bot moved this from 👀 In Review to ✅ Completed in Pact Python Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:examples Relating to the examples difficulty:easy A simple task appropriate for newcomers to the codebase good first issue Good for newcomers type:bug Something isn't working
Projects
Status: ✅ Completed
Development

Successfully merging a pull request may close this issue.

1 participant