Esempio n. 1
0
def test_hashid_model_choice_field_with_invalid_hashid():
    field = HashidModelChoiceField(queryset=Submission.objects.all())

    with raises(ValidationError) as e:
        field.to_python(encode_hashid(5))

    assert e.value.code == "invalid_choice"
Esempio n. 2
0
def test_returns_none_when_missing(graphql_client):
    resp = graphql_client.query(
        """query SubmissionQuery($id: ID!) {
            submission(id: $id) {
                id
            }
        }""",
        variables={"id": encode_hashid(11)},
    )

    assert not resp.get("errors")
    assert resp["data"]["submission"] is None
Esempio n. 3
0
def test_add_custom_item_from_submission(
    conference_factory,
    day_factory,
    slot_factory,
    room,
    submission,
    admin_graphql_client,
):
    conference = conference_factory(
        start=datetime(2020, 4, 2, tzinfo=pytz.UTC),
        end=datetime(2020, 4, 2, tzinfo=pytz.UTC),
    )

    day = day_factory(conference=conference, day=date(2020, 4, 2))
    slot = slot_factory(day=day, hour=time(8, 45), duration=60)

    resp = admin_graphql_client.query(
        """
        mutation($input: UpdateOrCreateSlotItemInput!) {
            updateOrCreateSlotItem(input: $input) {
                ... on UpdateOrCreateSlotItemResult {
                    updatedSlots {
                        items {
                            type
                            title
                        }
                }
            }
        }
                    }
        """,
        variables={
            "input": {
                "slotId": slot.id,
                "submissionId": encode_hashid(submission.id),
                "rooms": [room.id],
            }
        },
    )

    assert "errors" not in resp
    assert resp["data"]["updateOrCreateSlotItem"]["updatedSlots"][0][
        "items"] == [{
            "title": submission.title,
            "type": "submission"
        }]
Esempio n. 4
0
 def hashid(self):
     return encode_hashid(self.pk)