def doPrepareCreate(self, *args, **kwargs): """ Action method. """ self.contact_info = zcontacts.to_dict(self.target_contact) self.contact_info['id'] = zclient.make_epp_id( self.contact_info['email'])
def doPrepareRetry(self, *args, **kwargs): """ Action method. """ # small workaround for situations when that contact already exists on the server, # epp_id is generated randomly so there is a chance you hit already existing object self.contact_info['id'] = zclient.make_epp_id( self.contact_info['email']) + 'a'
def doEppCreateNewRegistrant(self, *args, **kwargs): """ Action method. """ response = args[0] self.current_registrant_info = response['epp']['response']['resData'][ 'infData'] self.current_registrant_address_info = zcontacts.extract_address_info( response) self.new_registrant_epp_id = zclient.make_epp_id( self.current_registrant_info['email']) try: response = zclient.cmd_contact_create( contact_id=self.new_registrant_epp_id, email=self.current_registrant_info['email'], voice=self.current_registrant_info.get('voice'), fax=self.current_registrant_info.get('fax'), contacts_list=[{ 'name': self.current_registrant_address_info.get( 'name', 'unknown'), 'org': self.current_registrant_address_info.get('org', 'unknown'), 'address': { 'street': [ self.current_registrant_address_info.get( 'street', 'unknown'), ], 'city': self.current_registrant_address_info.get( 'city', 'unknown'), 'sp': self.current_registrant_address_info.get( 'sp', 'unknown'), 'pc': self.current_registrant_address_info.get( 'pc', 'unknown'), 'cc': self.current_registrant_address_info.get('cc', 'AF'), }, }], raise_for_result=False, ) except zerrors.EPPError as exc: self.log(self.debug_level, 'Exception in doEppCreateNewRegistrant: %s' % exc) self.event('error', exc) else: self.event('response', response)
def test_contact_update(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable tester_contact = testsupport.prepare_tester_contact() existing_contact_id = zclient.make_epp_id(tester_contact.contact_email) existing_contact_info = zcontacts.to_dict(tester_contact) create_response = zclient.cmd_contact_create( contact_id=existing_contact_id, email=existing_contact_info['email'], voice=existing_contact_info['voice'], fax=existing_contact_info['fax'], # auth_info=auth_info, contacts_list=existing_contact_info['contacts'], raise_for_result=False, ) assert create_response['epp']['response']['result']['@code'] == '1000' tester_contact.epp_id = existing_contact_id tester_contact.person_name = 'Tester Tester ' + str(int(time.time())) tester_contact.save() scenario = [] cs = contact_synchronizer.ContactSynchronizer( log_events=True, log_transitions=True, ) cs.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append( (oldstate, newstate, event, ) ), ) cs.event('run', tester_contact) outputs = list(cs.outputs) del cs assert tester_contact.epp_id != '' delete_response = zclient.cmd_contact_delete(tester_contact.epp_id) assert delete_response['epp']['response']['result']['@code'] == '1000' tester_contact.epp_id = None tester_contact.save() assert scenario == [ ('AT_STARTUP', 'CONTACT_UPDATE', 'run'), ('CONTACT_UPDATE', 'DONE', 'response'), ] assert len(outputs) == 1 assert outputs[0]['epp']['response']['result']['@code'] == '1000'
def test_domain_update(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='test.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0], domain_epp_id=zclient.make_epp_id(tester.email), tester=tester, ) scenario = [] cs = domain_contacts_synchronizer.DomainContactsSynchronizer( update_domain=True, log_events=True, log_transitions=True, raise_errors=True, ) cs.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append( (oldstate, newstate, event, ) ), ) cs.event('run', target_domain=tester_domain) outputs = list(cs.outputs) del cs assert scenario == [ ('AT_STARTUP', 'SYNC_CONTACTS', 'run'), ('SYNC_CONTACTS', 'DOMAIN_INFO?', 'all-contacts-in-sync'), ('DOMAIN_INFO?', 'DOMAIN_UPDATE', 'response'), ('DOMAIN_UPDATE', 'DONE', 'response'), ] assert len(outputs) == 5 assert outputs[0][0] == 'admin' assert outputs[0][1]['epp']['response']['resData']['creData']['id'] == tester_domain.contact_admin.epp_id assert outputs[1][0] == 'billing' assert outputs[1][1]['epp']['response']['resData']['creData']['id'] == tester_domain.contact_billing.epp_id assert outputs[2][0] == 'registrant' assert outputs[2][1]['epp']['response']['resData']['creData']['id'] == tester_domain.registrant.epp_id assert outputs[3][0] == 'tech' assert outputs[3][1]['epp']['response']['resData']['creData']['id'] == tester_domain.contact_tech.epp_id
def test_update_hostnames(): if os.environ.get('E2E', '0') != '1': return pytest.skip('skip E2E') # @UndefinedVariable tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='test.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0], tester=tester, domain_epp_id=zclient.make_epp_id(tester.email), add_contacts=[ 'registrant', 'admin', ], nameservers=[ 'ns1.google.com', 'ns2.google.com', 'ns3.google.com', ]) scenario1 = [] cs1 = domain_hostnames_synchronizer.DomainHostnamesSynchronizer( update_domain=True, log_events=True, log_transitions=True, raise_errors=True, ) cs1.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario1.append( ( oldstate, newstate, event, )), ) cs1.event( 'run', target_domain=tester_domain, known_domain_info=zclient.cmd_domain_info(domain=tester_domain.name), ) outputs1 = list(cs1.outputs) del cs1 tester_domain.nameserver4 = 'ns4.google.com' tester_domain.save() scenario2 = [] cs2 = domain_hostnames_synchronizer.DomainHostnamesSynchronizer( update_domain=True, log_events=True, log_transitions=True, raise_errors=True, ) cs2.add_state_changed_callback( cb=lambda oldstate, newstate, event, *args, **kwargs: scenario2.append( ( oldstate, newstate, event, )), ) cs2.event( 'run', target_domain=tester_domain, known_domain_info=zclient.cmd_domain_info(domain=tester_domain.name), ) outputs2 = list(cs2.outputs) del cs2 # one nameserver should be removed assert scenario1 == [ ('AT_STARTUP', 'DOMAIN_INFO?', 'run'), ('DOMAIN_INFO?', 'HOSTS_CHECK', 'response'), ('HOSTS_CHECK', 'DOMAIN_UPDATE!', 'no-hosts-to-be-added'), ('DOMAIN_UPDATE!', 'DONE', 'response'), ] assert len(outputs1) == 1 assert outputs1[0]['epp']['response']['result']['@code'] == '1000' # one nameserver should be added back assert scenario2 == [ ('AT_STARTUP', 'DOMAIN_INFO?', 'run'), ('DOMAIN_INFO?', 'HOSTS_CHECK', 'response'), ('HOSTS_CHECK', 'HOSTS_CREATE', 'response'), ('HOSTS_CREATE', 'DOMAIN_UPDATE!', 'all-hosts-created'), ('DOMAIN_UPDATE!', 'DONE', 'response'), ] assert len(outputs2) == 1 assert outputs2[0]['epp']['response']['result']['@code'] == '1000'