s4:tests: fix use of a non-existent word (existant)
[Samba/gebeck_regimport.git] / source4 / scripting / python / samba / tests / samba_tool / timecmd.py
blob000f0f2828228c8b2b7050599f0a5c5d2ef122ff
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import os
19 from time import localtime, strptime, mktime
20 from samba.tests.samba_tool.base import SambaToolCmdTest
22 class TimeCmdTestCase(SambaToolCmdTest):
23 """Tests for samba-tool time subcommands"""
25 def test_timeget(self):
26 """Run time against the server and make sure it looks accurate"""
27 (result, out, err) = self.runcmd("time", os.environ["SERVER"])
28 self.assertCmdSuccess(result, "Ensuring time ran successfully")
30 timefmt = strptime(out, "%a %b %d %H:%M:%S %Y %Z\n")
31 servertime = int(mktime(timefmt))
32 now = int(mktime(localtime()))
34 # because there is a race here, allow up to 5 seconds difference in times
35 delta = 5
36 self.assertTrue((servertime > (now - delta) and (servertime < (now + delta)), "Time is now"))
38 def test_timefail(self):
39 """Run time against a non-existent server, and make sure it fails"""
40 (result, out, err) = self.runcmd("time", "notaserver")
41 self.assertEquals(result, -1, "check for result code")
42 self.assertTrue(err.strip().endswith("NT_STATUS_OBJECT_NAME_NOT_FOUND"), "ensure right error string")
43 self.assertEquals(out, "", "ensure no output returned")