diff --git a/djautotask/api.py b/djautotask/api.py index f8186f9..77d2228 100644 --- a/djautotask/api.py +++ b/djautotask/api.py @@ -721,15 +721,15 @@ class ContractsAPIClient(AutotaskAPIClient): API = 'Contracts' -class ContractExclusionSetsAPIClient(AutotaskAPIClient): +class ContractExclusionSetAPIClient(AutotaskAPIClient): API = 'ContractExclusionSets' -class ContractsExcludedWorkTypesAPIClient(AutotaskAPIClient): +class ContractsExcludedWorkTypeAPIClient(AutotaskAPIClient): API = 'ContractExclusionSetExcludedWorkTypes' -class ContractsExcludedRolesAPIClient(AutotaskAPIClient): +class ContractsExcludedRoleAPIClient(AutotaskAPIClient): API = 'ContractExclusionSetExcludedRoles' diff --git a/djautotask/management/commands/atsync.py b/djautotask/management/commands/atsync.py index 1547c5c..d0d4035 100644 --- a/djautotask/management/commands/atsync.py +++ b/djautotask/management/commands/atsync.py @@ -140,7 +140,7 @@ def __init__(self, *args, **kwargs): _('Contract Exclusion Set') ), ( - 'contract_excluded_worktype', + 'contract_excluded_work_type', sync.ContractExcludedWorkTypeSynchronizer, _('Contract Excluded Work Type') ), diff --git a/djautotask/migrations/0118_contractexclusionset_and_more.py b/djautotask/migrations/0118_contractexclusionset_and_more.py index c7b2bd0..19796be 100644 --- a/djautotask/migrations/0118_contractexclusionset_and_more.py +++ b/djautotask/migrations/0118_contractexclusionset_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.16 on 2024-10-25 15:25 +# Generated by Django 4.2.16 on 2024-10-30 23:14 from django.db import migrations, models import django.db.models.deletion @@ -52,28 +52,28 @@ class Migration(migrations.Migration): field=models.ManyToManyField(related_name='excluded_work_type_sets', through='djautotask.ContractExclusionSetExcludedWorkType', to='djautotask.billingcode'), ), migrations.CreateModel( - name='ContractExcludedWorkTypeTracker', + name='ContractExcludedRoleTracker', fields=[ ], options={ - 'db_table': 'djautotask_contractexclusionsetworktype', + 'db_table': 'djautotask_contractexclusionsetrole', 'proxy': True, 'indexes': [], 'constraints': [], }, - bases=('djautotask.contractexclusionsetexcludedworktype',), + bases=('djautotask.contractexclusionsetexcludedrole',), ), migrations.CreateModel( - name='ContractExcludeRoleTracker', + name='ContractExcludedWorkTypeTracker', fields=[ ], options={ - 'db_table': 'djautotask_contractexclusionsetrole', + 'db_table': 'djautotask_contractexclusionsetworktype', 'proxy': True, 'indexes': [], 'constraints': [], }, - bases=('djautotask.contractexclusionsetexcludedrole',), + bases=('djautotask.contractexclusionsetexcludedworktype',), ), migrations.CreateModel( name='ContractExclusionSetTracker', diff --git a/djautotask/models.py b/djautotask/models.py index d84213a..92397bf 100644 --- a/djautotask/models.py +++ b/djautotask/models.py @@ -986,10 +986,7 @@ class ContractExclusionSetExcludedWorkType(models.Model): on_delete=models.CASCADE) def __str__(self): - return ( - f"{self.contract_exclusion_set.name} - " - f"{self.excluded_work_type.name}" - ) + return str(self.id) or '' class ContractExclusionSetExcludedRole(models.Model): @@ -998,10 +995,7 @@ class ContractExclusionSetExcludedRole(models.Model): excluded_role = models.ForeignKey('Role', on_delete=models.CASCADE) def __str__(self): - return ( - f"{self.contract_exclusion_set.name} - " - f"{self.excluded_work_type.name}" - ) + return str(self.id) or '' class ServiceCall(TimeStampedModel): @@ -1523,7 +1517,7 @@ class Meta: db_table = 'djautotask_contractexclusionsetworktype' -class ContractExcludeRoleTracker(ContractExclusionSetExcludedRole): +class ContractExcludedRoleTracker(ContractExclusionSetExcludedRole): tracker = FieldTracker() class Meta: diff --git a/djautotask/sync.py b/djautotask/sync.py index d1e38d6..df120ef 100644 --- a/djautotask/sync.py +++ b/djautotask/sync.py @@ -2033,7 +2033,7 @@ def active_ids(self): class ContractExclusionSetSynchronizer(Synchronizer): - client_class = api.ContractExclusionSetsAPIClient + client_class = api.ContractExclusionSetAPIClient model_class = models.ContractExclusionSetTracker last_updated_field = None @@ -2047,7 +2047,7 @@ def _assign_field_data(self, instance, object_data): class ContractExcludedWorkTypeSynchronizer(BatchQueryMixin, Synchronizer): - client_class = api.ContractsExcludedWorkTypesAPIClient + client_class = api.ContractsExcludedWorkTypeAPIClient model_class = models.ContractExcludedWorkTypeTracker condition_field_name = 'contractExclusionSetID' last_updated_field = None @@ -2075,8 +2075,8 @@ def active_ids(self): class ContractExcludedRoleSynchronizer(BatchQueryMixin, Synchronizer): - client_class = api.ContractsExcludedRolesAPIClient - model_class = models.ContractExcludeRoleTracker + client_class = api.ContractsExcludedRoleAPIClient + model_class = models.ContractExcludedRoleTracker condition_field_name = 'contractExclusionSetID' last_updated_field = None diff --git a/djautotask/tests/fixture_utils.py b/djautotask/tests/fixture_utils.py index d9f2b30..eaa3d97 100644 --- a/djautotask/tests/fixture_utils.py +++ b/djautotask/tests/fixture_utils.py @@ -339,26 +339,26 @@ def init_contracts(): return synchronizer.sync() -def init_contracts_exclusion_sets(): +def init_contract_exclusion_sets(): models.ContractExclusionSet.objects.all().delete() - mocks.service_api_get_contracts_exclusions_sets_call( + mocks.service_api_get_contract_exclusion_sets_call( fixtures.API_CONTRACT_EXCLUSION_SET) synchronizer = sync.ContractExclusionSetSynchronizer() return synchronizer.sync() -def init_contracts_exclusion_roles(): +def init_contract_exclusion_roles(): models.ContractExclusionSetExcludedRole.objects.all() \ .delete() - mocks.service_api_get_contracts_excluded_roles_call( + mocks.service_api_get_contract_excluded_roles_call( fixtures.API_CONTRACT_EXCLUSION_ROLE) synchronizer = sync.ContractExcludedRoleSynchronizer() return synchronizer.sync() -def init_contracts_exlusion_work_types(): +def init_contract_exclusion_work_types(): models.ContractExclusionSetExcludedWorkType.objects.all().delete() - mocks.service_api_get_contracts_excluded_work_types_call( + mocks.service_api_get_contract_excluded_work_types_call( fixtures.API_CONTRACT_EXCLUSION_WORK_TYPE) synchronizer = sync.ContractExcludedWorkTypeSynchronizer() return synchronizer.sync() diff --git a/djautotask/tests/fixtures.py b/djautotask/tests/fixtures.py index aee27f6..da2df96 100644 --- a/djautotask/tests/fixtures.py +++ b/djautotask/tests/fixtures.py @@ -1463,7 +1463,7 @@ API_CONTRACT_EXCLUSION_ROLE_ITEM = { "id": 1, "contractExclusionSetID": 1, - "excludedRoleID": 29683399 + "excludedRoleID": 8 } API_CONTRACT_EXCLUSION_ROLE_ITEMS = [API_CONTRACT_EXCLUSION_ROLE_ITEM] API_CONTRACT_EXCLUSION_ROLE = { @@ -1475,7 +1475,7 @@ API_CONTRACT_EXCLUSION_WORK_TYPE_ITEM = { "id": 1, "contractExclusionSetID": 1, - "excludedWorkTypeID": 2968341 + "excludedWorkTypeID": 2 } API_CONTRACT_EXCLUSION_WORK_TYPE_ITEMS = [API_CONTRACT_EXCLUSION_WORK_TYPE_ITEM] API_CONTRACT_EXCLUSION_WORK_TYPE = { diff --git a/djautotask/tests/mocks.py b/djautotask/tests/mocks.py index d94da20..1cac0ab 100644 --- a/djautotask/tests/mocks.py +++ b/djautotask/tests/mocks.py @@ -59,18 +59,18 @@ def service_api_get_contracts_call(return_value): return create_mock_call(method_name, return_value) -def service_api_get_contracts_exclusions_sets_call(return_value): - method_name = 'djautotask.api.ContractExclusionSetsAPIClient.get' +def service_api_get_contract_exclusion_sets_call(return_value): + method_name = 'djautotask.api.ContractExclusionSetAPIClient.get' return create_mock_call(method_name, return_value) -def service_api_get_contracts_excluded_roles_call(return_value): - method_name = 'djautotask.api.ContractsExcludedRolesAPIClient.get' +def service_api_get_contract_excluded_roles_call(return_value): + method_name = 'djautotask.api.ContractsExcludedRoleAPIClient.get' return create_mock_call(method_name, return_value) -def service_api_get_contracts_excluded_work_types_call(return_value): - method_name = 'djautotask.api.ContractsExcludedWorkTypesAPIClient.get' +def service_api_get_contract_excluded_work_types_call(return_value): + method_name = 'djautotask.api.ContractsExcludedWorkTypeAPIClient.get' return create_mock_call(method_name, return_value) diff --git a/djautotask/tests/test_commands.py b/djautotask/tests/test_commands.py index 689f7d8..22fd9cc 100644 --- a/djautotask/tests/test_commands.py +++ b/djautotask/tests/test_commands.py @@ -613,38 +613,43 @@ def setUp(self): class TestSyncContractExclusionSetCommand(AbstractBaseSyncTest, TestCase): args = ( - mocks.service_api_get_contracts_exclusions_sets_call, + mocks.service_api_get_contract_exclusion_sets_call, fixtures.API_CONTRACT_EXCLUSION_SET, 'contract_exclusion_set', ) def setUp(self): super().setUp() + fixture_utils.init_contract_exclusion_sets() class TestSyncContractExclusionRoleCommand(AbstractBaseSyncTest, TestCase): args = ( - mocks.service_api_get_contracts_excluded_roles_call, + mocks.service_api_get_contract_excluded_roles_call, fixtures.API_CONTRACT_EXCLUSION_ROLE, - 'contract_exclusion_role', + 'contract_excluded_role', ) def setUp(self): super().setUp() - fixture_utils.init_contracts_exclusion_sets() + fixture_utils.init_roles() + fixture_utils.init_contract_exclusion_sets() + fixture_utils.init_contract_exclusion_roles() class TestSyncContractExclusionWorkTypeCommand(AbstractBaseSyncTest, TestCase): args = ( - mocks.service_api_get_contracts_excluded_work_types_call, + mocks.service_api_get_contract_excluded_work_types_call, fixtures.API_CONTRACT_EXCLUSION_WORK_TYPE, - 'contract_exclusion_work_type', + 'contract_excluded_work_type', ) def setUp(self): super().setUp() - fixture_utils.init_contracts_exclusion_sets() + fixture_utils.init_billing_codes() + fixture_utils.init_contract_exclusion_sets() + fixture_utils.init_contract_exclusion_work_types() class TestSyncServiceCallCommand(AbstractBaseSyncTest, TestCase): @@ -908,9 +913,9 @@ def test_full_sync(self): 'contact': models.Contact, 'company_alert': models.CompanyAlert, 'contract_exclusion_set': models.ContractExclusionSet, - 'contract_exclusion_role': + 'contract_excluded_role': models.ContractExclusionSetExcludedRole, - 'contract_exclusion_work_type': + 'contract_excluded_work_type': models.ContractExclusionSetExcludedWorkType, } run_sync_command() @@ -935,9 +940,8 @@ def test_full_sync(self): 'task_predecessor', 'task', 'time_entry', - 'contract_exclusion_set', - 'contract_exclusion_role', - 'contract_exclusion_work_type', + 'contract_excluded_role', + 'contract_excluded_work_type', ): # Assert that there were objects to get deleted, then change # to zero to verify the output formats correctly. @@ -1018,14 +1022,14 @@ def _call_service_api(self): fixtures.API_TASK_PREDECESSOR) mocks.service_api_get_company_alerts_call( fixtures.API_COMPANY_ALERTS) - mocks.service_api_get_contracts_exclusions_sets_call( + mocks.service_api_get_contract_exclusion_sets_call( fixtures.API_CONTRACT_EXCLUSION_SET ) - mocks.service_api_get_contracts_excluded_roles_call( + mocks.service_api_get_contract_excluded_roles_call( fixtures.API_CONTRACT_EXCLUSION_ROLE ) - mocks.service_api_get_contracts_excluded_work_types_call( - fixtures.API_CONTRACT_EXCLUSION_ROLE + mocks.service_api_get_contract_excluded_work_types_call( + fixtures.API_CONTRACT_EXCLUSION_WORK_TYPE ) def _call_empty_service_api(self): @@ -1081,10 +1085,10 @@ def _call_empty_service_api(self): mocks.service_api_get_project_note_types_call( fixtures.API_EMPTY_FIELDS) mocks.service_api_get_task_picklist_call(fixtures.API_EMPTY_FIELDS) - mocks.service_api_get_company_alerts_call(fixtures.API_COMPANY_ALERTS) - mocks.service_api_get_contracts_exclusions_sets_call( - fixtures.API_CONTRACT_EXCLUSION_SET) - mocks.service_api_get_contracts_excluded_roles_call( - fixtures.API_CONTRACT_EXCLUSION_ROLE) - mocks.service_api_get_contracts_excluded_work_types_call( - fixtures.API_CONTRACT_EXCLUSION_WORK_TYPE) + mocks.service_api_get_company_alerts_call(fixtures.API_EMPTY) + mocks.service_api_get_contract_exclusion_sets_call( + fixtures.API_EMPTY) + mocks.service_api_get_contract_excluded_roles_call( + fixtures.API_EMPTY) + mocks.service_api_get_contract_excluded_work_types_call( + fixtures.API_EMPTY) diff --git a/djautotask/tests/test_sync.py b/djautotask/tests/test_sync.py index 90dfb8c..4d70750 100644 --- a/djautotask/tests/test_sync.py +++ b/djautotask/tests/test_sync.py @@ -1174,29 +1174,30 @@ def setUp(self): self._sync(self.fixture) def _call_api(self, return_data): - return mocks.service_api_get_contracts_exclusions_sets_call( + return mocks.service_api_get_contract_exclusion_sets_call( return_data) def _assert_fields(self, instance, object_data): self.assertEqual(instance.id, object_data['id']) self.assertEqual(instance.description, object_data['description']) - self.assertEqual(instance.isActive, object_data['isActive']) + self.assertEqual(instance.is_active, object_data['isActive']) self.assertEqual(instance.name, object_data['name']) class TestContractExclusionRoleSynchronizer(SynchronizerTestMixin, TestCase): synchronizer_class = sync.ContractExcludedRoleSynchronizer - model_class = models.ContractExcludeRoleTracker + model_class = models.ContractExcludedRoleTracker fixture = fixtures.API_CONTRACT_EXCLUSION_ROLE update_field = 'excluded_role_id' def setUp(self): super().setUp() - fixture_utils.init_contracts_exclusion_sets() + fixture_utils.init_roles() + fixture_utils.init_contract_exclusion_sets() self._sync(self.fixture) def _call_api(self, return_data): - return mocks.service_api_get_contracts_excluded_roles_call( + return mocks.service_api_get_contract_excluded_roles_call( return_data) def _assert_fields(self, instance, object_data): @@ -1216,19 +1217,20 @@ class TestContractExclusionWorkTypeSynchronizer(SynchronizerTestMixin, def setUp(self): super().setUp() - fixture_utils.init_contracts_exclusion_sets() + fixture_utils.init_billing_codes() + fixture_utils.init_contract_exclusion_sets() self._sync(self.fixture) def _call_api(self, return_data): - return mocks.service_api_get_contracts_excluded_work_types_call( + return mocks.service_api_get_contract_excluded_work_types_call( return_data) def _assert_fields(self, instance, object_data): self.assertEqual(instance.id, object_data['id']) self.assertEqual(instance.contract_exclusion_set.id, object_data['contractExclusionSetID']) - self.assertEqual(instance.excluded_work_type.id, object_data[ - 'excludedWorkTypeID']) + self.assertEqual(instance.excluded_work_type.id, + object_data['excludedWorkTypeID']) class TestCompanyAlertsSynchronizer(SynchronizerTestMixin, TestCase):