diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 3b4fbe9..18a90d4 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -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 diff --git a/apps/mappings/connector.py b/apps/mappings/connector.py index b9c9477..734ddcd 100644 --- a/apps/mappings/connector.py +++ b/apps/mappings/connector.py @@ -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) @@ -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) \ No newline at end of file diff --git a/tests/test_mapping/test_connector.py b/tests/test_mapping/test_connector.py index aaf4441..7e771b8 100644 --- a/tests/test_mapping/test_connector.py +++ b/tests/test_mapping/test_connector.py @@ -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', @@ -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):