Skip to content

Commit

Permalink
LITE-30341 Fix filtering customer list report by tier type
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatrios committed Aug 2, 2024
1 parent 6cb6376 commit 69016a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
14 changes: 12 additions & 2 deletions reports/customers_list/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
'Extended Information',
)

TIER_TYPE = {
'customer': ['customer'],
'reseller': ['tier1', 'tier2'],
}


def generate(
client=None,
Expand Down Expand Up @@ -55,8 +60,13 @@ def _get_customers(client, parameters):
query &= R().events.created.at.ge(parameters['date']['after'])
query &= R().events.created.at.le(parameters['date']['before'])
if parameters.get('tier_type') and parameters['tier_type']['all'] is False:
query &= R().scopes.oneof(parameters['tier_type']['choices'])

# (tier1 or tier2) and customer in choices -> all (no RLQ filter for tier_type)
# one or both of tier1/2 in choices -> R().type.eq('reseller')
# only customer in choices -> R().type.eq('customer')
parameter_choices = set(parameters['tier_type']['choices'])
for t_type, choices in TIER_TYPE.items():
if not parameter_choices.difference(choices):
query &= R().type.eq(t_type)
return client.ns('tier').accounts.filter(query).order_by('-events.created.at').limit(1000)


Expand Down
28 changes: 25 additions & 3 deletions tests/test_customer_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Copyright (c) 2023, CloudBlue
# All rights reserved.
#
import copy

import pytest

from reports.customers_list.entrypoint import (
generate,
Expand All @@ -18,14 +21,30 @@
}


@pytest.mark.parametrize(
'parameter_choices,expected_rql',
(
({'choices': ['customer']}, ',eq(type,customer)'),
({'choices': ['tier1']}, ',eq(type,reseller)'),
({'choices': ['tier2']}, ',eq(type,reseller)'),
({'choices': ['tier2', 'tier1']}, ',eq(type,reseller)'),
({'choices': ['customer', 'tier1']}, ''),
({'choices': ['customer', 'tier2']}, ''),
),
)
def test_generate(
progress,
client_factory,
response_factory,
mkp_list,
ta_list,
tier_account,
parameter_choices,
expected_rql,
):
parameters = copy.deepcopy(PARAMETERS)
parameters['tier_type'] = {**parameter_choices, 'all': False}
responses = []
responses.append(
response_factory(
Expand All @@ -37,10 +56,13 @@ def test_generate(
count=1,
),
)
ta_list_query = (
'and(ge(events.created.at,2020-12-01T00:00:00),le(events.created.at,'
'2021-01-01T00:00:00){0})'
)
responses.append(
response_factory(
query='and(ge(events.created.at,2020-12-01T00:00:00),le(events.created.at,'
'2021-01-01T00:00:00))',
query=ta_list_query.format(expected_rql),
value=ta_list,
),
)
Expand All @@ -50,7 +72,7 @@ def test_generate(
),
)
client = client_factory(responses)
result = list(generate(client, PARAMETERS, progress))
result = list(generate(client, parameters, progress))

assert len(result) == 1
i = 0
Expand Down

0 comments on commit 69016a1

Please sign in to comment.