예제 #1
0
def test_expected_subjectable_resources_work(requests_mock):
    mock_assignments(requests_mock)
    mock_summary(requests_mock)
    mock_subjects(requests_mock)
    mock_reviews(requests_mock)
    mock_single_subject(requests_mock)
    mock_study_materials(requests_mock)
    mock_summary(requests_mock)

    client = Client("arbitrary_api_key")

    assignments = client.assignments()
    assert assignments[0].subject is not None

    study_materials = client.study_materials()
    assert study_materials[0].subject is not None

    study_materials = client.study_materials()
    assert study_materials[0].subject is not None

    summary = client.summary()
    assert summary.reviews[0].subjects is not None

    reviews = client.reviews()
    assert reviews[0].subject is not None
예제 #2
0
def test_client_can_get_assignments(requests_mock):
    mock_assignments(requests_mock)

    client = Client("v2_api_key")

    assignments = client.assignments()

    assert len(assignments.current_page.data) > 0
예제 #3
0
def test_subjectable_mixin_works(requests_mock):
    mock_subjects(requests_mock)
    mock_assignments(requests_mock)
    client = Client("arbitrary_api_key", subject_cache_enabled=True)

    assignments = client.assignments()
    assignment = assignments[0]
    subj = assignment.subject
    assert subj.id == assignment.subject_id
예제 #4
0
def test_assignment_parameters_are_properly_converted(requests_mock):
    mock_assignments(requests_mock)
    v2_api_key = "arbitrary_api_key"
    client = Client(v2_api_key)

    client.assignments(ids=[1, 2, 3], hidden=False, srs_stages=[0, 1, 2])

    assert requests_mock.call_count == 1
    assert (
        requests_mock.request_history[0].url ==
        "https://api.wanikani.com/v2/assignments?hidden=false&ids=1,2,3&srs_stages=0,1,2"
    )
예제 #5
0
def test_client_uses_cache(requests_mock):
    mock_subjects(requests_mock)
    mock_assignments(requests_mock)
    v2_api_key = "arbitrary_api_key"
    client = Client(v2_api_key, subject_cache_enabled=True)
    assignments = client.assignments()
    for ass in assignments:
        print(ass.subject.level)  # in theory here, if we have _not_ cached

    assert requests_mock.call_count == 2
    history = requests_mock.request_history
    assert "subjects" in history[0].url
    assert "assignments" in history[1].url