Example #1
0
def illegalize(clients, url, **kwargs):
    """Append illegal/long arguments to an url and trigger a 400 response.

    Parameters
    ----------
    clients: dict
        Mapping from users to client fixtures
    kwargs: dict
        Additional parameters to illegalize.
        The url will be expanded by formatting it with the `kwargs` values.
    """

    kwargsx = {k: v + "a" * 200 for (k, v) in kwargs.items()}
    base = url.format(**kwargs)
    basex = url.format(**kwargsx)

    uxs = [
        base,
        basex,
        f"{base}?action=xxx",
        f"{base}?xxx=xxx",
        f"{base}?action=" + "a" * 200,
        f"{base}?" + "a" * 2000,
    ]

    passable = {200, 301, 302, 303}
    for (i, ux) in enumerate(uxs):
        expectx = {
            user: 400 if i > 2 or i == 1 and len(kwargsx) else passable
            for user in USERS
            if user in clients
        }
        serverprint(f"LEGAL URL ? ({ux})")
        forall(clients, expectx, assertStatus, ux)
Example #2
0
def test_reviewEntries(clients):
    recordId = startInfo["recordId"]

    cIds = recordId[CRITERIA_ENTRY]
    reviewId = G(recordId, REVIEW)
    rEid = G(reviewId, EXPERT)
    rFid = G(reviewId, FINAL)
    assert rEid is not None
    assert rFid is not None

    def assertIt(cl, exp):
        user = cl.user
        for crId in cIds:
            criteriaEntryInfo = getItem(cl, CRITERIA_ENTRY, crId)
            text = criteriaEntryInfo["text"]
            reviewEntries = findReviewEntries(text)
            if exp:
                if user in {EXPERT, FINAL}:
                    assert user in reviewEntries
                    assert COMMENTS in reviewEntries[user][1]
                    assert reviewEntries[user][1][COMMENTS] == E
                else:
                    assert EXPERT in reviewEntries
                    assert FINAL in reviewEntries

    expect = {user: False for user in USERS}
    expect.update({user: True for user in POWER_USERS | {EXPERT, FINAL}})
    forall(clients, expect, assertIt)
def test_modify(clients):
    valueTables = startInfo["valueTables"]
    recordId = startInfo["recordId"]

    users = valueTables[USER]
    eid = recordId[CONTRIB]
    aId = recordId[ASSESS]
    reviewId = recordId[REVIEW]
    rExpertId = reviewId[EXPERT]
    rFinalId = reviewId[FINAL]
    cIdFirst = recordId[CRITERIA_ENTRY][0]
    renId = getReviewEntryId(clients, cIdFirst, rExpertId, rFinalId)

    def assertIt(cl, exp):
        assertModifyField(cl, CONTRIB, eid, TITLE, TITLE2, exp)
        assertModifyField(cl, ASSESS, aId, TITLE, TITLE_A2, exp)
        reviewerFId = G(users, FINAL)
        assertModifyField(cl, ASSESS, aId, REVIEWER_E, (reviewerFId, FINAL),
                          exp)
        assertModifyField(cl, CRITERIA_ENTRY, cIdFirst, EVIDENCE,
                          ([EVIDENCE1], EVIDENCE1), exp)
        for (rId, remarks) in ((rExpertId, REMARKS_E), (rFinalId, REMARKS_F)):
            assertModifyField(cl, REVIEW, rId, REMARKS, ([remarks], remarks),
                              exp)
        for (u, reid) in renId.items():
            comments = COMMENTS_E if u == EXPERT else COMMENTS_F
            assertModifyField(cl, REVIEW_ENTRY, reid, COMMENTS,
                              ([comments], comments), exp)

    expect = {user: False for user in USERS}
    forall(clients, expect, assertIt)
Example #4
0
def assignReviewers(clients, users, aId, field, user, keep, expect):
    """Verify assigning reviewers to an assessment.

    A reviewer will be assigned to an assessment and immediately be unassigned.
    But the undo can be suppressed.

    Parameters
    ----------
    clients: dict
        Mapping from users to client fixtures
    users: dict
        Mapping of users to ids
    aId: string(ObjectId)
        Assessment id
    field: string
        Reviewer field (`reviewerE` or `reviewerF`)
    user: string
        The reviewer user
    keep: boolean
        If True, the assignment will not be undone
    expect: dict
        For each user a boolean saying whether that user can assign the reviewer
    """

    value = G(users, user)

    def assertIt(cl, exp):
        assertModifyField(cl, ASSESS, aId, field, (value, user), exp)
        if exp and not keep:
            assertModifyField(cl, ASSESS, aId, field, (None, UNDEF_VALUE), True)

    forall(clients, expect, assertIt)
def test_addDelAll(clients):
    def assertIt(cl, exp):
        eid = assertAddItem(cl, CONTRIB, exp)
        if exp:
            assertDelItem(cl, CONTRIB, eid, True)

    expect = {user: True for user in USERS}
    expect["public"] = False
    forall(clients, expect, assertIt)
def test_modifyUrl(clientsMy, field, value, expectVal):
    recordId = startInfo["recordId"]

    eid = G(recordId, CONTRIB)

    def assertIt(cl, exp):
        assertModifyField(cl, CONTRIB, eid, field, (value, expectVal), exp)

    expect = {user: True for user in {OWNER, EDITOR}}
    forall(clientsMy, expect, assertIt)
Example #7
0
def test_tryStartAll(clients, url):
    recordId = startInfo["recordId"]

    eid = G(recordId, CONTRIB)
    theUrl = url.format(eid=eid)

    def assertIt(cl, exp):
        assertStatus(cl, theUrl, exp)

    expect = {user: False for user in USERS}
    forall(clients, expect, assertIt)
Example #8
0
def test_inspectTypeAll(clients):
    recordId = startInfo["recordId"]

    aId = G(recordId, ASSESS)

    def assertIt(cl, exp):
        assertFieldValue((cl, ASSESS, aId), TYPEA, exp)

    expect = {user: None for user in USERS}
    expect.update({user: TYPE1 for user in RIGHTFUL_USERS})
    forall(clients, expect, assertIt)
Example #9
0
def test_modifyTypeAll(clients):
    recordId = startInfo["recordId"]
    ids = startInfo["ids"]

    aId = G(recordId, ASSESS)

    def assertIt(cl, exp):
        assertModifyField(cl, ASSESS, aId, TYPEA, (ids["TYPE2"], None), exp)

    expect = {user: False for user in USERS}
    forall(clients, expect, assertIt)
def test_modifyTitleAll(clients):
    recordId = startInfo["recordId"]
    eid = G(recordId, CONTRIB)

    def assertIt(cl, exp):
        assertModifyField(cl, CONTRIB, eid, TITLE, TITLE2, exp)
        if exp:
            assertModifyField(cl, CONTRIB, eid, TITLE, TITLE1, exp)

    expect = {user: False for user in USERS}
    expect.update(
        {user: True
         for user in {OWNER, EDITOR, OFFICE, SYSTEM, ROOT}})
    forall(clients, expect, assertIt)
def test_descriptionMarkdown(clientsMy, field, checks):
    recordId = startInfo["recordId"]

    eid = G(recordId, CONTRIB)

    def assertIt(cl, exp):
        response = cl.get(
            f"/api/{CONTRIB}/item/{eid}/field/{field}?action=view")
        text = response.get_data(as_text=True)
        for check in checks:
            assert check in text

    expect = {user: True for user in {OWNER, EDITOR}}
    forall(clientsMy, expect, assertIt)
Example #12
0
def test_startReview(clientsReviewer):
    recordId = startInfo["recordId"]

    aId = G(recordId, ASSESS)
    recordId.setdefault(REVIEW, {})

    def assertIt(cl, exp):
        rId = assertStartTask(cl, START_REVIEW, aId, exp)
        assert rId is not None
        user = cl.user
        recordId[REVIEW][user] = rId

    expect = {user: True for user in {EXPERT, FINAL}}
    forall(clientsReviewer, expect, assertIt)
def test_makeEditorAll(clients):
    valueTables = startInfo["valueTables"]
    recordId = startInfo["recordId"]

    eid = G(recordId, CONTRIB)

    def assertIt(cl, exp):
        assertEditor(cl, CONTRIB, eid, valueTables, exp)
        if exp:
            assertEditor(cl, CONTRIB, eid, valueTables, exp, clear=True)

    expect = {user: False for user in USERS}
    expect.update({user: True for user in {OWNER, OFFICE, SYSTEM, ROOT}})
    forall(clients, expect, assertIt)
def test_viewCost(clients, field):
    recordId = startInfo["recordId"]

    eid = G(recordId, CONTRIB)
    value = EXAMPLE[field]
    if field == COST_DESCRIPTION:
        value = value[0]
    valueStrip = value.strip()

    def assertIt(cl, exp):
        assertFieldValue((cl, CONTRIB, eid), field, exp)

    expect = {user: None for user in USERS}
    expect.update({user: valueStrip for user in RIGHTFUL_USERS})
    expect.update({MYCOORD: valueStrip})
    forall(clients, expect, assertIt)
Example #15
0
def test_viewAssessment(clients):
    recordId = startInfo["recordId"]

    aId = G(recordId, ASSESS)

    def assertIt(cl, exp):
        assessInfo = getItem(cl, ASSESS, aId)
        text = assessInfo["text"]
        tasks = findTasks(text)
        if exp:
            assert len(tasks) == 1
            assert tasks[0] == exp

    expect = {user: () for user in USERS}
    expect.update({user: (START_REVIEW, aId) for user in (EXPERT, FINAL)})
    forall(clients, expect, assertIt)
Example #16
0
def test_tryStartReviewAll(clients):
    recordId = startInfo["recordId"]

    aId = G(recordId, ASSESS)

    def assertIt(cl, exp):
        rId = assertStartTask(cl, START_REVIEW, aId, exp)
        if exp:
            assert rId is not None
            assertDelItem(cl, REVIEW, rId, True)
        else:
            assert rId is None

    expect = {user: False for user in USERS}
    expect.update({user: True for user in {EXPERT, FINAL}})
    forall(clients, expect, assertIt)
def test_decideOthers(clients):
    recordId = startInfo["recordId"]

    reviewId = G(recordId, REVIEW)

    def assertIt(cl, exp):
        user = cl.user
        for kind in [EXPERT, FINAL]:
            rId = G(reviewId, kind)
            expStatus = kind == user if exp else exp
            for decision in [REJECT, REVISE, ACCEPT, REVOKE]:
                decisionStr = G(G(REVIEW_DECISION, decision), kind)
                url = f"/api/task/{decisionStr}/{rId}"
                assertStatus(cl, url, expStatus)

    expect = {user: False for user in USERS if user not in {EXPERT, FINAL}}
    forall(clients, expect, assertIt)
Example #18
0
def inspectTitleAll(clients, table, eid, expect):
    """Verify the title of an item, as seen by each user.

    Parameters
    ----------
    clients: dict
        Mapping from users to client fixtures
    table: the table of the item
    eid: the id of the item
    expect: dict
        The expected values, keyed per user
    """

    def assertIt(cl, exp):
        assertFieldValue((cl, table, eid), TITLE, exp)

    forall(clients, expect, assertIt)
Example #19
0
def test_modifyTitleAll(clients):
    recordId = startInfo["recordId"]
    recordInfo = startInfo["recordInfo"]

    aId = G(recordId, ASSESS)
    contribInfo = recordInfo[CONTRIB]
    fields = contribInfo["fields"]

    cTitle = G(fields, TITLE)
    aTitle = TITLE_A.format(cTitle=cTitle)

    def assertIt(cl, exp):
        assertModifyField(cl, ASSESS, aId, TITLE, TITLE_A2, exp)
        if exp:
            assertModifyField(cl, ASSESS, aId, TITLE, aTitle, exp)

    expect = {user: False for user in USERS}
    expect.update({user: True for user in RIGHTFUL_USERS})
    forall(clients, expect, assertIt)
Example #20
0
def test_reviewEntryFill(clientsReviewer):
    recordId = startInfo["recordId"]

    cIds = recordId[CRITERIA_ENTRY]

    def assertIt(cl, exp):
        user = cl.user
        for (i, crId) in enumerate(cIds):
            criteriaEntryInfo = getItem(cl, CRITERIA_ENTRY, crId)
            text = criteriaEntryInfo["text"]
            reviewEntries = findReviewEntries(text)
            rId = reviewEntries[user][0]
            newValue = [f"{user}'s comment on criteria {i + 1}"]
            newValueRep = ",".join(newValue)
            assertModifyField(cl, REVIEW_ENTRY, rId, COMMENTS,
                              (newValue, newValueRep), exp)

    expect = {user: True for user in {EXPERT, FINAL}}
    forall(clientsReviewer, expect, assertIt)
Example #21
0
def modifyTitleAll(clients, table, eid, expect):
    """Modify the title of an item, performed by each user.

    Parameters
    ----------
    clients: dict
        Mapping from users to client fixtures
    table: the table of the item
    eid: the id of the item
    expect: dict
        The expected values, keyed per user
    """

    def assertIt(cl, exp):
        assertModifyField(cl, table, eid, TITLE, TITLE2, exp)
        if exp:
            assertModifyField(cl, table, eid, TITLE, TITLE1, exp)

    forall(clients, expect, assertIt)
Example #22
0
def sidebar(clients, amounts):
    """Verify the sidebar.

    It will be verified whether each user sees the right entries,
    and that following an entry leads to the expected results.

    Parameters
    ----------
    clients: dict
        Mapping from users to client fixtures
    amounts: dict
        Keyed by entry, it is a list of instructions to change the expected amount.
        Each instruction is a pair `(set of users, amount)`, leading
        to setting the indicated amount for the indicated users.
        The set of users can be left out, then all users are implied.
    """

    expectedCaptions = {}
    for (caption, expectedUsers, expectedN, expectedItemSg, expectedItemPl) in CAPTIONS:
        for user in expectedUsers:
            thisCaption = (
                caption.format(country=USER_COUNTRY[user])
                if "{country}" in caption
                else caption
            )
            n = expectedN
            for instruction in G(amounts, thisCaption, default=[]):
                if type(instruction) is tuple or type(instruction) is list:
                    (theseUsers, thisAmount) = instruction
                else:
                    (theseUsers, thisAmount) = (USERS, instruction)
                if user in theseUsers:
                    n = thisAmount
            if n is None:
                expectedItem = expectedItemSg or thisCaption
            else:
                pl = expectedItemPl or thisCaption
                sg = expectedItemSg or thisCaption[0:-1]
                expectedItem = sg if n == 1 else pl
            expectedCaptions.setdefault(user, {})[thisCaption] = (n, expectedItem)

    expect = {user: G(expectedCaptions, user) for user in USERS}
    forall(clients, expect, assertCaptions)
def test_changeUserCountry(clientsPower):
    valueTables = startInfo["valueTables"]

    users = valueTables[USER]
    countries = valueTables[COUNTRY]

    assert MYCOORD in users
    assert BELGIUM in countries
    assert LUXEMBURG in countries

    mycoord = users[MYCOORD]
    belgium = countries[BELGIUM]
    luxemburg = countries[LUXEMBURG]

    def assertIt(cl, exp):
        assertFieldValue((cl, USER, mycoord), COUNTRY, BELGIUM)

        assertModifyField(cl, USER, mycoord, COUNTRY, (luxemburg, LUXEMBURG),
                          exp)
        assertModifyField(cl, USER, mycoord, COUNTRY, (belgium, BELGIUM), exp)

    expect = {user: True for user in POWER_USERS}
    forall(clientsPower, expect, assertIt)
def test_reviewEntryView(clients):
    recordId = startInfo["recordId"]

    cIds = recordId[CRITERIA_ENTRY]
    cIdFirst = cIds[0]
    reId = {}
    for user in {EXPERT, FINAL}:
        criteriaEntryInfo = getItem(clients[user], CRITERIA_ENTRY, cIdFirst)
        text = criteriaEntryInfo["text"]
        reviewEntries = findReviewEntries(text)
        reId[user] = reviewEntries[user][0]

    def assertIt(cl, exp):
        user = cl.user
        for (kind, rId) in reId.items():
            value = f"{kind}'s comment on criteria 1"
            expValue = (None
                        if exp is None else value if user in {EXPERT, FINAL}
                        | POWER_USERS else None)
            assertFieldValue((cl, REVIEW_ENTRY, rId), COMMENTS, expValue)

    expect = {user: None for user in USERS}
    expect.update({user: True for user in {EXPERT, FINAL} | POWER_USERS})
    forall(clients, expect, assertIt)
Example #25
0
def test_reviewEntryFillFirstAll(clients):
    recordId = startInfo["recordId"]

    cIds = recordId[CRITERIA_ENTRY]
    cIdFirst = cIds[0]
    reviewId = recordId[REVIEW]
    reviewEntryId = getReviewEntryId(clients, cIdFirst, reviewId[EXPERT],
                                     reviewId[FINAL])

    def assertIt(cl, exp):
        user = cl.user
        for (kind, renId) in reviewEntryId.items():
            thisExp = exp and (kind == user or user in POWER_USERS)
            newValue = [f"{user}'s comment"]
            newValueRep = ",".join(newValue)
            assertModifyField(cl, REVIEW_ENTRY, renId, COMMENTS,
                              (newValue, newValueRep), thisExp)
            if thisExp:
                assertModifyField(cl, REVIEW_ENTRY, renId, COMMENTS, ([], E),
                                  True)

    expect = {user: False for user in USERS}
    expect.update({user: True for user in {EXPERT, FINAL} | POWER_USERS})
    forall(clients, expect, assertIt)
Example #26
0
def startAssessment(clients, eid, expect):
    """Starts an assessment and deletes it immediately afterwards.

    All users in `clients` for which there is an entry in `expect` do this.

    Parameters
    ----------
    clients: dict
        Mapping from users to client fixtures
    eid: string(ObjectId)
        The id of the contribution for an assessment is started
    expect: dict
        Per user whether the starting of an assessment succeeds or not
    """

    def assertIt(cl, exp):
        aId = assertStartTask(cl, START_ASSESSMENT, eid, exp)
        if exp:
            assert aId is not None
            assertDelItem(cl, ASSESS, aId, True)
        else:
            assert aId is None

    forall(clients, expect, assertIt)
def test_modify2(clients):
    valueTables = startInfo["valueTables"]
    recordId = startInfo["recordId"]

    users = valueTables[USER]
    eid = recordId[CONTRIB]
    aId = recordId[ASSESS]
    reviewId = recordId[REVIEW]
    rExpertId = reviewId[EXPERT]
    rFinalId = reviewId[FINAL]
    cIdFirst = recordId[CRITERIA_ENTRY][0]
    renId = getReviewEntryId(clients, cIdFirst, rExpertId, rFinalId)

    def assertIt(cl, exp):
        assertModifyField(cl, CONTRIB, eid, TITLE, TITLE2, exp[CONTRIB])
        assertModifyField(cl, ASSESS, aId, TITLE, TITLE_A2, exp[ASSESS])
        reviewerFId = G(users, FINAL)
        reviewerEId = G(users, EXPERT)
        assertModifyField(cl, ASSESS, aId, REVIEWER_E, (reviewerFId, FINAL),
                          exp["assign"])
        assertModifyField(cl, ASSESS, aId, REVIEWER_E, (reviewerEId, EXPERT),
                          exp["assign"])
        assertModifyField(
            cl,
            CRITERIA_ENTRY,
            cIdFirst,
            EVIDENCE,
            ([EVIDENCE1], EVIDENCE1),
            exp[CRITERIA_ENTRY],
        )
        for (rId, remarks, kind) in (
            (rExpertId, REMARKS_E, EXPERT),
            (rFinalId, REMARKS_F, FINAL),
        ):
            assertModifyField(cl, REVIEW, rId, REMARKS, ([remarks], remarks),
                              exp[f"{REVIEW}_{kind}"])
        for (kind, reid) in renId.items():
            comments = COMMENTS_E if kind == EXPERT else COMMENTS_F
            assertModifyField(
                cl,
                REVIEW_ENTRY,
                reid,
                COMMENTS,
                ([comments], comments),
                exp[f"{REVIEW_ENTRY}_{kind}"],
            )

    expectDefault = {user: False for user in USERS}
    expectPerKind = {
        CONTRIB: dict(expectDefault),
        ASSESS: dict(expectDefault),
        CRITERIA_ENTRY: dict(expectDefault),
        "assign": dict(expectDefault),
        f"{REVIEW}_{EXPERT}": dict(expectDefault),
        f"{REVIEW}_{FINAL}": dict(expectDefault),
        f"{REVIEW_ENTRY}_{EXPERT}": dict(expectDefault),
        f"{REVIEW_ENTRY}_{FINAL}": dict(expectDefault),
    }
    expectPerKind["assign"].update({user: True for user in {OFFICE}})
    expectPerKind[f"{REVIEW}_{EXPERT}"].update(
        {user: True
         for user in {EXPERT} | POWER_USERS})
    expectPerKind[f"{REVIEW}_{FINAL}"].update(
        {user: True
         for user in {FINAL} | POWER_USERS})
    expectPerKind[f"{REVIEW_ENTRY}_{EXPERT}"].update(
        {user: True
         for user in {EXPERT} | POWER_USERS})
    expectPerKind[f"{REVIEW_ENTRY}_{FINAL}"].update(
        {user: True
         for user in {FINAL} | POWER_USERS})
    expect = {}
    for (kind, expectKind) in expectPerKind.items():
        for (user, exp) in expectKind.items():
            expect.setdefault(user, {})[kind] = exp

    forall(clients, expect, assertIt)
Example #28
0
def test_workflow(clients):
    url = "/workflow"
    expect = {user: 302 if user in {SYSTEM, ROOT} else 303 for user in USERS}
    forall(clients, expect, assertStatus, url)
    illegalize(clients, url)
Example #29
0
def test_long(clients):
    url = "/" + "a" * 1000
    expect = {user: 400 for user in USERS}
    forall(clients, expect, assertStatus, url)