Skip to content

Commit

Permalink
Merge pull request #47 from cedarville-university/develop
Browse files Browse the repository at this point in the history
bugfix release
  • Loading branch information
nattyboyme3 authored Nov 18, 2021
2 parents d3a563c + 85d7a74 commit e2ef84a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
name='TDXLib',
description='a python library for interacting with the TeamDynamix Web API',
version='0.3.0',
version='0.3.3',
author='Nat Biggs, Stephen Gaines, Josiah Lansford',
author_email='tdxlib@cedarville.edu',
packages=['tdxlib'],
Expand Down
2 changes: 1 addition & 1 deletion tdxlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
import tdxlib.tdx_ticket
import tdxlib.tdx_utils

__version__ = "0.3.0"
__version__ = "0.3.3"
37 changes: 24 additions & 13 deletions tdxlib/tdx_asset_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import datetime
import tdx_utils
import tdxlib.tdx_utils
import tdxlib.tdx_integration
from tdxlib.tdx_api_exceptions import *

Expand Down Expand Up @@ -826,7 +826,7 @@ def build_asset_custom_attribute_value(self, custom_attribute, value) -> dict:
ca_choice = self.get_custom_attribute_choice_by_name_id(ca, value)
value = ca_choice['ID']
if isinstance(value, datetime.datetime):
value = tdx_utils.export_tdx_date(value)
value = tdxlib.tdx_utils.export_tdx_date(value)
return {'ID': ca['ID'], 'Value': value}

def change_asset_custom_attribute_value(self, asset, custom_attributes: list) -> list:
Expand Down Expand Up @@ -858,7 +858,7 @@ def clear_asset_custom_attributes(self, asset: dict, attributes_to_clear: list):
to_change['Attributes'].append(ca)
return self.update_assets(full_asset, to_change, clear_custom_attributes=True)[0]

def get_asset_custom_attribute_value_by_name(self, asset, key: str, id: bool=False) -> str:
def get_asset_custom_attribute_value_by_name(self, asset, key: str, id_only: bool=False) -> str:
"""
Returns the current value of a specific CA in the specified asset
Expand All @@ -879,23 +879,31 @@ def get_asset_custom_attribute_value_by_name(self, asset, key: str, id: bool=Fal
ca_id = self.get_asset_custom_attribute_by_name_id(key)['ID']
for ca in this_asset['Attributes']:
if str(ca['ID']) == str(ca_id):
if ca['Choices'] and id:
if ca['Choices'] and id_only:
return ca['Value']
else:
return ca['ValueText']

def move_child_assets(self, source_asset: dict, target_asset: dict) -> list:
def move_child_assets(self, source_asset, target_asset) -> list:
"""
Moves child assets from one parent asset to another
:param source_asset: asset to move children from (doesn't have to be full record)
:param target_asset: asset to move children to
:param source_asset: asset (or asset ID) to move children from (doesn't have to be full record)
:param target_asset: asset (or asset ID) to move children to
:return: list of the updated assets
"""
search_params = {'ParentID': source_asset['ID']}
update_params = {'ParentID': target_asset['ID']}
if isinstance(source_asset, str) or isinstance(source_asset, int):
search_string = str(source_asset)
else:
search_string = source_asset['ID']
if isinstance(target_asset, str) or isinstance(target_asset, int):
target_string = str(target_asset)
else:
target_string = target_asset['ID']
search_params = {'ParentIDs': [search_string]}
update_params = {'ParentID': target_string}
children = self.search_assets(search_params)
return self.update_assets(children, update_params)

Expand All @@ -916,10 +924,8 @@ def copy_asset_attributes(self, source_asset, target_asset, copy_name=False, exc
:return: list of the target and source asset data
"""
excluded_attributes = ['ID', 'SerialNumber', 'Tag', 'ExternalID', 'ModelID', 'SupplierID', 'ManufacturerID',
'PurchaseCost', 'ExpectedReplacementDate', 'AcquisitionDate', 'MAC Address',
'WiFi MAC Address', 'Year Purchased', 'Warranty Expiration Date', 'Order Number',
'cu.Responsible Group', 'OwningCustomerID', 'OwningDepartmentID']
excluded_attributes = ['ID', 'SerialNumber', 'Tag', 'ExternalID', 'ProductModelID', 'SupplierID',
'ManufacturerID', 'PurchaseCost', 'ExpectedReplacementDate', 'AcquisitionDate']
if exclude:
excluded_attributes.append(exclude)
if not copy_name:
Expand All @@ -929,6 +935,11 @@ def copy_asset_attributes(self, source_asset, target_asset, copy_name=False, exc
else:
full_source = self.get_asset_by_id(source_asset['ID'])
source_id = full_source['ID']
real_attribs = list()
for ca in full_source['Attributes']:
if ca['Name'] not in excluded_attributes:
real_attribs.append(ca)
full_source['Attributes'] = real_attribs
for protected_attribute in excluded_attributes:
full_source.pop(protected_attribute, None)
updated_target = self.update_assets(target_asset, full_source)
Expand Down
12 changes: 12 additions & 0 deletions testing/tdx_asset_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,18 @@ def test_copy_asset_attributes(self):
self.assertTrue(validate2['Attributes'][0]['Name'] == self.testing_vars['attributes1'][0]['Name'])
self.assertTrue(validate1['StatusName'] == self.testing_vars['asset_status2']['Name'])

def test_move_child_assets(self):
if not self.timestamp:
self.setUp()
child_asset_id = self.testing_vars['child_asset']['ID']
parent_asset_id = self.testing_vars['parent_asset']['ID']
other_asset_id = self.testing_vars['asset1']['ID']
self.tax.move_child_assets(parent_asset_id, other_asset_id)
validate = self.tax.get_asset_by_id(child_asset_id)
self.assertTrue(str(validate['ParentID']) == str(other_asset_id))
self.tax.move_child_assets(other_asset_id, parent_asset_id)
validate2 = self.tax.get_asset_by_id(child_asset_id)
self.assertTrue(str(validate2['ParentID']) == str(parent_asset_id))

if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TdxAssetTesting)
Expand Down

0 comments on commit e2ef84a

Please sign in to comment.