예제 #1
0
def test_v2():
    pact = Consumer('consumer').has_pact_with(Provider('provider'),
                                              version='2.0.0')
    pact.given("the condition exists").upon_receiving("a request").with_request("GET", "/path") \
        .will_respond_with(200, body='ok')

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        'consumer': {
            'name': 'consumer'
        },
        'provider': {
            'name': 'provider'
        },
        'interactions': [{
            'description': 'a request',
            'providerState': 'the condition exists',
            'request': dict(method='GET', path='/path'),
            'response': dict(status=200, body='ok'),
        }],
        'metadata':
        dict(pactSpecification=dict(version='2.0.0'))
    }
예제 #2
0
def test_full_payload_v2():
    pact = Consumer('consumer').has_pact_with(Provider('provider'), version='2.0.0')
    (pact
        .given('UserA exists and is not an administrator')
        .upon_receiving('a request for UserA')
        .with_request('get', '/users/UserA', headers={'Accept': 'application/json'}, query='term=test')
        .will_respond_with(200, body={'username': '******'}, headers={'Content-Type': 'application/json'}))
    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        'consumer': {'name': 'consumer'},
        'provider': {'name': 'provider'},
        'interactions': [
            {
                'description': 'a request for UserA',
                'providerState': 'UserA exists and is not an administrator',
                'request': dict(method='get', path='/users/UserA', headers={'Accept': 'application/json'},
                                query='term=test'),
                'response': dict(status=200, body={'username': '******'},
                                 headers={'Content-Type': 'application/json'})
            }
        ],
        'metadata': dict(pactSpecification=dict(version='2.0.0'))
    }
예제 #3
0
def test_v2():
    pact = Consumer("consumer").has_pact_with(Provider("provider"),
                                              version="2.0.0")
    pact.given("the condition exists").upon_receiving(
        "a request").with_request("GET", "/path").will_respond_with(200,
                                                                    body="ok")

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        "consumer": {
            "name": "consumer"
        },
        "provider": {
            "name": "provider"
        },
        "interactions": [{
            "description": "a request",
            "providerState": "the condition exists",
            "request": dict(method="GET", path="/path"),
            "response": dict(status=200, body="ok"),
        }],
        "metadata":
        dict(pactSpecification=dict(version="2.0.0")),
    }
예제 #4
0
from RDS import Token, OAuth2Token, User, LoginService, OAuth2Service, Util


def create_app():
    from src import bootstrap

    # creates a test client
    app = bootstrap(use_default_error=True, testing=True).app

    return app


pact_host_port = 3000
pact_host_fqdn = f"http://localhost:{pact_host_port}"
pact = Consumer("CentralServiceTokenStorage").has_pact_with(
    Provider("OAuth-Provider"), port=pact_host_port)


class TestTokenStorageServer(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client()

        self.empty_storage = Storage()

        self.success = {"success": True}

        self.user1 = User("Max Mustermann")
        self.user2 = User("Mimi Mimikri")
        self.user3 = User("Karla Kolumda")
예제 #5
0
def test_v2_not_allowed():
    with pytest.raises(Equals.NotAllowed):
        Consumer('C').has_pact_with(Provider('P'), version='2.0.0') \
            .given("g").upon_receiving("r").with_request("post", "/foo", body=Equals("bee")) \
            .will_respond_with(200)
예제 #6
0
import unittest
from lib.Service import Service
from pactman import Consumer, Provider
import json
from RDS import FileTransferArchive, FileTransferMode

pact = Consumer("ServiceExporter").has_pact_with(Provider("Zenodo"), port=3000)
testingaddress = "http://localhost:3000"


class Test_Service(unittest.TestCase):
    @staticmethod
    def requestStorageFolderGET(pact, folderpath: str, userId: str, files: list):
        pact.given(
            f"user {userId} has {len(files)} files in folderpath {folderpath}"
        ).upon_receiving(
            "the filepaths for files in folder with folderpath"
        ).with_request(
            "GET", f"/storage/folder"
        ).will_respond_with(
            200, body={"files": files}
        )

    @staticmethod
    def requestStorageFileGET(
        pact, filepath: str, userId: str, fileContent: str, code=200
    ):
        pact.given(f"user {userId} has a file in filepath {filepath}").upon_receiving(
            "the filecontent of the given filepath"
        ).with_request("GET", f"/storage/file").will_respond_with(
            code, body=fileContent
예제 #7
0
api_key = os.getenv("ZENODO_API_KEY", default=None)


def create_app():
    from src import bootstrap

    # creates a test client
    app = bootstrap(use_default_error=True,
                    address="http://localhost:3000").app
    # propagate the exceptions to the test client
    app.config.update({"TESTING": True})

    return app


pact = Consumer("PortZenodo").has_pact_with(Provider("Zenodo"), port=3000)

unittest.TestCase.maxDiff = None


class TestPortZenodo(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client()

    @classmethod
    def tearDownClass(cls):
        pass

    def tearDown(self):
        pass
예제 #8
0
from .test_service import Test_Service


def create_app():
    testing_address = "http://localhost:3000"

    from src import bootstrap
    # creates a test client
    app = bootstrap(use_default_error=True).app
    # propagate the exceptions to the test client
    app.config.update({"TESTING": testing_address})

    return app


pact = Consumer('ServiceExporter').has_pact_with(Provider('Zenodo'), port=3000)

unittest.TestCase.maxDiff = None


class TestServiceExporter(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client()

    def test_files(self):
        userId = "admin"
        researchIndex = 1

        userId = "admin"
        researchIndex = 1
예제 #9
0
import atexit
import pytest
import requests
from pactman import Consumer, Provider

#from pact import Consumer, Provider
 
#pact = Consumer('buildReader').has_pact_with(Provider('bringon'))

#pact.start_service()
#atexit.register(pact.stop_service)

pact = Consumer('Consumer').has_pact_with(Provider('Provider'), version='3.0.0')

def test_interaction():
    pact.given("some data exists").upon_receiving("a request") \
        .with_request("get", "/", query={"foo": ["bar"]}).will_respond_with(200)
    with pact:
        requests.get(pact.uri, params={"foo": ["bar"]})

def test_server_is_up():
    pact.given("The Server is online").upon_receiving("a request") \
        .with_request("get", "/", headers={'Content-Type': 'application/json'}) \
            .will_respond_with(200, body= 'Server Works!', headers={'Content-Type': 'application/json'})
    with pact:
        r = requests.get(pact.uri, headers={'Content-Type': 'application/json'})
        print (r.text)
    
예제 #10
0
from lib.Research import Research
from pactman import Consumer, Provider
import unittest

pact = Consumer('UseCaseMetadataResearch').has_pact_with(
    Provider('PortMetadata'), port=3000)

testing_address = "localhost:3000"


class Test_Research(unittest.TestCase):
    def test_research_init_researchId(self):
        userId = 0
        researchIndex = 0
        researchId = 1

        ports = [
            # no entries
            [],
            # one entry
            [{
                "port": "port-zenodo",
                "properties": [{
                    "portType": "metadata",
                    "value": True
                }]
            }],
            # two entries
            [{
                "port": "port-zenodo",
                "properties": [{
예제 #11
0
import unittest
from lib.ownCloudUser import OwncloudUser
from pactman import Consumer, Provider
from urllib.parse import quote
import atexit

pact_host_port = 3000
pact_host_fqdn = f"http://*****:*****@unittest.skip("This does not work currently")
    def test_getSimpleFile(self):
        expected_user = "******"
예제 #12
0
    return node

project_node = _build_node("nodes")

def create_app():
    from src import bootstrap

    # creates a test client
    app = bootstrap(use_default_error=True, address="http://*****:*****@unittest.skip("not implemented")
    def test_project_index(self):
        pass
예제 #13
0
from lib.Metadata import Metadata
from pactman import Consumer, Provider
import unittest
import json
from RDS import OAuth2Service, OAuth2Token, User, Util

pact = Consumer('UseCaseMetadata').has_pact_with(Provider('PortMetadata'),
                                                 port=3000)

testing_address = "localhost:3000"

unittest.TestCase.maxDiff = None

Util.monkeypatch()


class Test_Metadata(unittest.TestCase):
    def setUp(self):
        self.user1 = User("MaxMustermann")
        self.service1 = OAuth2Service(
            servicename="TestService",
            implements=["metadata"],
            authorize_url="http://localhost/oauth/authorize",
            refresh_url="http://localhost/oauth/token",
            client_id="MNO",
            client_secret="UVW")
        self.token1 = OAuth2Token(self.user1, self.service1, "ABC", "X_ABC")

    def test_metadata_init(self):
        """
        This unit tests the metadata object constructor.
예제 #14
0
    app = bootstrap(
        use_optimizer={
            "compress": False,
            "minify": False
        },
        use_default_error=True,
        testing=address,
    ).app
    # propagate the exceptions to the test client
    app.config.update({"TESTING": True})

    return app


pact = Consumer("UseCaseTokenStorage").has_pact_with(
    Provider("CentralServiceTokenStorage"), port=3000)


class Test_TokenServiceServer(unittest.TestCase):
    def run(self, result=None):
        # this make pact as context in every test available.
        with pact as p:
            super(Test_TokenServiceServer, self).run(result)

    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client()

    def test_redirect(self):
        code = "XYZABC"
        user = User("user")
예제 #15
0
import unittest
from lib.ExporterService import ExporterService
from pactman import Consumer, Provider


def create_app():
    from src import bootstrap
    # creates a test client
    app = bootstrap(use_default_error=True).app
    # propagate the exceptions to the test client
    app.config.update({"TESTING": True, "TESTSERVER": "http://localhost:3000"})

    return app


pact = Consumer('PortZenodo').has_pact_with(Provider('Zenodo'), port=3000)


class Test_ExporterService(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client()

    @unittest.skip
    def test_export_zenodo_from_owncloud_working(self):
        exporter = ExporterService(
            testing=True, testing_address=self.app.config.get("TESTSERVER"))

        # call to get file from owncloud
        pact.given('file and userid are valid').upon_receiving(
            'the wanted file content').with_request(
예제 #16
0
import atexit
import unittest

import requests
from pactman import Consumer, Provider, Term, Like
from pactman.verifier.pytest_plugin import pact_verifier

pact = Consumer('Consumer').has_pact_with(
    Provider('Provider'),
    file_write_mode="override",
    use_mocking_server=False,
    pact_dir="C:\\Users\\abdulsha\\PycharmProjects\\pact-python-master\\Pacts")

# pact.start_mocking()
# atexit.register(pact.stop_mocking)


class Generate_POC_PACTS(unittest.TestCase):
    def test_generate_pact_from_consumer_end(self):
        # Setting up Expected Response
        expected = {'skip': 0, 'limit': 150}

        pact.given('A Support User exists and is not an administrator'
                   ).upon_receiving('a request for API support').with_request(
                       method='GET',
                       path='/api',
                   ).will_respond_with(200, body=expected)

        # When a request is hit to Server, would it retrieve the expected data
        with pact:
            result = requests.get(pact.uri + '/api')
예제 #17
0
import atexit
import unittest
from pactman import Consumer, Provider, Like
from movies_api.main import get_duration, post_duration

pact = Consumer('movies-api').has_pact_with(Provider('duration-provider'),
                                            port=9000,
                                            log_dir='./movies_api/logs',
                                            pact_dir='./movies_api/pacts')
pact.start_service()
atexit.register(pact.stop_service)


class DurationContract(unittest.TestCase):
    def test_get_duration(self):
        expected = {
            "id": 42,
            "duration_min": 192,
        }
        expected_pact = Like(expected)

        pact.given('Given a movie exists').upon_receiving(
            'a request for movies-api').with_request(
                'GET', '/duration/42').will_respond_with(200,
                                                         body=expected_pact)

        with pact:
            result = get_duration(42)

        self.assertEqual(result, expected)