コード例 #1
0
    def test_hosts(self):
        db = Database(C.getConnectionString())
        db.recreate()
        hosts = Hosts(db)

        h1 = hosts.create(u"test1", u"192.168.6.66")
        h2 = hosts.create(u"test2", u"192.168.6.77", u"ąść", u"password")

        allHosts = hosts.getAllHostsNames()
        self.assertListEqual([u"test1", u"test2"], allHosts)
        h2.user = u"łęść"

        # get once again host from database and asert its modified
        h2bis = hosts.get(u"test2")
        self.assertEqual(u"łęść", h2bis.user)

        # fields required
        self.assertRaises(IntegrityError, hosts.create,
                          None, None, None, None)
コード例 #2
0
ファイル: test_hosts.py プロジェクト: macarini2018/myrdp
class HostsTestCase(TestCase):
    def setUp(self):
        self.db = Database('sqlite://')  # in memory database
        self.db.create()
        self.ck = CryptoKey()
        self.hosts = Hosts(self.db, self.ck)

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

    def test_password(self):
        self.hosts.create("first host", "address", "user", "password")
        host1 = self.hosts.get("first host")
        self.assertEqual(host1.password, "password")

        self.hosts.create("second host",
                          "address",
                          "user",
                          password="******")
        host1 = self.hosts.get("first host")
        self.assertEqual(host1.password, "password")

        host2 = self.hosts.get("second host")
        self.assertEqual(host2.password, "differentpassword")

    def test_nonePassword(self):
        self.hosts.create("host", "address", None, None)
        host = self.hosts.get("host")
        self.assertIsNone(host.password)

    def test_updatePassword(self):
        host = self.hosts.create("host", "address", None, None)
        self.hosts.updateHostValues(host, {"password": "******"})
        host = self.hosts.get("host")
        self.assertEqual(host.password, "abc")

        self.hosts.updateHostValues(host, {"password": "******"})
        host = self.hosts.get("host")
        self.assertEqual(host.password, "def")

        self.hosts.updateHostValues(host, {"password": None})
        host = self.hosts.get("host")
        self.assertIsNone(host.password)