Skip to content

Commit

Permalink
fix: x-plat mime type detection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Aug 7, 2023
1 parent 1b319b1 commit 00b1843
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ env:
USE_STANDALONE: 1

PYTHON_VERSION_MATRIX: &PYTHON_VERSION_MATRIX
- VERSION: 3.11
# - VERSION: 3.6
# - VERSION: 3.7
# - VERSION: 3.8
# - VERSION: 3.9
# - VERSION: 3.10
- VERSION: 3.11

linux_arm64_task:
only_if: $CIRRUS_CHANGE_TITLE !=~ 'ci\(gha\).*'
Expand All @@ -48,7 +48,7 @@ macos_arm64_task:
<<: *PYTHON_VERSION_MATRIX
install_script:
- brew update
- brew install pyenv protobuf # protobuf only needed if using grpc plugins
- brew install pyenv protobuf shared-mime-info # protobuf only needed if using grpc plugins
- pyenv install ${VERSION}
- pyenv global ${VERSION}
- pyenv rehash
Expand Down
8 changes: 6 additions & 2 deletions examples/todo/src/todo_consumer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
import requests
import xml.etree.ElementTree as ET

import platform
target_platform = platform.platform().lower()
mime_type = 'image/jpeg' if ('macos' or 'linux' in target_platform) and (os.getenv("ACT")
== "true" or os.getenv("GITHUB_ACTIONS") == "true") else 'application/octet-stream'

class TodoConsumer(object):
def __init__(self, base_uri):
Expand Down Expand Up @@ -28,5 +32,5 @@ def post_image(self, id, file_path):
print(id)
print(file_path)
uri = self.base_uri + '/projects/' + str(id) + '/images'
response = requests.post(uri, data=open(file_path, 'rb'), headers={'Content-Type': 'image/jpeg'})
response = requests.post(uri, data=open(file_path, 'rb'), headers={'Content-Type': mime_type})
response.raise_for_status()
13 changes: 9 additions & 4 deletions examples/todo/tests/test_todo_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
from pact.matchers_v3 import EachLike, Integer, Like, AtLeastOneLike
# from pact.matchers_v3 import EachLike, Integer, Like, DateTime, AtLeastOneLike
# import xml.etree.ElementTree as ET
import platform
target_platform = platform.platform().lower()


mime_type = 'image/jpeg' if ('macos' or 'linux' in target_platform) and (os.getenv("ACT")
== "true" or os.getenv("GITHUB_ACTIONS") == "true") else 'application/octet-stream'
@pytest.fixture
def provider():
return PactV3('TodoApp', 'TodoServiceV3')
Expand Down Expand Up @@ -117,14 +120,16 @@ def test_with_xml_requests(provider: PactV3):


def test_with_image_upload(provider: PactV3):
print("os.getenv(ACT)")
print(os.getenv("ACT"))
print(target_platform)
print(mime_type)
binary_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'example.jpg'))
(provider
.new_http_interaction('same_as_upon_receiving').given('i have a project', {'id': 1001, 'name': 'Home Chores'})
.upon_receiving('a request to store an image against the project')
.with_request_with_binary_file(
# headers=[{"name": 'content-type', "value": "application/octet-stream"}],
# headers=[{"name": 'content-type', "value": "application/octet-stream"}],
headers=[{"name": 'content-type', "value": "image/jpeg"}],
headers=[{"name": 'content-type', "value": mime_type}],
file=binary_file_path,
path="/projects/1001/images")
.will_respond_with(status=201))
Expand Down
17 changes: 10 additions & 7 deletions examples/todo/tests/test_todo_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
from pact import VerifierV3
from flask import url_for
import platform

target_platform = platform.platform().lower()

@pytest.mark.skipif(
'windows' in target_platform,
reason="https://github.com/jarus/flask-testing/issues/44")
@pytest.fixture(scope='session')
def app():
if 'macos' in target_platform:
multiprocessing.set_start_method("fork") # Issue on MacOS - https://github.com/pytest-dev/pytest-flask/issues/104
if 'windows' in target_platform:
pass
# Also an issue on windows - using fork or using spawn
# see https://github.com/jarus/flask-testing/issues/44
# and https://github.com/uqfoundation/dill/issues/245
return create_app()


@pytest.mark.skipif(
'windows' in target_platform,
reason="https://github.com/jarus/flask-testing/issues/44")
@pytest.mark.usefixtures('live_server')
def test_pact_json():
verifier = VerifierV3(provider='TodoServiceV3',
Expand All @@ -31,6 +33,9 @@ def test_pact_json():
)
assert result == 0

@pytest.mark.skipif(
'windows' in target_platform,
reason="https://github.com/jarus/flask-testing/issues/44")
@pytest.mark.usefixtures('live_server')
def test_pact_image():
verifier = VerifierV3(provider='TodoServiceV3',
Expand All @@ -42,7 +47,7 @@ def test_pact_image():
assert result == 0

@pytest.mark.skipif(
True,
'windows' in target_platform,
reason="https://github.com/pact-foundation/pact-reference/issues/305")
@pytest.mark.usefixtures('live_server')
def test_pact_xml():
Expand All @@ -53,5 +58,3 @@ def test_pact_xml():
filter_description='a request for projects in XML',
)
assert result == 0
# TODO:- Ideally this should pass, but having issues with xml content types headers
# see https://github.com/pact-foundation/pact-reference/issues/305
Loading

0 comments on commit 00b1843

Please sign in to comment.