Esempio n. 1
0
def setup_module():
    settings._reset()
    settings.configure(CONFIG)
    pymodm.connect(settings.PYMODM_CONFIG["URI"])

    # Clear the database
    if GENERATE_FIXTURES:
        server, db_name = settings.PYMODM_CONFIG["URI"].rsplit("/", 1)
        client = pymongo.MongoClient(server)
        client.drop_database(db_name)
        generate_examples(False)
    else:
        print("Skipping Fixtures")
Esempio n. 2
0
            if (ObjectId.is_valid(resource.id)):
                Item._id = resource.id
            Item.save()
            count += 1
            print(f'{count} / {total}  {cls_name}' + 20 * ' ', end='\r')
    print('Fixtures generated' + 20 * ' ')
    return examples


if __name__ == "__main__":
    import sys
    wait = sys.argv[-1] == '-w'
    import pymongo
    import pymodm
    from fhirbug.config import settings, import_models
    settings.configure('settings')
    server, db_name = settings.PYMODM_CONFIG["URI"].rsplit("/", 1)
    while True:
        try:
            client = pymongo.MongoClient(server)
            client.server_info()
        except pymongo.errors.ServerSelectionTimeoutError:
            if not wait:
                sys.exit(1)
        else:
            break
    pymodm.connect(settings.PYMODM_CONFIG["URI"])

    # Clear the database
    client.drop_database(db_name)
    generate_examples(False)
Esempio n. 3
0
import unittest
from unittest.mock import Mock, patch, call
from types import SimpleNamespace
from fhirbug.config import settings

if settings.is_configured():
    settings._reset()
settings.configure({
    "DB_BACKEND": "SQLAlchemy",
    "SQLALCHEMY_CONFIG": {
        "URI": "sqlite:///memory"
    }
})
from . import models
from fhirbug.constants import AUDIT_SUCCESS, AUDIT_MINOR_FAILURE
from fhirbug.Fhir.resources import Patient, Observation
from fhirbug.exceptions import (
    AuthorizationError,
    DoesNotExistError,
    MappingValidationError,
)
from fhirbug.models.mixins import (
    FhirAbstractBaseMixin,
    FhirBaseModelMixin,
    get_pagination_info,
)


class TestAbstractBaseMixin(unittest.TestCase):
    def test_get_resource_cls(self):
        cls = models.BaseMixinModel._get_resource_cls()
Esempio n. 4
0
import unittest
from types import SimpleNamespace
from unittest.mock import call, patch, Mock
from fhirbug.config import settings
from fhirbug.exceptions import UnsupportedOperationError, MappingValidationError, MappingException

settings._reset()
settings.configure({
    "DB_BACKEND": "SQLAlchemy",
    "SQLALCHEMY_CONFIG": {
        "URI": "sqlite:///memory"
    },
    'MODELS_PATH': 'tests.models'
})
from . import models


class TestAttributes(unittest.TestCase):
    def test_getter_string(self):
        """
        Getter can be a string representing the name of an attribute of _model
        """
        inst = models.AttributeWithStringGetter()

        self.assertEquals(inst.name, "my_name")

    def test_getter_setter_string(self):
        """
        Getter and setter can be a string representing the name of an attribute of _model
        """
        inst = models.AttributeWithStringGetterAndSetter()
Esempio n. 5
0
import sys
from pathlib import Path
import json
import dicttoxml
import flask
from flask import Flask, Response, render_template
import pymodm

try:
    from fhirbug.config import settings
    settings.configure("settings")
    from fhirbug.server import GetRequestHandler, PostRequestHandler, PutRequestHandler
except ModuleNotFoundError:
    # Allow execution from a git clone without having fhirball installed.
    if Path('./fhirbug').is_dir(): # Executed from the example's directory`
        sys.path.append("./")
    elif Path('../../fhirbug').is_dir(): # Executed from the project's root directory`
        sys.path.append("../../")
    from fhirbug.config import settings
    settings.configure("settings")
    from fhirbug.server import GetRequestHandler, PostRequestHandler, PutRequestHandler


pymodm.connect(settings.PYMODM_CONFIG["URI"])

app = Flask(__name__)
app.config.update(debug=settings.DEBUG)


@app.route("/r4/", defaults={"path": ""})
@app.route("/r4/<path:path>", methods=["GET", "POST", "PUT"])