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

feat: Add organizations array resolver on Account type #863

Merged
merged 5 commits into from
Oct 8, 2024

Conversation

spalmurray-codecov
Copy link
Contributor

Adds the paginated organizations array resolver on the Account type in the graphql API.

Closes codecov/engineering-team#2558

after: String
last: Int
before: String
): AccountOrganizationConnection! @cost(complexity: 25, multipliers: ["first", "last"])
Copy link
Contributor Author

@spalmurray-codecov spalmurray-codecov Oct 7, 2024

Choose a reason for hiding this comment

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

complexity is same as on user organizations list. Seems to make sense to keep things consistent. Have run this by Ajay

@spalmurray-codecov spalmurray-codecov marked this pull request as ready for review October 7, 2024 21:08
@spalmurray-codecov spalmurray-codecov requested a review from a team as a code owner October 7, 2024 21:08
@codecov-staging
Copy link

codecov-staging bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Oct 7, 2024

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
2455 4 2451 6
View the top 3 failed tests by shortest run time
api.internal.tests.test_charts.TestChartQueryRunnerQuery test_query_aggregates_multiple_repository_totals
Stack Traces | 0.071s run time
self = <tests.test_charts.TestChartQueryRunnerQuery testMethod=test_query_aggregates_multiple_repository_totals>

    @override_settings(GITHUB_CLIENT_ID="3d44be0e772666136a13")
    def test_query_aggregates_multiple_repository_totals(self):
        query_runner = ChartQueryRunner(
            user=self.user,
            request_params={
                "owner_username": self.org.username,
                "service": self.org.service,
                "end_date": str(timezone.now()),
                "grouping_unit": "day",
            },
        )
    
        results = query_runner.run_query()
    
        assert len(results) == 1
>       assert results[0]["total_hits"] == 114
E       AssertionError: assert Decimal('100') == 114

.../internal/tests/test_charts.py:564: AssertionError
graphql_api.tests.test_account.AccountTestCase test_fetch_organizations
Stack Traces | 0.413s run time
self = <graphql_api.tests.test_account.AccountTestCase testMethod=test_fetch_organizations>

    def test_fetch_organizations(self) -> None:
        for i in range(3):
            OwnerFactory(
                username=f"owner-{i}",
                plan_activated_users=[j for j in range(i)],
                account=self.account,
            )
    
        query = """
            query {
                owner(username: "%s") {
                    account {
                        organizations(first: 20) {
                            edges {
                                node {
                                    username
                                    activatedUserCount
                                }
                            }
                        }
                    }
                }
            }
        """ % (self.owner.username)
    
        result = self.gql_request(query, owner=self.owner)
    
        assert "errors" not in result
    
        orgs = [
            node["node"]["username"]
            for node in result["owner"]["account"]["organizations"]["edges"]
        ]
    
>       assert orgs == ["owner-2", "owner-1", "randomOwner", "owner-0"]
E       AssertionError: assert ['randomOwner...1', 'owner-0'] == ['owner-2', '...r', 'owner-0']
E         
E         At index 0 diff: 'randomOwner' != 'owner-2'
E         Use -v to get more diff

graphql_api/tests/test_account.py:119: AssertionError
graphql_api.tests.test_account.AccountTestCase test_fetch_organizations_pagination
Stack Traces | 0.416s run time
self = <graphql_api.tests.test_account.AccountTestCase testMethod=test_fetch_organizations_pagination>

    def test_fetch_organizations_pagination(self) -> None:
        for i in range(3):
            OwnerFactory(
                username=f"owner-{i}",
                plan_activated_users=[j for j in range(i)],
                account=self.account,
            )
    
        query = """
            query {
                owner(username: "%s") {
                    account {
                        organizations(first: 2) {
                            edges {
                                node {
                                    username
                                    activatedUserCount
                                }
                            }
                            totalCount
                            pageInfo {
                                hasNextPage
                            }
                        }
                    }
                }
            }
        """ % (self.owner.username)
    
        result = self.gql_request(query, owner=self.owner)
    
        assert "errors" not in result
    
        totalCount = result["owner"]["account"]["organizations"]["totalCount"]
    
        assert totalCount == 4
    
        orgs = [
            node["node"]["username"]
            for node in result["owner"]["account"]["organizations"]["edges"]
        ]
    
>       assert orgs == ["owner-2", "owner-1"]
E       AssertionError: assert ['randomOwner', 'owner-2'] == ['owner-2', 'owner-1']
E         
E         At index 0 diff: 'randomOwner' != 'owner-2'
E         Use -v to get more diff

graphql_api/tests/test_account.py:271: AssertionError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

Copy link

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2461 tests with 4 failed, 2451 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: api.internal.tests.test_charts.TestChartQueryRunnerQuery
    Test name: test_query_aggregates_multiple_repository_totals

    self = <tests.test_charts.TestChartQueryRunnerQuery testMethod=test_query_aggregates_multiple_repository_totals>

    @override_settings(GITHUB_CLIENT_ID="3d44be0e772666136a13")
    def test_query_aggregates_multiple_repository_totals(self):
    query_runner = ChartQueryRunner(
    user=self.user,
    request_params={
    "owner_username": self.org.username,
    "service": self.org.service,
    "end_date": str(timezone.now()),
    "grouping_unit": "day",
    },
    )

    results = query_runner.run_query()

    assert len(results) == 1
    > assert results[0]["total_hits"] == 114
    E AssertionError: assert Decimal('100') == 114

    .../internal/tests/test_charts.py:564: AssertionError
  • Class name: graphql_api.tests.test_account.AccountTestCase
    Test name: test_fetch_organizations

    self = <graphql_api.tests.test_account.AccountTestCase testMethod=test_fetch_organizations>

    def test_fetch_organizations(self) -> None:
    for i in range(3):
    OwnerFactory(
    username=f"owner-{i}",
    plan_activated_users=[j for j in range(i)],
    account=self.account,
    )

    query = """
    query {
    owner(username: "%s") {
    account {
    organizations(first: 20) {
    edges {
    node {
    username
    activatedUserCount
    }
    }
    }
    }
    }
    }
    """ % (self.owner.username)

    result = self.gql_request(query, owner=self.owner)

    assert "errors" not in result

    orgs = [
    node["node"]["username"]
    for node in result["owner"]["account"]["organizations"]["edges"]
    ]

    > assert orgs == ["owner-2", "owner-1", "randomOwner", "owner-0"]
    E AssertionError: assert ['randomOwner...1', 'owner-0'] == ['owner-2', '...r', 'owner-0']
    E
    E At index 0 diff: 'randomOwner' != 'owner-2'
    E Use -v to get more diff

    graphql_api/tests/test_account.py:119: AssertionError
  • Class name: graphql_api.tests.test_account.AccountTestCase
    Test name: test_fetch_organizations_order_by_activated_users_asc

    self = <graphql_api.tests.test_account.AccountTestCase testMethod=test_fetch_organizations_order_by_activated_users_asc>

    def test_fetch_organizations_order_by_activated_users_asc(self) -> None:
    for i in range(3):
    OwnerFactory(
    username=f"owner-{i}",
    plan_activated_users=[j for j in range(i)],
    account=self.account,
    )

    query = """
    query {
    owner(username: "%s") {
    account {
    organizations(first: 20, ordering: ACTIVATED_USERS, orderingDirection: ASC) {
    edges {
    node {
    username
    activatedUserCount
    }
    }
    }
    }
    }
    }
    """ % (self.owner.username)

    result = self.gql_request(query, owner=self.owner)

    assert "errors" not in result

    orgs = [
    node["node"]["username"]
    for node in result["owner"]["account"]["organizations"]["edges"]
    ]

    > assert orgs == ["randomOwner", "owner-0", "owner-1", "owner-2"]
    E AssertionError: assert ['owner-0', '...'randomOwner'] == ['randomOwner...1', 'owner-2']
    E
    E At index 0 diff: 'owner-0' != 'randomOwner'
    E Use -v to get more diff

    graphql_api/tests/test_account.py:155: AssertionError
  • Class name: graphql_api.tests.test_account.AccountTestCase
    Test name: test_fetch_organizations_pagination

    self = <graphql_api.tests.test_account.AccountTestCase testMethod=test_fetch_organizations_pagination>

    def test_fetch_organizations_pagination(self) -> None:
    for i in range(3):
    OwnerFactory(
    username=f"owner-{i}",
    plan_activated_users=[j for j in range(i)],
    account=self.account,
    )

    query = """
    query {
    owner(username: "%s") {
    account {
    organizations(first: 2) {
    edges {
    node {
    username
    activatedUserCount
    }
    }
    totalCount
    pageInfo {
    hasNextPage
    }
    }
    }
    }
    }
    """ % (self.owner.username)

    result = self.gql_request(query, owner=self.owner)

    assert "errors" not in result

    totalCount = result["owner"]["account"]["organizations"]["totalCount"]

    assert totalCount == 4

    orgs = [
    node["node"]["username"]
    for node in result["owner"]["account"]["organizations"]["edges"]
    ]

    > assert orgs == ["owner-2", "owner-1"]
    E AssertionError: assert ['randomOwner', 'owner-2'] == ['owner-2', 'owner-1']
    E
    E At index 0 diff: 'randomOwner' != 'owner-2'
    E Use -v to get more diff

    graphql_api/tests/test_account.py:271: AssertionError

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.34%. Comparing base (b6b028c) to head (5eece3c).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #863   +/-   ##
=======================================
  Coverage   96.34%   96.34%           
=======================================
  Files         823      823           
  Lines       19157    19163    +6     
=======================================
+ Hits        18457    18463    +6     
  Misses        700      700           
Flag Coverage Δ
unit 92.71% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 92.71% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.



__all__ = ["get_current_license", "account_bindable"]
__all__ = ["get_current_license", "account_bindable", "account"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this in a lot of GQL files but idk if we actually need get_current_license here, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right lol. I removed the unnecessary instances and tests are all green.

):
return queryset_to_connection(
account.organizations,
ordering=(ordering,),
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need the tuple here for ordering? vs ordering=ordering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we do. Not sure exactly how this works under the hood, but the queryset_to_connection helper does a for field in ordering. Some other calls do pass multiple values in the tuple, so seems like there's a reason for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it 👌 Thanks for clarifying!

def resolve_organizations(
account: Account,
info: GraphQLResolveInfo,
ordering=AccountOrganizationOrdering.ACTIVATED_USERS,
Copy link
Contributor

Choose a reason for hiding this comment

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

just to confirm, default ordering is by plan_activated_users in descending order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

@spalmurray-codecov spalmurray-codecov force-pushed the spalmurray/account-organizations branch from 6e72268 to 79e22d2 Compare October 8, 2024 14:02
Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

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

send it ✅

@spalmurray-codecov spalmurray-codecov added this pull request to the merge queue Oct 8, 2024
Merged via the queue into main with commit 3f4c348 Oct 8, 2024
18 of 19 checks passed
@spalmurray-codecov spalmurray-codecov deleted the spalmurray/account-organizations branch October 8, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API] Implement organizations resolver on Account
2 participants