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

fix: bug fix for support qbd (minor fix) #102

Merged
merged 10 commits into from
Aug 5, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
continue-on-error: true
- name: Bring up Services and Run Tests
run: |
docker-compose -f docker-compose-pipeline.yml build
docker-compose -f docker-compose-pipeline.yml up -d
docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --cov-report=xml --cov-fail-under=97
docker compose -f docker-compose-pipeline.yml build
docker compose -f docker-compose-pipeline.yml up -d
docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --cov-report=xml --cov-fail-under=97
echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV
echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV
- name: Upload coverage reports to Codecov with GitHub Action
Expand Down
32 changes: 17 additions & 15 deletions apps/mappings/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,22 @@ def sync_projects(self, source_type: str):
'order': 'updated_at.desc'
}
projects_generator = self.platform.v1beta.admin.projects.list_all(query)
existing_projects = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)

existing_projects = QBDMapping.objects.filter(
workspace_id=self.workspace_id,
attribute_type=source_type).values_list('source_value', flat=True)

source_attributes = []

for projects in projects_generator:
for project in projects.get('data'):
if project['sub_project']:
project['name'] = '{0} / {1}'.format(project['name'], project['sub_project'])
if project['name'] not in existing_projects:
source_attributes.append({
'attribute_type': source_type,
'value': project['name'],
'source_id': project['id']
})

if project['name'] not in existing_projects:
anishfyle marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

indent fixed

source_attributes.append({
'attribute_type': source_type,
'value': project['name'],
'source_id': project['id']
})

if source_attributes:
QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id)
Expand All @@ -139,20 +140,21 @@ def sync_cost_center(self, source_type: str):
query = {
'order': 'updated_at.desc'
}

cost_center_generator = self.platform.v1beta.admin.cost_centers.list_all(query)
existing_cost_centers = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)
existing_cost_centers = QBDMapping.objects.filter(
workspace_id=self.workspace_id,
attribute_type=source_type).values_list('source_value', flat=True)

source_attributes = []

for cost_centers in cost_center_generator:
for cost_center in cost_centers.get('data'):
if cost_center not in existing_cost_centers:
if cost_center['name'] not in existing_cost_centers:
source_attributes.append({
'attribute_type': source_type,
'value': cost_center,
'source_id': cost_center
'value': cost_center['name'],
'source_id': cost_center['id']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

name and id went missing, in concurrent prs, fixed this

})


if source_attributes:
QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id)
18 changes: 14 additions & 4 deletions tests/test_mapping/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ def test_sync_cost_center(create_temp_workspace, add_fyle_credentials, mocker):
workspace_id = 1
source_type = 'COST_CENTER'
mock_response = [
{'data': ['Cost Center 1', 'Cost Center 2']}
{'data': [
{
'code': None,
'created_at': '2024-07-29T12:30:58.972642+00:00',
'description': 'Cost Center - RENT, Id - 1',
'id': 24714,
'is_enabled': True,
'name': 'RENT',
'org_id': 'orU77Fyqx0YH',
'restricted_spender_user_ids': None,
'updated_at': '2024-07-29T12:30:58.972644+00:00'
}
]}
]
mocker.patch(
'fyle.platform.apis.v1beta.admin.cost_centers.list_all',
Expand All @@ -61,9 +73,7 @@ def test_sync_cost_center(create_temp_workspace, add_fyle_credentials, mocker):
qbd_mappings = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type)
assert len(qbd_mappings) == len(mock_response[0]['data'])
for i, mapping in enumerate(qbd_mappings):
cost_center = mock_response[0]['data'][i]
assert mapping.source_value == cost_center

assert mapping.source_value == mock_response[0]['data'][i]['name']

@pytest.mark.django_db(databases=['default'], transaction=True)
def test_sync_custom_field(mocker, api_client, test_connection):
Expand Down
Loading