test_paver_bok_choy_cmds.py 3.01 KB
Newer Older
1 2 3 4
"""
Tests for the bok-choy paver commands themselves.
Run just this test with: paver test_lib -t pavelib/paver_tests/test_paver_bok_choy_cmds.py
"""
5 6
import os
import unittest
7
from pavelib.utils.test.suites import BokChoyTestSuite
8 9 10 11

REPO_DIR = os.getcwd()


12
class TestPaverBokChoyCmd(unittest.TestCase):
13

14 15 16 17 18
    def _expected_command(self, name, store=None):
        """
        Returns the command that is expected to be run for the given test spec
        and store.
        """
19
        shard = os.environ.get('SHARD')
20 21
        expected_statement = (
            "DEFAULT_STORE={default_store} "
22 23 24
            "SCREENSHOT_DIR='{repo_dir}/test_root/log{shard_str}' "
            "BOK_CHOY_HAR_DIR='{repo_dir}/test_root/log{shard_str}/hars' "
            "SELENIUM_DRIVER_LOG_DIR='{repo_dir}/test_root/log{shard_str}' "
25
            "nosetests {repo_dir}/common/test/acceptance/{exp_text} "
26
            "--with-xunit "
27 28
            "--xunit-file={repo_dir}/reports/bok_choy{shard_str}/xunit.xml "
            "--verbosity=2 "
29
        ).format(
30
            default_store=store,
31
            repo_dir=REPO_DIR,
32
            shard_str='/shard_' + shard if shard else '',
33
            exp_text=name,
34
        )
35
        return expected_statement
36

37 38 39 40
    def test_default(self):
        suite = BokChoyTestSuite('')
        name = 'tests'
        self.assertEqual(suite.cmd, self._expected_command(name=name))
41

42 43 44 45 46
    def test_suite_spec(self):
        spec = 'test_foo.py'
        suite = BokChoyTestSuite('', test_spec=spec)
        name = 'tests/{}'.format(spec)
        self.assertEqual(suite.cmd, self._expected_command(name=name))
47

48 49 50 51 52
    def test_class_spec(self):
        spec = 'test_foo.py:FooTest'
        suite = BokChoyTestSuite('', test_spec=spec)
        name = 'tests/{}'.format(spec)
        self.assertEqual(suite.cmd, self._expected_command(name=name))
53

54 55 56 57 58
    def test_testcase_spec(self):
        spec = 'test_foo.py:FooTest.test_bar'
        suite = BokChoyTestSuite('', test_spec=spec)
        name = 'tests/{}'.format(spec)
        self.assertEqual(suite.cmd, self._expected_command(name=name))
59

60 61 62 63 64 65 66 67
    def test_spec_with_draft_default_store(self):
        spec = 'test_foo.py'
        suite = BokChoyTestSuite('', test_spec=spec, default_store='draft')
        name = 'tests/{}'.format(spec)
        self.assertEqual(
            suite.cmd,
            self._expected_command(name=name, store='draft')
        )
68

69
    def test_invalid_default_store(self):
70
        # the cmd will dumbly compose whatever we pass in for the default_store
71 72 73 74 75 76
        suite = BokChoyTestSuite('', default_store='invalid')
        name = 'tests'
        self.assertEqual(
            suite.cmd,
            self._expected_command(name=name, store='invalid')
        )
77 78

    def test_serversonly(self):
79 80 81 82 83 84 85 86 87 88
        suite = BokChoyTestSuite('', serversonly=True)
        self.assertEqual(suite.cmd, "")

    def test_test_dir(self):
        test_dir = 'foo'
        suite = BokChoyTestSuite('', test_dir=test_dir)
        self.assertEqual(
            suite.cmd,
            self._expected_command(name=test_dir)
        )