def test_addAssessment2(clientOwner):
    recordId = startInfo["recordId"]
    recordInfo = startInfo["recordInfo"]
    ids = startInfo["ids"]

    eid = G(recordId, CONTRIB)
    aId = G(recordId, ASSESS)

    assessInfo = getItem(clientOwner, ASSESS, aId)
    recordInfo[ASSESS] = assessInfo
    fields = assessInfo["fields"]

    aTitle = G(fields, TITLE)
    assertModifyField(clientOwner, CONTRIB, eid, TYPE, (ids["TYPE2"], TYPE2),
                      True)
    assessInfo = getItem(clientOwner, ASSESS, aId)
    text = assessInfo["text"]
    assert checkWarning(text, aTitle)

    assertStartTask(clientOwner, START_ASSESSMENT, eid, True)
    aIds = getEid(clientOwner, ASSESS, multiple=True)
    assert len(aIds) == 2

    newAId = [i for i in aIds if i != aId][0]
    assertDelItem(clientOwner, ASSESS, newAId, True)

    assertModifyField(clientOwner, CONTRIB, eid, TYPE, (ids["TYPE1"], TYPE1),
                      True)
    assessInfo = getItem(clientOwner, ASSESS, aId)
    text = assessInfo["text"]
    assert not checkWarning(text, aTitle)
Example #2
0
 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
Example #3
0
    def startFillout():
        aId = recordId[ASSESS]
        assessInfo = getItem(clientOwner, ASSESS, aId)
        criteriaEntries = findDetails(assessInfo["text"], CRITERIA_ENTRY)
        nCId = len(criteriaEntries)
        assert nCId == CRITERIA_ENTRIES_N[TYPE1]
        cIds = []

        for (i, (cId, material)) in enumerate(criteriaEntries):
            cIds.append(cId)
            assert ELLIPS_DIV in material
            scores = getScores(cId)
            (scoreValue, scoreId) = sorted(scores.items())[1]
            assertModifyField(
                clientOwner, CRITERIA_ENTRY, cId, SCORE, (scoreId, scoreValue), True,
            )
            theEvidence = [f"evidence for {i + 1}", "see the internet"]
            theEvidenceRep = ",".join(theEvidence)
            assertModifyField(
                clientOwner,
                CRITERIA_ENTRY,
                cId,
                EVIDENCE,
                (theEvidence, theEvidenceRep),
                True,
            )
        recordId[CRITERIA_ENTRY] = cIds

        assertStage(clientOwner, ASSESS, aId, COMPLETE)

        if submit:
            startSubmit()
Example #4
0
def assertStage(client, table, eid, expect):
    """Check whether a record has a certain workflow stage.

    Parameters
    ----------
    client: fixture
    table: string
    eid: ObjectId | string
    expect: string | set of string
        If a set, we expect one of the values in the set

    Returns
    -------
    dict
        The text, fields, msgs and stage of the record
    """

    info = getItem(client, table, eid)
    text = info["text"]
    stageFound = findStages(text)[0]
    info["stage"] = stageFound
    if type(expect) is set:
        assert stageFound in expect
    else:
        assert stageFound == expect
    return info
Example #5
0
def assertFieldValue(source, field, expect):
    """Verify whether a field has a certain expected value.

    If we pass expect `None` we want to assert that the field is not present at all.

    Parameters
    ----------
    source: dict | (client: fixture, table: string, eid: string)
        The dictionary of fields and values of a retrieved response.
        If it is a tuple, the dictionary will be retrieved by looking up
        the item specified by `table` and `eid`.
    field: string
        The name of the specific field.
    expect:
        The expected value for this field.
    """

    if type(source) is tuple:
        (client, table, eid) = source
        info = getItem(client, table, eid)
        fields = info["fields"]
    else:
        fields = source

    if expect is None:
        assert field not in fields
    else:
        assert field in fields
        value = fields[field]
        if value != expect:
            serverprint(f"FIELDVALUE {field}={value} (=/={expect})")
        assert expect == fields[field]
def test_addOwner(clientOwner):
    recordId = startInfo["recordId"]
    recordInfo = startInfo["recordInfo"]

    eid = assertAddItem(clientOwner, CONTRIB, True)
    recordId[CONTRIB] = eid
    recordInfo[CONTRIB] = getItem(clientOwner, CONTRIB, eid)
Example #7
0
def assertModifyField(client, table, eid, field, newValue, expect):
    """Try to modify a field and check the outcome.

    !!! note "Read access"
        The test has to reckon with the fact that the client may not even have
        read access to the field.

    Parameters
    ----------
    client: fixture
    table: string
    eid: ObjectId | string
    field: string
    newValue: string | tuple
        If a tuple, the first component is the modification value,
        and the second component is the value we read back from the modified record
    expect: boolean
        Whether we expect the modification to succeed
    """

    if not expect:
        info = getItem(client, table, eid)
        fields = info["fields"]
        oldValue = fields[field] if field in fields else None

    if type(newValue) is tuple:
        (newValue, newValueRep) = newValue
    else:
        newValueRep = newValue

    (text, fields) = modifyField(client, table, eid, field, newValue)

    if not expect:
        assert field not in fields

    info = getItem(client, table, eid)
    fields = info["fields"]

    if expect:
        assertFieldValue(fields, field, newValueRep)
    else:
        if field in fields:
            assertFieldValue(fields, field, oldValue)
Example #8
0
 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)
Example #9
0
 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
Example #10
0
def test_inspectTitleAll(clients):
    recordId = startInfo["recordId"]
    recordInfo = startInfo["recordInfo"]

    eid = G(recordId, CONTRIB)
    aId = G(recordId, ASSESS)

    contribInfo = getItem(clients[OWNER], CONTRIB, eid)
    recordInfo[CONTRIB] = contribInfo
    fields = contribInfo["fields"]

    cTitle = G(fields, TITLE)
    aTitle = TITLE_A.format(cTitle=cTitle)
    expect = {user: None for user in USERS}
    expect.update({user: aTitle for user in RIGHTFUL_USERS})
    inspectTitleAll(clients, ASSESS, aId, expect)
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)
import json
from helpers import getItem, loginUser, getItem

nick = {'username': '******', 'password': '******'}
nickToken = loginUser(nick)

olga = {'username': '******', 'password': '******'}
olgaToken = loginUser(olga)

itemId = 48

responseNick = getItem(itemId, nickToken)
responseOlga = getItem(itemId, olgaToken)

nickJson = responseNick.text
nickParsed = json.loads(nickJson)
print(json.dumps(nickParsed, indent=4, sort_keys=True))

olgaJson = responseOlga.text
olgaParsed = json.loads(olgaJson)
print(json.dumps(olgaParsed, indent=4, sort_keys=True))
Example #13
0
 def get(self, courseId, _id):
     return helpers.getItem(handle, "questions", models.question_fields, _id, courseId)
Example #14
0
 def get(self, _id):
     return helpers.getItem(handle, "users", models.user_fields, _id)
Example #15
0
 def get(self, _id):
     return helpers.getItem(handle, "courses", models.course_fields, _id)