Source

MyHost / couchdb / tests.py

Full commit
#!/usr/bin/env python

# -*- coding: utf-8 -*-
import couchdbkit

__author__ = 'a8'

import unittest
import fill_couch

class CouchDBConnect(unittest.TestCase):

    def test_db_connect(self):
        self.assertNotEqual(fill_couch.db_connect(), False)

class CouchDBRegister(unittest.TestCase):

    def setUp(self):
        """
        init db
        """
        self.db = fill_couch.db_connect()

    def disabled_db_register(self):
        self.assertTrue(issubclass(
            fill_couch.db_register(fill_couch.Host, self.db),
            couchdbkit.Document))

    def tearDown(self):
        del(self.db)


class SaveHost(unittest.TestCase):
    """"""

    def setUp(self):
        """
        init db
        """
        self.db = fill_couch.db_connect()
        fill_couch.Host.set_db(self.db)

    def test_simple_save(self):
        """"test to save a simple host"""
        self.host1 = fill_couch.save_or_create_host(
            fill_couch.Host,
            name="eris")
        self.assertTrue(isinstance(
            self.host1,
            fill_couch.Host))
        self.host1.delete()

    def test_complex_host_save(self):
        """"test to save a simple host"""
        self.host2 = fill_couch.save_or_create_host(
            fill_couch.Host,
            name="fnord",
            cpu_family="fam10",
            )
        self.assertTrue(isinstance(
            self.host2,
            fill_couch.Host))
        self.assertEqual(self.host2.name, "fnord")
        self.assertEqual(self.host2.cpu_family, "fam10")
        self.host2.delete()

    def tearDown(self):
        del(self.db)

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