def test_updateConfig_structure(mocker): mocker.patch('contractor.Records.lib._connect', fake_connect) global fake_key global fake_item s = Site() s.name = 'site_test' s.description = 'testing Site' s.full_clean() s.save() fb = FoundationBluePrint() fb.name = 'fdnbp_test' fb.description = 'testing FBP' fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() fdn = Foundation() fdn.locator = 'fdn_test' fdn.blueprint = fb fdn.site = s fdn.full_clean() fdn.save() sb = StructureBluePrint() sb.name = 'strbp_test' sb.description = 'testing SBP' sb.full_clean() sb.save() sb.foundation_blueprint_list = [fb] sb.full_clean() sb.save() fake_key = None fake_item = None str = Structure() str.hostname = 'testme' str.site = s str.blueprint = sb str.foundation = fdn str.full_clean() str.save() pk = str.pk assert fake_key == { '_id': pk } # the auto inc value could be all sorts of values assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_site': 'site_test', '_blueprint': 'strbp_test', '_foundation_class_list': [], '_foundation_id': 'fdn_test', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn_test', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_fqdn': 'testme', '_hostname': 'testme', '_domain_name': None, '_interface_map': {}, '_provisioning_interface': None, '_provisioning_interface_mac': None, '_provisioning_address': None, '_primary_interface': None, '_primary_interface_mac': None, '_primary_address': None, '_structure_config_uuid': '*UUID*', '_structure_id': '*ID*', '_structure_state': 'planned' } fake_key = None fake_item = None str.config_values = {'sdf': {'a': 'rrrr', 'b': [1, 2, 3, 4]}} str.full_clean() str.save() assert fake_key == {'_id': pk} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_site': 'site_test', '_blueprint': 'strbp_test', '_foundation_class_list': [], '_foundation_id': 'fdn_test', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn_test', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_fqdn': 'testme', '_hostname': 'testme', '_domain_name': None, '_interface_map': {}, '_provisioning_interface': None, '_provisioning_interface_mac': None, '_provisioning_address': None, '_primary_interface': None, '_primary_interface_mac': None, '_primary_address': None, '_structure_config_uuid': '*UUID*', '_structure_id': '*ID*', '_structure_state': 'planned', 'sdf': { 'a': 'rrrr', 'b': [1, 2, 3, 4] } } fake_key = None str.delete() assert fake_key == {'_id': pk}
def test_updateConfig_blueprint(mocker): mocker.patch('contractor.Records.lib._connect', fake_connect) global fake_key global fake_item fake_key = None fake_item = None sb = StructureBluePrint() sb.name = 'sbptest' sb.description = 'testing SBP' sb.full_clean() sb.save() assert fake_key == {'_id': 'sbptest'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_blueprint': 'sbptest' } fake_key = None fake_item = None sb.config_values = {'er': 'bob', 'um': 'sally'} sb.full_clean() sb.save() assert fake_key == {'_id': 'sbptest'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_blueprint': 'sbptest', 'er': 'bob', 'um': 'sally' } fake_key = None fake_item = None fb = FoundationBluePrint() fb.name = 'fdntest' fb.description = 'testing FBP' fb.foundation_type_list = ['nope'] fb.full_clean() fb.save() assert fake_key == {'_id': 'fdntest'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_blueprint': 'fdntest' } fake_key = None fake_item = None fb.config_values = {'qwert': [1, 2, 3, 'z']} fb.full_clean() fb.save() assert fake_key == {'_id': 'fdntest'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_blueprint': 'fdntest', 'qwert': [1, 2, 3, 'z'] } fake_key = None fake_item = None sb.foundation_blueprint_list = [fb] sb.full_clean() sb.save() assert fake_key == {'_id': 'sbptest'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_blueprint': 'sbptest', 'er': 'bob', 'um': 'sally' } fake_key = None fb.delete() assert fake_key == {'_id': 'fdntest'} fake_key = None sb.delete() assert fake_key == {'_id': 'sbptest'}