Skip to content

Commit 97759a5

Browse files
authored
fix: bug fix for support qbd (minor fix) (#102)
* 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
1 parent e3bfbd2 commit 97759a5

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

.github/workflows/codecov.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
continue-on-error: true
1818
- name: Bring up Services and Run Tests
1919
run: |
20-
docker-compose -f docker-compose-pipeline.yml build
21-
docker-compose -f docker-compose-pipeline.yml up -d
22-
docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --cov-report=xml --cov-fail-under=97
20+
docker compose -f docker-compose-pipeline.yml build
21+
docker compose -f docker-compose-pipeline.yml up -d
22+
docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --cov-report=xml --cov-fail-under=97
2323
echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV
2424
echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV
2525
- name: Upload coverage reports to Codecov with GitHub Action

apps/mappings/connector.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,22 @@ def sync_projects(self, source_type: str):
112112
'order': 'updated_at.desc'
113113
}
114114
projects_generator = self.platform.v1beta.admin.projects.list_all(query)
115-
existing_projects = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)
116-
115+
existing_projects = QBDMapping.objects.filter(
116+
workspace_id=self.workspace_id,
117+
attribute_type=source_type).values_list('source_value', flat=True)
118+
117119
source_attributes = []
118120

119121
for projects in projects_generator:
120122
for project in projects.get('data'):
121123
if project['sub_project']:
122124
project['name'] = '{0} / {1}'.format(project['name'], project['sub_project'])
123-
if project['name'] not in existing_projects:
124-
source_attributes.append({
125-
'attribute_type': source_type,
126-
'value': project['name'],
127-
'source_id': project['id']
128-
})
129-
125+
if project['name'] not in existing_projects:
126+
source_attributes.append({
127+
'attribute_type': source_type,
128+
'value': project['name'],
129+
'source_id': project['id']
130+
})
130131

131132
if source_attributes:
132133
QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id)
@@ -139,20 +140,21 @@ def sync_cost_center(self, source_type: str):
139140
query = {
140141
'order': 'updated_at.desc'
141142
}
143+
142144
cost_center_generator = self.platform.v1beta.admin.cost_centers.list_all(query)
143-
existing_cost_centers = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)
145+
existing_cost_centers = QBDMapping.objects.filter(
146+
workspace_id=self.workspace_id,
147+
attribute_type=source_type).values_list('source_value', flat=True)
144148

145149
source_attributes = []
146-
147150
for cost_centers in cost_center_generator:
148151
for cost_center in cost_centers.get('data'):
149-
if cost_center not in existing_cost_centers:
152+
if cost_center['name'] not in existing_cost_centers:
150153
source_attributes.append({
151154
'attribute_type': source_type,
152-
'value': cost_center,
153-
'source_id': cost_center
155+
'value': cost_center['name'],
156+
'source_id': cost_center['id']
154157
})
155158

156-
157159
if source_attributes:
158160
QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id)

tests/test_mapping/test_connector.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ def test_sync_cost_center(create_temp_workspace, add_fyle_credentials, mocker):
5050
workspace_id = 1
5151
source_type = 'COST_CENTER'
5252
mock_response = [
53-
{'data': ['Cost Center 1', 'Cost Center 2']}
53+
{'data': [
54+
{
55+
'code': None,
56+
'created_at': '2024-07-29T12:30:58.972642+00:00',
57+
'description': 'Cost Center - RENT, Id - 1',
58+
'id': 24714,
59+
'is_enabled': True,
60+
'name': 'RENT',
61+
'org_id': 'orU77Fyqx0YH',
62+
'restricted_spender_user_ids': None,
63+
'updated_at': '2024-07-29T12:30:58.972644+00:00'
64+
}
65+
]}
5466
]
5567
mocker.patch(
5668
'fyle.platform.apis.v1beta.admin.cost_centers.list_all',
@@ -61,9 +73,7 @@ def test_sync_cost_center(create_temp_workspace, add_fyle_credentials, mocker):
6173
qbd_mappings = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type)
6274
assert len(qbd_mappings) == len(mock_response[0]['data'])
6375
for i, mapping in enumerate(qbd_mappings):
64-
cost_center = mock_response[0]['data'][i]
65-
assert mapping.source_value == cost_center
66-
76+
assert mapping.source_value == mock_response[0]['data'][i]['name']
6777

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

0 commit comments

Comments
 (0)