Esempio n. 1
0
def test_retrieve_project_with_old_format(mongo_client: MongoClient,
                                          repository: ProjectRepository):
    data = {
        "name": "climoji",
        "total_downloads": 1100,
        "downloads": {
            "2020-04-01": [["2.0", 30]],
            "2020-04-02": [["2.0", 10]],
            "2020-03-31": [["2.0", 40]],
            "2020-04-03": [["2.0", 30]],
        },
    }
    query = {"name": "climoji"}
    mongo_client.pepy_test.projects.replace_one(query, data, upsert=True)

    result = repository.get("climoji")
    assert ProjectName("climoji") == result.name
    assert datetime.date(2020, 3, 31) == result.min_date
    assert Downloads(1100) == result.total_downloads
    expected_last_downloads = [
        ProjectVersionDownloads(datetime.date(2020, 3, 31), "2.0",
                                Downloads(40)),
        ProjectVersionDownloads(datetime.date(2020, 4, 1), "2.0",
                                Downloads(30)),
        ProjectVersionDownloads(datetime.date(2020, 4, 2), "2.0",
                                Downloads(10)),
        ProjectVersionDownloads(datetime.date(2020, 4, 3), "2.0",
                                Downloads(30)),
    ]
    assert expected_last_downloads == result.last_downloads()
Esempio n. 2
0
def test_retrieve_project_with_new_format(mongo_client: MongoClient,
                                          repository: ProjectRepository):
    data = {
        "name": "climoji",
        "total_downloads": 1100,
    }
    query = {"name": "climoji"}
    mongo_client.pepy_test.projects.replace_one(query, data, upsert=True)
    downloads_data = [
        InsertOne({
            "project": "climoji",
            "date": "2020-04-01",
            "downloads": [{
                "version": "2.0",
                "downloads": 30
            }]
        }),
        InsertOne({
            "project": "climoji",
            "date": "2020-04-02",
            "downloads": [{
                "version": "2.0",
                "downloads": 10
            }]
        }),
        InsertOne({
            "project": "climoji",
            "date": "2020-03-31",
            "downloads": [{
                "version": "2.0",
                "downloads": 40
            }]
        }),
        InsertOne({
            "project": "climoji",
            "date": "2020-04-03",
            "downloads": [{
                "version": "2.0",
                "downloads": 30
            }]
        }),
    ]
    mongo_client.pepy_test.project_downloads.bulk_write(downloads_data)

    result = repository.get("climoji")
    assert ProjectName("climoji") == result.name
    assert datetime.date(2020, 3, 31) == result.min_date
    assert Downloads(1100) == result.total_downloads
    expected_last_downloads = [
        ProjectVersionDownloads(datetime.date(2020, 3, 31), "2.0",
                                Downloads(40)),
        ProjectVersionDownloads(datetime.date(2020, 4, 1), "2.0",
                                Downloads(30)),
        ProjectVersionDownloads(datetime.date(2020, 4, 2), "2.0",
                                Downloads(10)),
        ProjectVersionDownloads(datetime.date(2020, 4, 3), "2.0",
                                Downloads(30)),
    ]
    assert expected_last_downloads == result.last_downloads()
Esempio n. 3
0
def test_update_min_date_when_no_other_downloads():
    project = Project(ProjectName("random"), Downloads(10))
    project.add_downloads(date(2019, 3, 9), "0.0.6", Downloads(20))
    project.add_downloads(date(2020, 4, 10), "0.0.2", Downloads(10))
    project.add_downloads(date(2020, 4, 10), "0.0.4", Downloads(10))
    assert project.total_downloads == Downloads(50)
    assert project.last_downloads() == [
        ProjectVersionDownloads(date(2020, 4, 10), "0.0.2", Downloads(10)),
        ProjectVersionDownloads(date(2020, 4, 10), "0.0.4", Downloads(10)),
    ]
    assert project.versions() == {"0.0.6", "0.0.2", "0.0.4"}
    assert project.min_date == date(2020, 4, 10)
Esempio n. 4
0
def test_filter_date():
    project = Project(ProjectName("random"), Downloads(10))
    project.add_downloads(date(2020, 3, 9), "0.0.6", Downloads(20))
    project.add_downloads(date(2020, 4, 10), "0.0.2", Downloads(10))
    project.add_downloads(date(2020, 4, 10), "0.0.4", Downloads(10))
    project.add_downloads(date(2020, 4, 11), "0.0.4", Downloads(10))
    assert project.total_downloads == Downloads(60)
    assert project.last_downloads(date(2020, 4, 10)) == [
        ProjectVersionDownloads(date(2020, 4, 10), "0.0.2", Downloads(10)),
        ProjectVersionDownloads(date(2020, 4, 10), "0.0.4", Downloads(10)),
        ProjectVersionDownloads(date(2020, 4, 11), "0.0.4", Downloads(10)),
    ]
    assert project.versions() == {"0.0.6", "0.0.2", "0.0.4"}
    assert project.min_date == date(2020, 3, 9)
Esempio n. 5
0
def test_remove_old_data():
    project = Project(ProjectName("random"), Downloads(10))
    old_date = datetime.now().date() - timedelta(days=181)
    limit_date = datetime.now().date() - timedelta(days=180)
    now_date = datetime.now().date()
    project.add_downloads(old_date, "2.3.1", Downloads(10))
    project.add_downloads(limit_date, "2.3.0", Downloads(20))
    project.add_downloads(now_date, "2.3.2", Downloads(30))
    assert project.total_downloads == Downloads(70)
    assert project.last_downloads() == [
        ProjectVersionDownloads(limit_date, "2.3.0", Downloads(20)),
        ProjectVersionDownloads(now_date, "2.3.2", Downloads(30)),
    ]
    assert {"2.3.0", "2.3.2"}.issubset(project.versions())
Esempio n. 6
0
def test_add_downloads_to_project():
    project = Project(ProjectName("random"), Downloads(0))
    date = datetime.now().date()
    version = "2.3.1"
    day_downloads = Downloads(10)
    project.add_downloads(date, version, day_downloads)
    assert project.total_downloads == day_downloads
    assert project.last_downloads() == [
        ProjectVersionDownloads(date, version, day_downloads)
    ]
    assert project.versions() == {version}
Esempio n. 7
0
def test_project_replace_downloads():
    project = Project(ProjectName("random"), Downloads(10))
    date = datetime.now().date()
    version = "2.3.1"
    project.add_downloads(date, version, DayDownloads(25, 25))
    project.add_downloads(date, version, DayDownloads(5, 5))
    assert project.total_downloads == Downloads(15)
    assert project.last_downloads() == [
        ProjectVersionDownloads(date, version, Downloads(5), Downloads(5))
    ]
    assert project.versions() == {version}