Пример #1
0
def test_search_projects_with_pagination(paginated_collection, paginated_session):
    # Given
    common_name = "same name"

    same_name_projects_data = ProjectDataFactory.create_batch(35, name=common_name)
    more_data = ProjectDataFactory.create_batch(35, name="some other name")


    per_page = 10

    paginated_session.set_response({ 'projects': same_name_projects_data })

    search_params = {'status': {
        'value': common_name,
        'search_method': 'EXACT'}}


    # When
    projects = list(paginated_collection.search(per_page=per_page, search_params=search_params))

    # Then
    assert 4 == paginated_session.num_calls
    expected_first_call = FakeCall(method='POST', path='/projects/search', 
                                        params={'per_page': per_page}, json={'search_params': search_params} )
    expected_last_call = FakeCall(method='POST', path='/projects/search', 
                                        params={'page': 4, 'per_page': per_page}, json={'search_params': search_params})

    assert expected_first_call == paginated_session.calls[0]
    assert expected_last_call == paginated_session.last_call

    project_ids = [str(p.uid) for p in projects]
    expected_ids = [p['id'] for p in same_name_projects_data]

    assert project_ids == expected_ids
Пример #2
0
def test_search_projects(collection, session):
    # Given
    projects_data = ProjectDataFactory.create_batch(2)

    project_name_to_match = projects_data[0]['name']

    expected_response = list(
        filter(lambda p: p["name"] == project_name_to_match, projects_data))

    session.set_response({'projects': expected_response})

    search_params = {
        'name': {
            'value': project_name_to_match,
            'search_method': 'EXACT'
        }
    }

    # When
    projects = list(collection.search(search_params=search_params))

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='POST',
                             path='/projects/search',
                             params={'per_page': 100},
                             json={'search_params': search_params})
    assert expected_call == session.last_call
    assert len(expected_response) == len(projects)
Пример #3
0
def test_project_registration(collection, session):
    # Given
    create_time = parse('2019-09-10T00:00:00+00:00')
    project_data = ProjectDataFactory(
        name='testing',
        description='A sample project',
        created_at=int(
            create_time.timestamp() *
            1000)  # The lib expects ms since epoch, which is really odd
    )
    session.set_response({'project': project_data})

    # When
    created_project = collection.register('testing')

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='POST',
                             path='/projects',
                             json={
                                 'name': 'testing',
                                 'description': None,
                                 'id': None,
                                 'status': None,
                                 'created_at': None,
                             })
    assert expected_call == session.last_call

    assert 'A sample project' == created_project.description
    assert 'CREATED' == created_project.status
    assert create_time == created_project.created_at
Пример #4
0
def test_list_projects_filters_non_projects(collection, session):
    # Given
    projects_data = ProjectDataFactory.create_batch(5)
    projects_data.append({'foo': 'not a project'})
    session.set_response({'projects': projects_data})

    # Then
    with pytest.raises(RuntimeError):
        # When
        projects = list(collection.list())
Пример #5
0
def test_list_projects_with_page_params(collection, session):
    # Given
    project_data = ProjectDataFactory()
    session.set_response({'projects': [project_data]})

    # When
    list(collection.list(page=3, per_page=10))

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='GET', path='/projects', params={'page': 3, 'per_page': 10})
    assert expected_call == session.last_call
Пример #6
0
def test_list_projects(collection, session):
    # Given
    projects_data = ProjectDataFactory.create_batch(5)
    session.set_response({'projects': projects_data})

    # When
    projects = list(collection.list())

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='GET', path='/projects', params={'per_page': 1000})
    assert expected_call == session.last_call
    assert 5 == len(projects)
Пример #7
0
def test_list_projects_filters_non_projects(collection, session):
    # Given
    projects_data = ProjectDataFactory.create_batch(5)
    projects_data.append({'foo': 'not a project'})
    session.set_response({'projects': projects_data})

    # When
    projects = list(collection.list())

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(method='GET', path='/projects')
    assert expected_call == session.last_call
    assert 5 == len(projects)   # The non-project data is filtered out
Пример #8
0
def test_get_project(collection, session):
    # Given
    project_data = ProjectDataFactory(name='single project')
    session.set_response({'project': project_data})

    # When
    created_project = collection.get(project_data['id'])

    # Then
    assert 1 == session.num_calls
    expected_call = FakeCall(
        method='GET',
        path='/projects/{}'.format(project_data['id']),
    )
    assert expected_call == session.last_call
    assert 'single project' == created_project.name
Пример #9
0
def project() -> Project:
    return Project.build(ProjectDataFactory())