Skip to content

Commit

Permalink
fix: bug fix for support qbd (minor fix) (#102)
Browse files Browse the repository at this point in the history
* fix: bug fix for support qbd (minor fix)

* remove print

* fix indent issues

* some minor fixes for cost center

* fixtures updated

* fixed tests

* fixed few things basis on structure

* docker compose

* fixed minor indents and dicts

* updated test
  • Loading branch information
anishfyle authored Aug 5, 2024
1 parent e3bfbd2 commit 97759a5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
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:
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']
})


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

0 comments on commit 97759a5

Please sign in to comment.