--- /dev/null
+# Black box tests for script/traffic_leaner
+#
+# Copyright (C) Catalyst IT Ltd. 2017
+#
+# 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""Blackbox tests for traffic_summary"""
+
+from contextlib import contextmanager
+import os
+import subprocess
+import tempfile
+
+from samba.tests import BlackboxTestCase
+
+SCRIPT = "script/traffic_summary.pl"
+DATA_DIR = "python/samba/tests/blackbox/testdata"
+INPUT = os.path.join(DATA_DIR, "traffic_summary.pdml")
+EXPECTED_FN = os.path.join(DATA_DIR, "traffic_summary.expected")
+
+
+@contextmanager
+def temp_file(temp_dir):
+ try:
+ tf = tempfile.NamedTemporaryFile(dir=temp_dir)
+ name = tf.name
+ tf.close()
+ yield name
+ finally:
+ if os.path.exists(name):
+ os.remove(name)
+
+
+class TrafficSummaryTests(BlackboxTestCase):
+
+ def check_twig(self):
+ """Check that perl XML::Twig module is installed.
+ Traffic summary depends on this module being installed.
+ """
+ line = "perl -MXML::Twig -e 1"
+ p = subprocess.Popen(line, shell=True)
+ retcode = p.wait()
+ return (retcode == 0)
+
+ def test_traffic_summary(self):
+ if not self.check_twig():
+ self.skipTest("Perl module XML::Twig is not installed")
+
+ with temp_file(self.tempdir) as output:
+ command = "%s %s >%s" % (SCRIPT, INPUT, output)
+ print command
+ self.check_run(command)
+ expected = open(EXPECTED_FN).readlines()
+ actual = open(output).readlines()
+ self.assertEquals(expected, actual)
+++ /dev/null
-#!/bin/sh
-
-if [ $# -lt 1 ]; then
-cat <<EOF
-Usage: test_traffic_summary.sh
-EOF
-exit 1;
-fi
-
-PREFIX="$1"
-shift 1
-ARGS=$@
-
-. `dirname $0`/../../testprogs/blackbox/subunit.sh
-
-script_dir=`dirname $0`/..
-input="$script_dir/testdata/traffic_summary.pdml"
-expected="$script_dir/testdata/traffic_summary.expected"
-output="$(mktemp $TMPDIR/traffic_summary.XXXXXXXXXXX)"
-ts="$script_dir/traffic_summary.pl"
-
-traffic_summary() {
-
- $ts $input >$output
- if [ "$?" != "0" ]; then
- return 1
- fi
-
- diff $output $expected
- if [ "$?" != "0" ]; then
- return 1
- fi
-}
-
-# Check the required perl modules for traffic_summary
-# skip the tests if they are not installed
-perl -MXML::Twig -e 1
-if [ "$?" != "0" ]; then
- subunit_start_test "traffic_summary"
- subunit_skip_test "traffic_summary" <<EOF
-perl module XML::Twig not installed
-EOF
-else
- testit "traffic_summary" traffic_summary
-fi
-
-exit $failed
planoldpythontestsuite("ad_dc_ntvfs",
"samba.tests.blackbox.traffic_learner",
extra_args=['-U"$USERNAME%$PASSWORD"'])
+planoldpythontestsuite("ad_dc_ntvfs",
+ "samba.tests.blackbox.traffic_summary",
+ extra_args=['-U"$USERNAME%$PASSWORD"'])
plantestsuite_loadlist("samba4.ldap.python(ad_dc_ntvfs)", "ad_dc_ntvfs", [python, os.path.join(samba4srcdir, "dsdb/tests/python/ldap.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '$LOADLIST', '$LISTOPT'])
plantestsuite_loadlist("samba4.tokengroups.krb5.python(ad_dc_ntvfs)", "ad_dc_ntvfs:local", [python, os.path.join(samba4srcdir, "dsdb/tests/python/token_group.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '-k', 'yes', '$LOADLIST', '$LISTOPT'])