Skip to content

Commit

Permalink
Updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ssarwar-topleft committed Oct 30, 2024
1 parent a03e46b commit 341f555
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 69 deletions.
6 changes: 3 additions & 3 deletions djautotask/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down
2 changes: 1 addition & 1 deletion djautotask/management/commands/atsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, *args, **kwargs):
_('Contract Exclusion Set')
),
(
'contract_excluded_worktype',
'contract_excluded_work_type',
sync.ContractExcludedWorkTypeSynchronizer,
_('Contract Excluded Work Type')
),
Expand Down
14 changes: 7 additions & 7 deletions djautotask/migrations/0118_contractexclusionset_and_more.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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',
Expand Down
12 changes: 3 additions & 9 deletions djautotask/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -1509,7 +1503,7 @@ class Meta:
db_table = 'djautotask_contractexclusionsetworktype'


class ContractExcludeRoleTracker(ContractExclusionSetExcludedRole):
class ContractExcludedRoleTracker(ContractExclusionSetExcludedRole):
tracker = FieldTracker()

class Meta:
Expand Down
8 changes: 4 additions & 4 deletions djautotask/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ def _assign_field_data(self, instance, json_data):


class ContractExclusionSetSynchronizer(Synchronizer):
client_class = api.ContractExclusionSetsAPIClient
client_class = api.ContractExclusionSetAPIClient
model_class = models.ContractExclusionSetTracker
last_updated_field = None

Expand All @@ -2009,7 +2009,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
Expand Down Expand Up @@ -2037,8 +2037,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

Expand Down
12 changes: 6 additions & 6 deletions djautotask/tests/fixture_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions djautotask/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,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 = {
Expand All @@ -1464,7 +1464,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 = {
Expand Down
12 changes: 6 additions & 6 deletions djautotask/tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,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)


Expand Down
48 changes: 26 additions & 22 deletions djautotask/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -893,9 +898,9 @@ def test_full_sync(self):
'task_predecessor': models.TaskPredecessor,
'contact': models.Contact,
'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()
Expand All @@ -920,9 +925,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.
Expand Down Expand Up @@ -1001,14 +1005,14 @@ def _call_service_api(self):
fixtures.API_SERVICE_CALL_TASK_RESOURCE)
mocks.service_api_get_task_predecessors_call(
fixtures.API_TASK_PREDECESSOR)
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):
Expand Down Expand Up @@ -1064,9 +1068,9 @@ 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_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_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)
20 changes: 11 additions & 9 deletions djautotask/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 TestServiceCallSynchronizer(SynchronizerTestMixin, TestCase):
Expand Down

0 comments on commit 341f555

Please sign in to comment.