Esempio n. 1
0
def test_filter_by_spec(collection: MaterialRunCollection, session):
    """
    Test that MaterialRunCollection.filter_by_spec() hits the expected endpoint
    """
    # Given
    project_id = '6b608f78-e341-422c-8076-35adc8828545'
    material_spec = MaterialSpecFactory()
    test_scope = 'id'
    test_id = material_spec.uids[test_scope]
    sample_run = MaterialRunDataFactory(spec=material_spec)
    session.set_response({'contents': [sample_run]})

    # When
    runs = [run for run in collection.filter_by_spec(test_id, per_page=20)]

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(
        method="GET",
        path="projects/{}/material-specs/{}/{}/material-runs".format(
            project_id, test_scope, test_id),
        # per_page will be ignored
        params={
            "dataset_id": str(collection.dataset_id),
            "forward": True,
            "ascending": True,
            "per_page": 100
        })
    assert session.last_call == expected_call
    assert runs == [collection.build(sample_run)]
Esempio n. 2
0
def test_register_all(collection, session):
    runs = [
        MaterialRunFactory(name='1'),
        MaterialRunFactory(name='2'),
        MaterialRunFactory(name='3')
    ]
    session.set_response({'objects': [r.dump() for r in runs]})
    registered = collection.register_all(runs)
    assert [r.name for r in runs] == [r.name for r in registered]
    assert len(session.calls) == 1
    assert session.calls[0].method == 'PUT'
    assert session.calls[
        0].path == 'projects/{}/datasets/{}/material-runs/batch'.format(
            collection.project_id, collection.dataset_id)
    with pytest.raises(RuntimeError):
        MaterialRunCollection(collection.project_id,
                              dataset_id=None,
                              session=session).register_all([])
Esempio n. 3
0
 def material_runs(self) -> MaterialRunCollection:
     """Return a resource representing all material runs in this dataset."""
     return MaterialRunCollection(self.uid, None, self.session)
Esempio n. 4
0
def collection(session) -> MaterialRunCollection:
    return MaterialRunCollection(
        project_id=UUID('6b608f78-e341-422c-8076-35adc8828545'),
        dataset_id=UUID('8da51e93-8b55-4dd3-8489-af8f65d4ad9a'),
        session=session)