def test_site(): s1 = Site( name='site1', description='test site 1' ) s1.config_values = {} s1.full_clean() s1.save() now = datetime.now( timezone.utc ) tmp = getConfig( s1 ) assert now - tmp[ '__last_modified' ] < timedelta( seconds=5 ) assert now - tmp[ '__timestamp' ] < timedelta( seconds=5 ) del tmp[ '__last_modified' ] del tmp[ '__timestamp' ] del tmp[ '__pxe_template_location' ] assert tmp == { '__contractor_host': 'http://contractor/', '__pxe_location': 'http://static/pxe/', '_site': 'site1' } assert _strip_base( getConfig( s1 ) ) == { '_site': 'site1' } s2 = Site( name='site2', description='test site 2', parent=s1 ) s2.config_values = { 'myval': 'this is a test', 'stuff': 'this is only a test' } s2.full_clean() s2.save() assert _strip_base( getConfig( s2 ) ) == { '_site': 'site2', 'myval': 'this is a test', 'stuff': 'this is only a test' } s1.config_values = { 'under': 'or over' } s1.full_clean() s1.save() assert _strip_base( getConfig( s2 ) ) == { '_site': 'site2', 'myval': 'this is a test', 'stuff': 'this is only a test', 'under': 'or over' } s2.config_values[ '>under' ] = ' here' s2.config_values[ '<under' ] = 'going ' s2.full_clean() s2.save() assert _strip_base( getConfig( s2 ) ) == { '_site': 'site2', 'myval': 'this is a test', 'stuff': 'this is only a test', 'under': 'going or over here' }
def test_site(): s = Site() with pytest.raises(ValidationError): s.full_clean() s = Site(name='test') with pytest.raises(ValidationError): s.full_clean() s = Site(name='test', description='test site') s.full_clean() s.save() s = Site(name='test', description='test site') s.config_values = None with pytest.raises(ValidationError): s.full_clean() s = Site(name=' test') with pytest.raises(ValidationError): s.full_clean() s = Site(name='test', description='more testing') with pytest.raises(ValidationError): s.full_clean() s = Site(name='test2', description='more testing') s.full_clean() s.config_values = {'stuff': 'yep'} s.full_clean() s.save() s = Site(name='test3', description='blah blah') s.full_clean() s.config_values = {' stuff': 'yep'} with pytest.raises(ValidationError): s.full_clean()
def test_site(mocker): mocker.patch('contractor.Records.lib._connect', fake_connect) global fake_key global fake_item fake_key = None fake_item = None s = Site() s.name = '1234test' s.description = 'test desc' s.full_clean() s.save() assert fake_key == {'_id': '1234test'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_site': '1234test' } fake_key = None fake_item = None s.config_values = {'a': 42, 'z': 'abc'} s.full_clean() s.save() assert fake_key == {'_id': '1234test'} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_site': '1234test', 'a': 42, 'z': 'abc' } fake_key = None s.delete() assert fake_key == {'_id': '1234test'}
def test_foundation(): s1 = Site( name='site1', description='test site 1' ) s1.config_values = {} s1.full_clean() s1.save() fb1 = FoundationBluePrint( name='fdnb1', description='Foundation BluePrint 1' ) fb1.foundation_type_list = [ 'Unknown' ] fb1.full_clean() fb1.save() f1 = Foundation( site=s1, locator='fdn1', blueprint=fb1 ) f1.full_clean() f1.save() now = datetime.now( timezone.utc ) tmp = getConfig( f1 ) assert now - tmp[ '__last_modified' ] < timedelta( seconds=5 ) assert now - tmp[ '__timestamp' ] < timedelta( seconds=5 ) del tmp[ '__last_modified' ] del tmp[ '__timestamp' ] del tmp[ '__pxe_template_location' ] assert tmp == { '__contractor_host': 'http://contractor/', '__pxe_location': 'http://static/pxe/', '_foundation_class_list': [], '_foundation_id': 'fdn1', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn1', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_provisioning_interface': None, '_provisioning_interface_mac': None, '_blueprint': 'fdnb1', '_site': 'site1' } assert _strip_base( getConfig( f1 ) ) == { '_foundation_class_list': [], '_foundation_id': 'fdn1', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn1', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_provisioning_interface': None, '_provisioning_interface_mac': None, '_blueprint': 'fdnb1', '_site': 'site1' } fb1.config_values[ 'lucky' ] = 'blueprint' fb1.full_clean() fb1.save() assert _strip_base( getConfig( f1 ) ) == { '_foundation_class_list': [], '_foundation_id': 'fdn1', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn1', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_provisioning_interface': None, '_provisioning_interface_mac': None, '_blueprint': 'fdnb1', '_site': 'site1', 'lucky': 'blueprint' } s1.config_values[ 'lucky' ] = 'site' s1.full_clean() s1.save() assert _strip_base( getConfig( f1 ) ) == { '_foundation_class_list': [], '_foundation_id': 'fdn1', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn1', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_provisioning_interface': None, '_provisioning_interface_mac': None, '_blueprint': 'fdnb1', '_site': 'site1', 'lucky': 'site' }