from pushmanager.testing.testservlet import TemplateTestCase


class PushesTemplateTest(TemplateTestCase):

    authenticated = True
    pushes_page = 'pushes.html'
    new_push_page = 'new-push.html'

    def render_pushes_page(self, page_title='Pushes', pushes=[], pushes_per_page=50, last_push=None):
        return self.render_etree(self.pushes_page,
            page_title=page_title,
            pushes=pushes,
            rpp=pushes_per_page,
            last_push=last_push
        )

    def test_include_new_push(self):
        tree = self.render_pushes_page()

        found_form = []
        for form in tree.iter('form'):
            if form.attrib['id'] == 'push-info-form':
                found_form.append(form)

        T.assert_equal(len(found_form), 1)


if __name__ == '__main__':
    T.run()
class TestDiscoverIgnoreImportedThings(DiscoveryTestCase):
    def test_imported_things_are_ignored(self):
        discovered_imported = list(test_discovery.discover("test.test_suite_subdir.import_testcase"))
        discovered_actually_defined_in_module = list(test_discovery.discover("test.test_suite_subdir.define_testcase"))

        assert_length(discovered_imported, 0)
        assert_length(discovered_actually_defined_in_module, 1)


class ImportTestClassCase(DiscoveryTestCase):
    def discover(self, module_path, class_name):
        return test_discovery.import_test_class(module_path, class_name)

    def test_discover_testify_case(self):
        assert self.discover("test.test_suite_subdir.define_testcase", "DummyTestCase")

    def test_discover_unittest_case(self):
        assert self.discover("test.test_suite_subdir.define_unittestcase", "TestifiedDummyUnitTestCase")

    def test_discover_bad_case(self):
        assert_raises(test_discovery.DiscoveryError, self.discover, "bad.subdir", "DummyTestCase")
        assert_raises(
            test_discovery.DiscoveryError, self.discover, "test.test_suite_subdir.define_testcase", "IGNORE ME"
        )


if __name__ == "__main__":
    run()

# vim: set ts=4 sts=4 sw=4 et:
Example #3
0
        testify.assert_equal(self.get_perm_mask(self.path), 0666)

    def test_custom_mode(self):
        # Turn off umask
        os.umask(0000)

        # Create a db with a custom mode
        mode = 0600
        sqlite3dbm.dbm.SqliteMap(self.path, flag='c', mode=mode)
        testify.assert_equal(self.get_perm_mask(self.path), mode)

    def test_respects_umask(self):
        mode = 0777
        umask = 0002
        os.umask(umask)
        expected_mode = mode & ~umask

        sqlite3dbm.dbm.SqliteMap(self.path, flag='c', mode=mode)
        testify.assert_equal(self.get_perm_mask(self.path), expected_mode)


class SanityCheckOpen(SqliteCreationTest):
    def test_open_creates(self):
        smap = sqlite3dbm.dbm.open(self.path, flag='c')
        smap['foo'] = 'bar'
        testify.assert_equal(smap['foo'], 'bar')


if __name__ == '__main__':
    testify.run()
Example #4
0
        self.obs = obs
        self.event = event
        self.watch(obs, event)
        self.has_watched = 0

    def handler(self, obs, event):
        assert_equal(obs, self.obs)
        assert_equal(event, self.event)
        self.has_watched += 1


class ObserverTestCase(TestCase):
    @setup
    def setup_observer(self):
        self.obs = Observable()

    def test_watch(self):
        event = "FIVE"
        handler = MockObserver(self.obs, event)

        self.obs.notify(event)
        assert_equal(handler.has_watched, 1)
        self.obs.notify("other event")
        assert_equal(handler.has_watched, 1)
        self.obs.notify(event)
        assert_equal(handler.has_watched, 2)


if __name__ == "__main__":
    run()
                self.people, "Push starting! %s" % self.pushmanager_url)

    def test_send_notifications_empty_user_list(self):
        """If there is no pending push request we'll only send IRC and
        email notifications, but not XMPP messages."""
        self.people = []
        self.pushmanager_url = "fake_push_url"
        self.pushtype = "fake_puth_type"

        with self.mocked_notifications() as (mocked_call, mocked_mail,
                                             mocked_xmpp):
            send_notifications(self.people, self.pushtype,
                               self.pushmanager_url)
            mocked_call.assert_called_once_with([
                '/nail/sys/bin/nodebot',
                '-i',
                Settings['irc']['nickname'],
                Settings['irc']['channel'],
                mock.ANY,  # msg
            ])
            mocked_mail.assert_called_once_with(
                Settings['mail']['notifyall'],
                mock.ANY,  # msg
                mock.ANY,  # subject
            )
            T.assert_is(mocked_xmpp.called, False)


if __name__ == '__main__':
    T.run()
Example #6
0
                os.path.join(self.tmpdir, name % i) for i in xrange(num_iters)
            ]
            return [sqlite3dbm.sshelve.open(path) for path in db_paths]

        update_dbs = setup_dbs('update')
        insert_dbs = setup_dbs('insert')

        # Setup data
        insert_data = [('foo%d' % i, 'bar%d' % i)
                       for i in xrange(insert_per_iter)]

        # Time upates
        update_start = time.time()
        for update_db in update_dbs:
            update_db.update(insert_data)
        update_time = time.time() - update_start

        # Time inserts
        insert_start = time.time()
        for insert_db in insert_dbs:
            for k, v in insert_data:
                insert_db[k] = v
        insert_time = time.time() - insert_start

        # Inserts should take a subsantially greater amount of time
        testify.assert_gt(insert_time, min_ratio * update_time)


if __name__ == '__main__':
    testify.run()