Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some tests

  • Loading branch information...
commit d90928bbde902f6e748acc5cd767cfebecb573f9 1 parent f2651d9
@ronnix ronnix authored
View
4 .hgignore
@@ -1,8 +1,12 @@
+^.*\.egg/
^.*\.egg-info/
^\.Python
^bin/
+^build/
^include/
^lib/
+^man/
+^tests/\.vagrant
syntax: glob
*.pyc
View
12 README.md
@@ -59,3 +59,15 @@ def setup():
# Ensure we have a cron task running daily
fabtools.cron.add_daily('maintenance', 'myuser', 'my_script.py')
```
+
+Tests
+=====
+
+The tests use [Vagrant](http://vagrantup.com/) to launch a virtual machine,
+against which all the tests will be run.
+
+Launch the tests using the [nose](http://readthedocs.org/docs/nose/) test runner:
+
+```
+$ nosetests
+```
View
3  setup.py
@@ -16,6 +16,9 @@
"fabric>=1.2.0",
],
setup_requires=[],
+ tests_require=[
+ "nose",
+ ],
packages=find_packages(exclude=['ez_setup']),
include_package_data=True,
zip_safe=False,
View
34 tests/Vagrantfile
@@ -0,0 +1,34 @@
+Vagrant::Config.run do |config|
+ # All Vagrant configuration is done here. The most common configuration
+ # options are documented and commented below. For a complete reference,
+ # please see the online documentation at vagrantup.com.
+
+ # Every Vagrant virtual environment requires a box to build off of.
+ config.vm.box = "lucid64"
+
+ # The url from where the 'config.vm.box' box will be fetched if it
+ # doesn't already exist on the user's system.
+ config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
+
+ # Boot with a GUI so you can see the screen. (Default is headless)
+ # config.vm.boot_mode = :gui
+
+ # Set VM memory size
+ config.vm.customize do |vm|
+ vm.memory_size = 512
+ end
+
+ # Assign this VM to a host only network IP, allowing you to access it
+ # via the IP.
+ # config.vm.network "33.33.33.10"
+
+ # Forward a port from the guest to the host, which allows for outside
+ # computers to access the VM, whereas host only networking does not.
+ config.vm.forward_port("ssh", 22, 2224)
+
+ # Share an additional folder to the guest VM. The first argument is
+ # an identifier, the second is the path on the guest to mount the
+ # folder, and the third is the path on the host to the actual folder.
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
+
+end
View
18 tests/fabfile.py
@@ -0,0 +1,18 @@
+from fabric.api import *
+from fabtools import icanhaz
+import fabtools
+
+
+def mysql():
+ """
+ Setup MySQL server, user and database
+ """
+ icanhaz.mysql.server(password='s3cr3t')
+
+ with settings(mysql_user='root', mysql_password='s3cr3t'):
+
+ icanhaz.mysql.user('myuser', 'foo')
+ assert fabtools.mysql.user_exists('myuser')
+
+ icanhaz.mysql.database('mydb', owner='myuser')
+ assert fabtools.mysql.database_exists('mydb')
View
27 tests/id_rsa_vagrant
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
+w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
+kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
+hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
+Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
+yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd
+ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1
+Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf
+TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK
+iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A
+sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf
+4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP
+cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk
+EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN
+CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX
+3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG
+YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj
+3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+
+dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz
+6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC
+P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF
+llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ
+kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
++vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
+NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
+-----END RSA PRIVATE KEY-----
View
44 tests/test_fabfile.py
@@ -0,0 +1,44 @@
+import os.path
+
+from fabric.api import *
+from nose import with_setup
+
+import fabfile
+
+
+HOST = 'vagrant@127.0.0.1:2224'
+KEYFILE = os.path.join(os.path.dirname(__file__), 'id_rsa_vagrant')
+
+
+def setup():
+ """
+ Start the vagrant virtual machine before running tests
+ """
+ with lcd(os.path.dirname(__file__)):
+ local('vagrant up')
+
+
+def teardown():
+ """
+ Stop the vagrant virtual machine after running tests
+ """
+ with lcd(os.path.dirname(__file__)):
+ local('vagrant halt')
+
+
+def setup_mysql():
+ """
+ Clean up MySQL install before tests
+ """
+ with settings(hide('running', 'stdout'), host_string=HOST, key_filename=KEYFILE):
+ sudo("aptitude remove --assume-yes --purge mysql-server-5.1")
+ sudo("rm -rf /var/lib/mysql")
+
+
+@with_setup(setup_mysql)
+def test_mysql():
+ """
+ Run the 'mysql' task from the fabfile
+ """
+ with settings(host_string=HOST, key_filename=KEYFILE):
+ fabfile.mysql()
Please sign in to comment.
Something went wrong with that request. Please try again.