def test_domains_dns_setDefault_on_nonexisting_domain(): api = Api(username, api_key, username, ip_address, sandbox=True) domain_name = random_domain_name() # This should fail because the domain does not exist with pytest.raises(ApiError): api.domains_dns_setDefault(domain_name)
def test_domains_dns_setHosts(): api = Api(username, api_key, username, ip_address, sandbox=True) domain_name = test_register_domain() api.domains_dns_setHosts(domain_name, [{ 'HostName': '@', 'RecordType': 'URL', 'Address': 'http://news.ycombinator.com', 'MXPref': '10', 'TTL': '100' }])
def main(): args = get_args() with open(os.path.join(os.getenv("HOME"), ".config", "namecheap", "namecheap.json")) as cfg: config = json.loads(cfg.read()) if args.sandbox: api_key = config['sandbox_key'] username = config['sandbox_username'] else: api_key = config['api_key'] username = config['username'] ip_address = config['ip_address'] domain = args.domain if domain: print("domain: %s" % domain) else: print("Domains:") api = Api(username, api_key, username, ip_address, sandbox=args.sandbox, debug=args.debug) if args.add: record_add( api, domain, args.type, args.name, args.address, args.ttl ) elif args.delete: record_delete( api, domain, args.name, args.address, args.type ) elif args.list: if not domain: [print(f"Name: {i['Name']}") for i in api.domains_getList()] exit() for line in list_records(api, domain): print("\t%s \t%s\t%s -> %s" % (line["Type"], line["TTL"], line["Name"], line["Address"]))
def test_domains_dns_bulkAddHosts(): api = Api(username, api_key, username, ip_address, sandbox=True) api.payload_limit = 3 domain_name = test_register_domain() api.domains_dns_setHosts(domain_name, [{ 'HostName': '@', 'RecordType': 'URL', 'Address': 'http://news.ycombinator.com' }]) for i in range(1, 10): api.domains_dns_addHost( domain_name, { 'Name': "test" + str(i), 'Type': 'A', 'Address': '1.2.3.4', 'TTL': '60' }) hosts = api.domains_dns_getHosts(domain_name) if len(hosts) == 10: return True return False
def test_register_domain(): api = Api(username, api_key, username, ip_address, sandbox=True) # Try registering a random domain. Fails if exception raised. domain_name = random_domain_name() api.domains_create(DomainName=domain_name, FirstName='Jack', LastName='Trotter', Address1='Ridiculously Big Mansion, Yellow Brick Road', City='Tokushima', StateProvince='Tokushima', PostalCode='771-0144', Country='Japan', Phone='+81.123123123', EmailAddress='*****@*****.**') return domain_name
def test_domains_dns_getHosts(): api = Api(username, api_key, username, ip_address, sandbox=True) domain_name = test_register_domain() api.domains_dns_setHosts(domain_name, [{ 'HostName': '@', 'RecordType': 'URL', 'Address': 'http://news.ycombinator.com', 'MXPref': '10', 'TTL': '100' }, { 'HostName': '*', 'RecordType': 'A', 'Address': '1.2.3.4', 'MXPref': '10', 'TTL': '1800' }]) hosts = api.domains_dns_getHosts(domain_name) # these might change del hosts[0]['HostId'] del hosts[1]['HostId'] expected_result = [{ 'Name': '*', 'Address': '1.2.3.4', 'TTL': '1800', 'Type': 'A', 'MXPref': '10', 'AssociatedAppTitle': '', 'FriendlyName': '', 'IsActive': 'true', 'IsDDNSEnabled': 'false' }, { 'Name': '@', 'Address': 'http://news.ycombinator.com', 'TTL': '100', 'Type': 'URL', 'MXPref': '10', 'AssociatedAppTitle': '', 'FriendlyName': '', 'IsActive': 'true', 'IsDDNSEnabled': 'false' }] assert hosts == expected_result
def test_list_of_dictionaries_to_numbered_payload(): x = [{'foo': 'bar', 'cat': 'purr'}, {'foo': 'buz'}, {'cat': 'meow'}] result = Api._list_of_dictionaries_to_numbered_payload(x) expected_result = { 'foo1': 'bar', 'cat1': 'purr', 'foo2': 'buz', 'cat3': 'meow' } assert result == expected_result
def test_domains_dns_setDefault_on_existing_domain(): api = Api(username, api_key, username, ip_address, sandbox=True) domain_name = test_register_domain() api.domains_dns_setDefault(domain_name)
def test_domains_getList(): api = Api(username, api_key, username, ip_address, sandbox=True) iter(api.domains_getList())
def test_domain_available(): api = Api(username, api_key, username, ip_address, sandbox=True) domain_name = random_domain_name() assert api.domains_check(domain_name) == True
def test_domain_taken(): api = Api(username, api_key, username, ip_address, sandbox=True) domain_name = "google.com" assert api.domains_check(domain_name) == False