Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #549

Closed
wants to merge 1 commit into from
Closed

WIP #549

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def db(engine, sqlalchemy_connect_url):
Base.metadata.create_all(engine)


@pytest.fixture(scope="session")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixture to avoid django trying to recreate a DB and instead pointing to the preexisting DB

def django_db_setup():
from django.conf import settings

settings.DATABASES["default"]["NAME"] = "background_test"


@pytest.fixture
def dbsession(db, engine):
connection = engine.connect()
Expand Down
31 changes: 31 additions & 0 deletions database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def validate_external_id(self, key, value):
return value


class Account(object):
# __tablename__ = "codecov_auth_account"
id_ = Column("id", types.BigInteger, primary_key=True)
name = Column(types.String(100), server_default=FetchedValue())


class Owner(CodecovBaseModel):
__tablename__ = "owners"
ownerid = Column(types.Integer, primary_key=True)
Expand Down Expand Up @@ -105,6 +111,31 @@ class Owner(CodecovBaseModel):
passive_deletes=True,
)

business_email = Column(types.Text, server_default=FetchedValue())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing fields from SQLAlchemy model compared to it's Django counterpart

stripe_coupon_id = Column(types.Text, server_default=FetchedValue())
root_parent_service_id = Column(types.Text, server_default=FetchedValue())
private_access = Column(types.Boolean, server_default=FetchedValue())
staff = Column(types.Boolean, server_default=FetchedValue())
cache = Column(postgresql.JSON, server_default=FetchedValue())
did_trial = Column(types.Boolean, server_default=FetchedValue())
invoice_details = Column(types.Text, server_default=FetchedValue())
uses_invoice = Column(types.Boolean, server_default=FetchedValue())
delinquent = Column(types.Boolean, server_default=FetchedValue())
student = Column(types.Boolean, server_default=FetchedValue())
student_created_at = Column(types.DateTime, server_default=FetchedValue())
student_updated_at = Column(types.DateTime, server_default=FetchedValue())
is_superuser = Column(types.Boolean, server_default=FetchedValue())
max_upload_limit = Column(types.Integer, server_default=FetchedValue())
sentry_user_id = Column(types.Text, server_default=FetchedValue())
sentry_user_data = Column(postgresql.JSON, server_default=FetchedValue())
# ownerid = Column(types.Integer, ForeignKey("owners.ownerid"))
user_id = Column(types.Integer, ForeignKey("users.id"))
user = relationship(User, foreign_keys=[user_id])

account_id = Column(types.Integer, server_default=FetchedValue())
# account_id = Column(types.Integer, ForeignKey("account.id"))
# account = relationship(Account, foreign_keys=[account_id])

# TODO: Create association between `User` and `Owner` mirroring `codecov-api`
# https://github.com/codecov/codecov-api/blob/204f7fd7e37896efe0259e4bc91aad20601087e0/codecov_auth/models.py#L196-L202

Expand Down
4 changes: 3 additions & 1 deletion services/owner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging

import shared.torngit as torngit

# from services.bots import get_adapter_auth_information
from shared.bots import get_adapter_auth_information
from shared.config import get_config, get_verify_ssl
from shared.django_apps.codecov_auth.models import Service
from shared.typings.torngit import (
Expand All @@ -9,7 +12,6 @@
)

from helpers.token_refresh import get_token_refresh_callback
from services.bots import get_adapter_auth_information

log = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions services/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from typing import Any, Mapping, Optional, Tuple

import shared.torngit as torngit
from shared.bots import (
get_adapter_auth_information,
)
from shared.config import get_config, get_verify_ssl
from shared.django_apps.codecov_auth.models import Service
from shared.torngit.exceptions import (
Expand All @@ -25,9 +28,6 @@
GITHUB_APP_INSTALLATION_DEFAULT_NAME,
)
from helpers.token_refresh import get_token_refresh_callback
from services.bots import (
get_adapter_auth_information,
)
from services.bots.github_apps import (
get_github_app_token,
get_specific_github_app_details,
Expand Down
11 changes: 5 additions & 6 deletions tasks/tests/unit/test_sync_repos_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,9 @@ def repo_obj(service_id, name, language, private, branch, using_integration):

mocked_app.tasks[sync_repo_languages_task_name].apply_async.assert_not_called()

@pytest.mark.django_db(databases={"default"})
def test_sync_repos_using_integration_affected_repos_known(
self,
mocker,
dbsession,
mock_owner_provider,
mock_redis,
self, mocker, dbsession, mock_owner_provider, mock_redis, engine
):
user = OwnerFactory.create(
organizations=[],
Expand All @@ -946,7 +943,6 @@ def test_sync_repos_using_integration_affected_repos_known(
service_id="45343385",
)
dbsession.add(user)

mocked_app = mocker.patch.object(
SyncRepoLanguagesGQLTask,
"app",
Expand Down Expand Up @@ -1044,6 +1040,9 @@ async def side_effect(*args, **kwargs):
mock_owner_provider.get_repos_from_nodeids_generator.side_effect = side_effect
mock_owner_provider.service = "github"

print("le query", dbsession.query(Owner).all())
print("le engineee", engine.__dict__)

SyncReposTask().run_impl(
dbsession,
ownerid=user.ownerid,
Expand Down
Loading