Skip to content

Commit

Permalink
Merge branch 'release/1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
goranvrbaski committed Oct 10, 2022
2 parents 3ae1340 + 44fe807 commit a35372f
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 18 deletions.
11 changes: 0 additions & 11 deletions .codecov.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/python-package.yml
@@ -0,0 +1,37 @@
name: Python package

on:
workflow_run:
workflows: ["Python Test"]
types: [completed]
branches: [master]

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/python-test.yml
@@ -0,0 +1,29 @@
name: Python Test

on:
push:
branches: [master, develop, "release/*", "feature/*", "bugfix/*"]
pull_request:
branches: [master, develop]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests with coverage
run: |
export PYTHONPATH=/home/runner/work/python-namesilo/python-namesilo
python -m unittest --verbose tests/test_namesilo.py
7 changes: 3 additions & 4 deletions README.md
@@ -1,12 +1,11 @@
# Python Namesilo Module

[![Build Status Badge][BuildStatus]](https://travis-ci.org/goranvrbaski/python-namesilo.svg?branch=master)
[![Code Coverage Badge][CodeCov]](https://codecov.io/gh/goranvrbaski/python-namesilo)
[![PyPiVersion Badge][PyPiVersion]](https://pypi.org/project/python-namesilo)
[![Read The Docs][ReadtheDocs]](https://python-namesilo.readthedocs.io)
[![DonateMe][PaypalBadge]](https://paypal.me/goranvrbaski)

This code is written in Python 3.6 If you want to contribute to this
This code is written in Python, and the following versions are supported: `3.6`, `3.7`, `3.8`, `3.9`, `3.10`.

If you want to contribute to this
project feel free to contact me at any time. If you're using this module and
you like it, consider [buying me a beer.](https://paypal.me/goranvrbaski) :beer:

Expand Down
60 changes: 60 additions & 0 deletions namesilo/core.py
Expand Up @@ -380,3 +380,63 @@ def remove_domain_privacy(self, domain_name):
f"domain={domain_name}"
self._process_data(url_extend)
return True

def list_dns_records(self, domain_name):
"""
List all DNS records for specified domain name
:param str domain_name: Domain name for listing DNS records
:return: Returns a list of DNS records for specified domain name
:rtype: list
"""

url_extend = f"dnsListRecords?version=1&type=xml&key={self._token}" \
f"&domain={domain_name}"
parsed_context = self._process_data(url_extend)
records = parsed_context['namesilo']['reply']['resource_record']
return records

def add_dns_records(
self, domain_name, record_type, record_host, record_value,
ttl=7207):
"""
Add DNS record to specified domain name
:param str domain_name: Domain name for adding DNS record
:param str record_type: The type of resources record to add
:param str record_host: The hostname for the new record
:param str record_value: The value for the resource record
:param int ttl: The TTL for the new record
:return: Returns record id for specified domain record
:rtype: int
"""

url_extend = f"dnsAddRecord?version=1&type=xml&key={self._token}" \
f"&domain={domain_name}&rrtype={record_type}" \
f"&rrhost={record_host}&rrvalue={record_value}&rrttl={ttl}"
parsed_context = self._process_data(url_extend)
record_id = parsed_context['namesilo']['reply']['record_id']
return record_id

def update_dns_records(
self, domain_name, record_id, record_host, record_value,
ttl=7207):
"""
Update an existing DNS resource record
:param str domain_name: Domain name for updating DNS record
:param str record_id: The unique ID of the resource record
:param str record_host: The hostname to use
:param str record_value: The value for the resource record
:param int ttl: The TTL for this record
:return: Returns record id for updated domain record
:rtype: int
"""

url_extend = f"dnsUpdateRecord?version=1&type=xml" \
f"&key={self._token}&domain={domain_name}&" \
f"rrid={record_id}&rrhost={record_host}" \
f"&rrvalue={record_value}&rrttl={ttl}"
parsed_context = self._process_data(url_extend)
new_record_id = parsed_context['namesilo']['reply']['record_id']
return new_record_id
9 changes: 7 additions & 2 deletions setup.py
Expand Up @@ -9,16 +9,21 @@

setup(
name='python-namesilo',
version='1.1.3',
version='1.4.1',
packages=find_packages(exclude=['docs', 'tests']),
install_requires=['requests', 'xmltodict'],
python_requires='>=3.6',
python_requires='>=3.6,<=3.10',
py_modules=['namesilo'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries :: Python Modules'
],
Expand Down
11 changes: 10 additions & 1 deletion tests/mocked_data.py
Expand Up @@ -69,7 +69,16 @@
},
'domains': {
'domain': ['some-example-domain.com', 'example.com']
}
},
'resource_record': [
{
'record_id': 'e3f383786a647e83c49c6082c7ce8015',
'type': 'A',
'host': 'some-domain.com',
'value': '107.161.23.204'
}
],
'record_id': 'e3f383786a647e83c49c6082c7ce8014'
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/test_namesilo.py
Expand Up @@ -299,6 +299,39 @@ def test_remove_auto_renew_domain(self, mock_content_xml):
"domain=some-domain.com"
)

@mock.patch('namesilo.core.NameSilo._process_data')
def test_list_dns_records(self, mock_content_xml):
domain_name = "some-domain.com"
mock_content_xml.return_value = mocked_data
result = self.ns.list_dns_records(domain_name)
self.assertIsInstance(result, list)
self.assertListEqual(mocked_data['namesilo']['reply']['resource_record'], result)

@mock.patch('namesilo.core.NameSilo._process_data')
def test_add_dns_record(self, mock_content_xml):
mock_content_xml.return_value = mocked_data
record_id = self.ns.add_dns_records(
"some-domain.com", "A", "test.some-domain.com", "192.168.71.50", 86400
)
mock_content_xml.assert_called_once_with(
"dnsAddRecord?version=1&type=xml&key=name-silo-token&domain=some-domain.com&"
"rrtype=A&rrhost=test.some-domain.com&rrvalue=192.168.71.50&rrttl=86400"
)
self.assertEqual(record_id, 'e3f383786a647e83c49c6082c7ce8014')

@mock.patch('namesilo.core.NameSilo._process_data')
def test_update_dns_record(self, mock_content_xml):
mock_content_xml.return_value = mocked_data
record_id = self.ns.update_dns_records(
"some-domain.com", "e3f383786a647e83c49c6082c7ce8014", "test.some-domain.com", "192.168.71.55"
)
mock_content_xml.assert_called_once_with(
"dnsUpdateRecord?version=1&type=xml&key=name-silo-token&domain=some-domain.com&"
"rrid=e3f383786a647e83c49c6082c7ce8014&rrhost=test.some-domain.com&"
"rrvalue=192.168.71.55&rrttl=7207"
)
self.assertEqual(record_id, 'e3f383786a647e83c49c6082c7ce8014')


if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit a35372f

Please sign in to comment.