def step_impl(context: Context, name: str): project = ProjectStub.create(ProjectName(name), Downloads(0)) for row in context.table: date = datetime.strptime(row["date"], "%Y-%m-%d").date() project.add_downloads(date, row["version"], Downloads(int(row["downloads"]))) context.container.project_repository.save(project)
def test_find_project_replacing_dots_with_dashes(project_repository: DBProjectRepository, project_view: DBProjectView): project = ProjectStub.create(name=ProjectName('pepy-rocks')) project_repository.save_projects([project]) result = project_view.find('pepy.rocks') expected = ProjectProjection('pepy-rocks', project.downloads.value, []) assert result == expected
def test_update_downloads(project_repository: DBProjectRepository): project = ProjectStub.create() project_repository.save_projects([project]) project_downloads = ProjectDownloadsStub.create(name=project.name) project_repository.update_downloads([project_downloads]) result = find_project(project.name.name) assert project_downloads.downloads.value + project.downloads.value == result["downloads"]
def test_find_project_ignoring_white_spaces(project_repository: DBProjectRepository, project_view: DBProjectView): project = ProjectStub.create(name=ProjectName('pepy')) project_repository.save_projects([project]) result = project_view.find(' pepy ') expected = ProjectProjection('pepy', project.downloads.value, []) assert result == expected
def test_find_project(project_repository: DBProjectRepository): project = ProjectStub.create() project_repository.save_projects([project]) result = project_repository.find(project.name) assert isinstance(result, Project) assert project.name.name == result.name.name assert project.downloads.value == result.downloads.value
def test_find_project_ignoring_case(project_repository: DBProjectRepository, project_view: DBProjectView): project = ProjectStub.create(name=ProjectName("pepy")) project_repository.save_projects([project]) result = project_view.find("PEpy") expected = ProjectProjection("pepy", project.downloads.value, []) assert result == expected
def step_impl(context: Context, name: str): project_name = ProjectName(name) project = ProjectStub.create(project_name) context.container.project_repository.save_projects([project]) downloads = [] for row in context.table: date = datetime.strptime(row['date'], '%Y-%m-%d').date() downloads.append( ProjectDownloads(project_name, Downloads(row['downloads']), date)) context.container.project_repository.save_day_downloads(downloads)
def step_impl(context: Context, name: str): project_name = ProjectName(name) downloads = [] total_downloads = 0 for row in context.table: date = datetime.strptime(row["date"], "%Y-%m-%d").date() total_downloads += int(row["downloads"]) downloads.append( ProjectDownloads(project_name, Downloads(row["downloads"]), date)) project = ProjectStub.create(project_name, Downloads(total_downloads)) context.container.project_repository.save_projects([project]) context.container.project_repository.save_day_downloads(downloads)
def step_impl(context: Context): projects = [ ProjectStub.from_plain_data(**row.as_dict()) for row in context.table ] context.container.project_repository.save_projects(projects)
def test_retrieve_last_downloads(project_repository: DBProjectRepository): project = ProjectStub.create() project_repository.save_projects([project]) project_downloads = ProjectDownloadsStub.create_consecutive(project.name) project_repository.save_day_downloads(project_downloads) assert project_downloads == project_repository.last_downloads(project.name)