Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouhei committed Apr 1, 2013
2 parents 867d197 + b69d78b commit df2d6fb
Show file tree
Hide file tree
Showing 29 changed files with 744 additions and 490 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -4,4 +4,4 @@ python:
# command to install dependencies
install: pip install -r requirements.txt --use-mirrors
# command to run tests
script: nosetests
script: utils/pre-commit.txt
4 changes: 2 additions & 2 deletions debian/changelog
@@ -1,5 +1,5 @@
tonicdnscli (0.9-1) unstable; urgency=low
tonicdnscli (0.10-1) unstable; urgency=low

* Initial release (Closes: #679426)

-- Kouhei Maeda <mkouhei@palmtb.net> Thu, 13 Sep 2012 15:20:15 +0900
-- Kouhei Maeda <mkouhei@palmtb.net> Mon, 01 Apr 2013 16:50:28 +0900
2 changes: 1 addition & 1 deletion debian/control
Expand Up @@ -2,7 +2,7 @@ Source: tonicdnscli
Section: python
Priority: optional
Maintainer: Kouhei Maeda <mkouhei@palmtb.net>
Build-Depends: debhelper (>= 8.0.0), python-all, python-setuptools, python-nose, python-minimock, pep8, python-mock
Build-Depends: debhelper (>= 8.0.0), python-all, python-setuptools, python-pytest, python-minimock, pep8, python-mock
Standards-Version: 3.9.3
X-Python-Version: 2.7
Homepage: https://github.com/mkouhei/tonicdnscli
Expand Down
6 changes: 3 additions & 3 deletions debian/rules
Expand Up @@ -14,9 +14,9 @@

override_dh_auto_test:
set -e; \
PYTHONPATH=$(CURDIR)/src nosetests -d
py.test -v $(CURDIR)/_build

override_dh_install:
dh_install
rm -rf $(CURDIR)/debian/python-tonicdnscli/usr/share/pyshared/tonicdnscli/tests
rm -rf $(CURDIR)/debian/python-tonicdnscli/usr/lib/python2.7/dist-packages/tonicdnscli/tests
find $(CURDIR)/debian/python-tonicdnscli -name "*pyc" -delete
find $(CURDIR)/debian/python-tonicdnscli -type d -a -empty -delete
6 changes: 6 additions & 0 deletions docs/HISTORY.rst
@@ -1,6 +1,12 @@
History
-------

0.10 (2013-04-01)
^^^^^^^^^^^^^^^^^

* Change format of pretty print
* move test directory

0.9 (2012-09-13)
^^^^^^^^^^^^^^^^

Expand Down
43 changes: 22 additions & 21 deletions docs/README.rst
Expand Up @@ -88,11 +88,12 @@ Retrieve all zones
Get all zones and print.::

$ tonicdnscli get -u tonicusername -P
==============================================================================
name type notified_serial
==============================================================================
example.org MASTER 2012052201
example.net MASTER 2012060502
+-------------+--------+-----------------+
| name | type | notified_serial |
+-------------+--------+-----------------+
| example.org | MASTER | 2012052201 |
| example.net | MASTER | 2012060502 |
+-------------+--------+-----------------+


Retrieve records
Expand All @@ -101,20 +102,20 @@ Retrieve records
Get records of specific zone and print.::

$ tonicdnscli get -s ns.example.org -d example.org -u tonicusername -P
domain: example.org
serial: 2012042403
DNS : MASTER
==============================================================================
name type content ttl prio
==============================================================================
example.org SOA
> ns.example.org hostmaster.example.org 2012042403 86400
example.org NS ns.example.org 86400
example.org NS ns2.example.org 86400
ns.example.org A 192.168.0.100 86400
ns2.example.org A 192.168.0.101 86400
www.example.org A 192.168.0.1 86400
==============================================================================
zone: example.org
SOA record: ns.example.org hostmaster.example.org 2012042403
ttl: 86400
change date: 1341314161
example.org
+------+------+-----------------+-------+------+-------------+
| name | type | content | ttl | prio | change date |
+------+------+-----------------+-------+------+-------------+
| | NS | ns.example.org | 86400 | - | - |
| | NS | ns2.example.org | 86400 | - | - |
| ns. | A | 192.168.0.100 | 86400 | - | - |
| ns2. | A | 192.168.0.101 | 86400 | - | - |
| www. | A | 192.168.0.1 | 86400 | - | - |
+------+------+-----------------+-------+------+-------------+


Create single record
Expand Down Expand Up @@ -253,9 +254,9 @@ Firstly copy pre-commit hook script.::

$ cp -f utils/pre-commit.txt .git/hooks/pre-commit

Next install python2.7 later, and nosetests. Below in Debian GNU/Linux Sid system,::
Next install python2.7 later, and py.test. Below in Debian GNU/Linux Sid system,::

$ sudo apt-get install python python-nose
$ sudo apt-get install python python-pytest

Then checkout 'devel' branch for development, commit your changes. Before pull request, execute git rebase.

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,2 +1,2 @@
pep8==1.2
pep8==1.4
minimock
9 changes: 4 additions & 5 deletions setup.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2012 Kouhei Maeda <mkouhei@palmtb.net>
Copyright (C) 2012, 2013 Kouhei Maeda <mkouhei@palmtb.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -56,14 +55,14 @@
install_requires=requires,
extras_require=dict(
test=[
'Nose',
'pytest',
'pep8',
'unittest',
'minimock',
],
),
test_suite='nose.collector',
tests_require=['Nose','pep8','minimock'],
test_suite='tests',
tests_require=['pytest','pep8','minimock'],
entry_points="""
[console_scripts]
tonicdnscli = tonicdnscli.command:main
Expand Down
File renamed without changes.
@@ -1,18 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Tests of __init__.py
"""
import unittest
import sys
import os.path
sys.path.append(os.path.abspath('src'))
import tonicdnscli


class InitTests(unittest.TestCase):
def test_version_defined(self):
actual_version = tonicdnscli.__version__
self.assertTrue(actual_version)


if __name__ == '__main__':
unittest.main()
51 changes: 51 additions & 0 deletions src/tests/test_command.py
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-

"""
Tests of command.py
"""
import unittest
import sys
import os.path
sys.path.append(os.path.abspath('src'))
import tonicdnscli.command as c
import test_vars as v


class commandTests(unittest.TestCase):
def setUp(self):
import os.path
self.maxDiff = None
self.domain = 'example.org'
self.cu_records = [{'records': v.dicts1}]
self.r_records = [{'name': 'example.org',
'records': self.cu_records[0].get('records')}]
self.record = ['test3.example.org A 10.10.20.10 3600']
self.d_cu_record = [{'records': [{'name': 'test3.example.org',
'type': 'A',
'content': '10.10.20.10',
'ttl': 3600}]}]
self.d_r_record = [{'name': self.domain,
'records': [{'name': 'test3.example.org',
'type': 'A',
'content': '10.10.20.10',
'ttl': 3600}]}]
sample0 = os.path.dirname(__file__) + \
'/../../../examples/example.org.txt'
sample1 = os.path.dirname(__file__) + '/../../examples/example.org.txt'
if os.path.isfile(sample0):
self.sample = sample0
elif os.path.isfile(sample1):
self.sample = sample1

def test_check_infile(self):
self.assertEquals(self.domain, c.check_infile(self.sample))

def test_set_json(self):
self.assertEquals(self.cu_records,
c.set_json(self.domain, True, filename=self.sample))
self.assertEquals(self.r_records,
c.set_json(self.domain, False, filename=self.sample))
self.assertEquals(self.d_cu_record,
c.set_json(self.domain, True, record=self.record))
self.assertEquals(self.d_r_record,
c.set_json(self.domain, False, record=self.record))
66 changes: 66 additions & 0 deletions src/tests/test_connect.py
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-

"""
Tests of connect.py
"""
import unittest
from minimock import mock, Mock, restore
import sys
if sys.version_info > (2, 6) and sys.version_info < (2, 8):
import StringIO as io
elif sys.version_info > (3, 0):
import io as io
if sys.version_info > (2, 6) and sys.version_info < (2, 8):
import urllib2 as urllib
elif sys.version_info > (3, 0):
import urllib.request as urllib
import os.path
sys.path.append(os.path.abspath('src'))
import tonicdnscli.connect as conn
import test_vars as v


class connectTests(unittest.TestCase):
def setUp(self):
self.datajson = v.datajson

self.datadict = v.datadict

urllib.build_opener = Mock(
'build_opener',
returns=Mock(
'opener',
open=Mock(
'opener.open',
returns=Mock(
'opener.open',
read=Mock(
'opener.open.read',
returns=self.datajson)))))

self.uri = v.uri
self.token = v.token
self.data = ''

def tearDown(self):
restore()

def test_tonicdns_client(self):
dumpout = io.StringIO()
ostdout = sys.stdout
sys.stdout = dumpout
uri = self.uri + '/zone/example.org'
conn.tonicdns_client(uri,
'GET', self.token, self.data)
sys.stdout = ostdout
dumpout.seek(0)
self.assert_(dumpout.getvalue())

def test_print_formatted(self):
dumpout = io.StringIO()
ostdout = sys.stdout
sys.stdout = dumpout
conn.print_formatted(self.datadict)
sys.stdout = ostdout
dumpout.seek(0)
self.assert_(dumpout.getvalue())
84 changes: 84 additions & 0 deletions src/tests/test_converter.py
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

"""
Tests of converter.py
"""
import unittest
import sys
import os.path
sys.path.append(os.path.abspath('src'))
from tonicdnscli.converter import JSONConverter
import test_vars as v


class JSONConvertTests(unittest.TestCase):

def setUp(self):
sample0 = os.path.dirname(__file__) + \
'/../../../examples/example.org.txt'
sample1 = os.path.dirname(__file__) + '/../../examples/example.org.txt'
if os.path.isfile(sample0):
self.sample = sample0
elif os.path.isfile(sample1):
self.sample = sample1

def test__init__(self):
o = JSONConverter('example.org')
self.assertEquals('example.org', o.domain)
self.assertEquals(0, o.split_index)
self.assertListEqual([], o.records)
self.assertListEqual([], o.separated_list)
self.assertFalse(o.delta)

def test_read_records(self):
o = JSONConverter('example.org')
o.read_records(v.str2.splitlines())
self.assertListEqual(v.dicts1, o.records)

def test_check_key(self):
o = JSONConverter('example.org')
self.assertEquals("test0.example.org", o.check_key(v.line1, 0))
self.assertEquals("A", o.check_key(v.line1, 1))
self.assertEquals("10.10.10.10", o.check_key(v.line1, 2))
self.assertEquals("86400", o.check_key(v.line1, 3))
self.assertFalse(o.check_key(v.line1, 4))
self.assertEquals("0", o.check_key(v.line2, 4))
self.assertFalse(o.check_key(v.line2, 5))
self.assertEquals("10.10.11.10", o.check_key(v.line3, 2))

def test_generate_records(self):
o = JSONConverter('example.org')
o.generate_records(v.line1)
self.assertListEqual(v.list3, o.records)
o2 = JSONConverter('example.org')
o2.generate_records(v.line2)
self.assertListEqual(v.list4, o2.records)

def test_generata_data(self):
o1 = JSONConverter('example.org')
o1.generata_data(True)
self.assertListEqual([{'records': []}], o1.dict_records)
o2 = JSONConverter('example.org')
o2.generata_data(False)
self.assertListEqual([{'records': [], 'name': 'example.org'}],
o2.dict_records)

def test_separate_input_file(self):
import os.path
o = JSONConverter('example.org')
with open(self.sample, 'r') as f:
o.separate_input_file(f)
self.maxDiff = None
self.assertListEqual([v.str1], o.separated_list)
o2 = JSONConverter('example.org')
o2.delta = 3
with open(self.sample, 'r') as f2:
o2.separate_input_file(f2)
self.assertListEqual(v.str_l, o2.separated_list)

def test_get_soa(self):
o = JSONConverter('exmaple.org')
self.assertEquals(v.new_soa,
o.get_soa(v.older_cur_soa, v.content))
self.assertNotEquals(v.new_soa,
o.get_soa(v.today_cur_soa, v.content))

0 comments on commit df2d6fb

Please sign in to comment.