Пример #1
0
    def test_timezone_inheritance(self):
        parent = Organization(id=101, name='parentOrg')
        org = Organization(id=102, name='org', partOf_id=101)

        # test that with no timezones set, defaults to UTC
        with SessionScope(db):
            db.session.add(parent)
            db.session.add(org)
            db.session.commit()
        parent, org = map(db.session.merge, (parent, org))
        assert org.timezone == 'UTC'

        # test that timezone-less child org inherits from parent
        parent.timezone = 'Asia/Tokyo'
        with SessionScope(db):
            db.session.add(parent)
            db.session.commit()
        parent, org = map(db.session.merge, (parent, org))
        assert org.timezone == 'Asia/Tokyo'

        # test that child org with timezone does NOT inherit from parent
        org.timezone = 'Europe/Rome'
        with SessionScope(db):
            db.session.add(org)
            db.session.commit()
        org = db.session.merge(org)
        assert org.timezone == 'Europe/Rome'
    def test_timezone_inheritance(self):
        parent = Organization(id=101, name='parentOrg')
        org = Organization(id=102, name='org', partOf_id=101)

        # test that with no timezones set, defaults to UTC
        with SessionScope(db):
            db.session.add(parent)
            db.session.add(org)
            db.session.commit()
        parent, org = map(db.session.merge, (parent, org))
        assert org.timezone == 'UTC'

        # test that timezone-less child org inherits from parent
        parent.timezone = 'Asia/Tokyo'
        with SessionScope(db):
            db.session.add(parent)
            db.session.commit()
        parent, org = map(db.session.merge, (parent, org))
        assert org.timezone == 'Asia/Tokyo'

        # test that child org with timezone does NOT inherit from parent
        org.timezone = 'Europe/Rome'
        with SessionScope(db):
            db.session.add(org)
            db.session.commit()
        org = db.session.merge(org)
        assert org.timezone == 'Europe/Rome'
    def test_delete_extension(self):
        org = Organization(name='testy')
        org.timezone = 'Asia/Tokyo'  # stored in an extension
        with SessionScope(db):
            db.session.add(org)
            db.session.commit()
        org = db.session.merge(org)
        mp = ModelPersistence(
            Organization, lookup_field='id',
            sequence_name='organizations_id_seq',
            target_dir=self.tmpdir)
        mp.export()

        # Strip the empty extensions, as expected in the real persistence file
        with open(
                os.path.join(self.tmpdir, 'Organization.json'), 'r') as pfile:
            data = json.load(pfile)
            # Special handling of extensions - empties only have 'url' key

        for i, entry in enumerate(data['entry']):
            extensions = entry['extension']
            keepers = []
            for e in extensions:
                if len(e.keys()) > 1:
                    keepers.append(e)
            data['entry'][i]['extension'] = keepers
            empty_keys = [k for k, v in entry.items() if not v]
            for k in empty_keys:
                del data['entry'][i][k]

        with open(
                os.path.join(self.tmpdir, 'Organization.json'), 'w') as pfile:
            pfile.write(json.dumps(data))

        # Add an additional extension to the org, make sure
        # they are deleted when importing again from
        # persistence that doesn't include them

        org.locales.append(LocaleConstants().AmericanEnglish)
        with SessionScope(db):
            db.session.commit()
        org = db.session.merge(org)
        assert len(org.as_fhir()['extension']) > 1

        mp.import_(keep_unmentioned=False)
        org = Organization.query.filter(Organization.name == 'testy').one()
        assert org.locales.count() == 0
        assert org.timezone == 'Asia/Tokyo'