コード例 #1
0
    def upsert_organization(self, organization_data):
        organization = (self.db.query(models.Organization).filter_by(
            pubid=organization_data["pubid"]).one_or_none())

        if not organization:
            organization = models.Organization()
            self.db.add(organization)

        self.setattrs(organization, organization_data)
コード例 #2
0
def test_repr(db_session, factories):
    organization = models.Organization(name='My Organization',
                                       authority='example.com')
    db_session.add(organization)
    db_session.flush()

    assert organization.id is not None
    assert organization.pubid is not None
    assert repr(organization) == "<Organization: my-organization>"
コード例 #3
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_init_sets_given_attributes():
    logo = """<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
            <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
            </svg>"""
    organization = models.Organization(name="My organization",
                                       logo=logo,
                                       authority="example.com")

    assert organization.name == "My organization"
    assert organization.logo == logo
    assert organization.authority == "example.com"
コード例 #4
0
def test_init_sets_given_attributes():
    logo = """<svg width="100" height="100">
            <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
            </svg>"""
    organization = models.Organization(
        name='My organization',
        logo=logo,
        authority='example.com',
    )

    assert organization.name == 'My organization'
    assert organization.logo == logo
    assert organization.authority == 'example.com'
コード例 #5
0
def test_group_organization(db_session):
    name = "My Hypothesis Group"

    org = models.Organization(name="My Organization", authority="foobar.com")
    db_session.add(org)
    db_session.flush()

    group = models.Group(name=name, authority="foobar.com", organization=org)
    db_session.add(group)
    db_session.flush()

    assert group.organization == org
    assert group.organization_id == org.id
コード例 #6
0
def _maybe_create_default_organization(engine, authority):
    from h import models

    session = Session(bind=engine)

    try:
        default_org = models.Organization.default(session)
    except exc.NoResultFound:
        default_org = None

    if default_org is None:
        default_org = models.Organization(name="Hypothesis",
                                          authority=authority,
                                          pubid="__default__")
        with open("h/static/images/icons/logo.svg", "rb") as h_logo:
            default_org.logo = h_logo.read().decode("utf-8")
        session.add(default_org)

    session.commit()
    session.close()

    return default_org
コード例 #7
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_is_default(pubid, is_default):
    organization = models.Organization(pubid=pubid)

    assert organization.is_default == is_default
コード例 #8
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_repr():
    organization = models.Organization(name="My Organization",
                                       authority="example.com",
                                       pubid="test_pubid")

    assert repr(organization) == "<Organization: test_pubid>"
コード例 #9
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_none_logo_is_valid():
    org = models.Organization(name="My Organization", logo=None)
    assert org.logo is None
コード例 #10
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_too_long_name_raises_value_error():
    with pytest.raises(ValueError):
        models.Organization(name="abcdefghijklmnopqrstuvwxyz")
コード例 #11
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_too_short_name_raises_value_error():
    with pytest.raises(ValueError):
        models.Organization(name="")
コード例 #12
0
def test_repr(db_session, factories):
    organization = models.Organization(name='My Organization',
                                       authority='example.com',
                                       pubid='test_pubid')

    assert repr(organization) == "<Organization: test_pubid>"
コード例 #13
0
def test_non_svg_logo_raises_value_error():
    with pytest.raises(ValueError):
        models.Organization(logo='<h>This is not a svg</h>')
コード例 #14
0
def test_malformed_logo_raises_value_error():
    with pytest.raises(ValueError):
        models.Organization(logo='<svg>/svg>')
コード例 #15
0
def test_too_long_logo_raises_value_error():
    with pytest.raises(ValueError):
        models.Organization(
            logo='<svg>{}</svg>'.format("abcdefghijklmnopqrstuvwxyz" * 400))
コード例 #16
0
ファイル: organization_test.py プロジェクト: kaydoh/h
def test_null_logo():
    organization = models.Organization(name="My Organization")

    assert organization.name == "My Organization"
    assert organization.logo is None
コード例 #17
0
def test_slug():
    organization = models.Organization(name="My Organization")

    assert organization.slug == 'my-organization'