예제 #1
0
def test_downloads_format_quadrillion(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(11_132_919_492_432_000)
    assert "11P" == downloads_formatter.format(downloads)
예제 #2
0
def downloads_formatter():
    return DownloadsNumberFormatter()
예제 #3
0
def test_downloads_format_million(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(412_132_492)
    assert "412M" == downloads_formatter.format(downloads)
예제 #4
0
def test_downloads_format_billion(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(9_132_919_492)
    assert "9G" == downloads_formatter.format(downloads)
예제 #5
0
def test_downloads_format_less_than_thousands(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(121)
    assert "121" == downloads_formatter.format(downloads)
예제 #6
0
def test_downloads_format_thousands(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(12132)
    assert "12k" == downloads_formatter.format(downloads)
예제 #7
0
def test_downloads_format_with_abbreviation_quadrillion(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(11_132_919_492_432_000)
    assert "11Q" == downloads_formatter.format_with_units(
        downloads, BadgeUnits.abbreviation)
예제 #8
0
def test_downloads_format_0(downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(0)
    assert "0" == downloads_formatter.format(downloads)
예제 #9
0
def test_downloads_format_with_abbreviation_billion(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(9_132_919_492)
    assert "9B" == downloads_formatter.format_with_units(
        downloads, BadgeUnits.abbreviation)
예제 #10
0
def test_downloads_format_with_abbreviation_million(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(412_132_492)
    assert "412M" == downloads_formatter.format_with_units(
        downloads, BadgeUnits.abbreviation)
예제 #11
0
def test_downloads_format_with_abbreviation_thousands(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(12132)
    assert "12k" == downloads_formatter.format_with_units(
        downloads, BadgeUnits.abbreviation)
예제 #12
0
def test_downloads_format_with_abbreviation_0(
        downloads_formatter: DownloadsNumberFormatter):
    downloads = Downloads(0)
    assert "0" == downloads_formatter.format_with_units(
        downloads, BadgeUnits.abbreviation)
예제 #13
0
file_handler = logging.FileHandler(LOGGING_FILE)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
mongo_client = MongoClient(MONGODB)

if environment == Environment.test:
    project_repository = MongoProjectRepository(mongo_client.pepy_test)
else:
    project_repository = MongoProjectRepository(mongo_client.pepy)

bq_client = None
if environment == Environment.prod:
    bq_client = bigquery.Client.from_service_account_json(BQ_CREDENTIALS_FILE)

if environment == Environment.test:
    stats_viewer = MockStatsViewer()
else:
    stats_viewer = BQStatsViewer(bq_client)

admin_password_checker = AdminPasswordChecker(HashedPassword(ADMIN_PASSWORD))
command_bus = CommandBus()
command_bus.subscribe(
    UpdateVersionDownloads,
    UpdateVersionDownloadsHandler(project_repository, stats_viewer,
                                  admin_password_checker, logger),
)
command_bus.subscribe(ImportTotalDownloads,
                      ImportTotalDownloadsHandler(project_repository, logger))
downloads_formatter = DownloadsNumberFormatter()
badge_service = BadgeService(project_repository, downloads_formatter)