Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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"]
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
    ImportDownloadsFile,
    ImportDownloadsFileHandler,
    UpdateDownloads,
    UpdateDownloadsHandler,
)
from pepy.application.helper import AdminPasswordChecker
from pepy.application.query import BadgeProvider, ProjectProvider, DownloadsNumberFormatter
from pepy.domain.model import HashedPassword
from pepy.infrastructure.bq_downloads_extractor import BQDownloadsExtractor
from pepy.infrastructure.db_repository import DBProjectRepository
from pepy.infrastructure.db_view import DBProjectView
from ._config import DATABASE, BQ_CREDENTIALS_FILE, ADMIN_PASSWORD, LOGGING_FILE, DATABASE_ORATOR, LOGGING_DIR

db_connection = psycopg2.connect(**DATABASE)
db_orator = DatabaseManager(DATABASE_ORATOR)
project_repository = DBProjectRepository(db_connection)
db_project_view = DBProjectView(db_orator)
command_bus = CommandBus()
command_bus.subscribe(ImportDownloadsFile,
                      ImportDownloadsFileHandler(project_repository))
downloads_formatter = DownloadsNumberFormatter()
badge_query = BadgeProvider(db_project_view, downloads_formatter)
project_provider = ProjectProvider(db_project_view)

# Directories configuration
if not os.path.exists(LOGGING_DIR):
    os.makedirs(LOGGING_DIR)

# Logger configuration
logger = logging.getLogger("pepy")
logger.setLevel(logging.INFO)
Exemplo n.º 7
0
def project_repository():
    conn = container.db_connection
    with conn.cursor() as cursor:
        cursor.execute("TRUNCATE TABLE projects CASCADE")
    yield DBProjectRepository(conn)
Exemplo n.º 8
0
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)