示例#1
0
        def try_init(path, should_succeed):
            success = False
            try:
                init_static_path(path)
                success = True
            except SijaxError:
                pass

            self.assertEqual(should_succeed, success)
示例#2
0
        def try_init(path, should_succeed):
            success = False
            try:
                init_static_path(path)
                success = True
            except SijaxError:
                pass

            self.assertEqual(should_succeed, success)
示例#3
0
    def test_init_static_path_helper_works(self):
        import os
        import sijax

        with temporary_dir() as static_path:
            init_static_path(static_path)

            version_file = os.path.join(static_path, 'sijax_version')
            if not os.path.exists(version_file):
                self.fail('Version file %s does not exist' % version_file)
            with open(version_file) as fp:
                self.assertEqual(fp.read(), sijax.__version__)

            core_js_file = os.path.join(static_path, 'sijax.js')

            # let's ensure that files are only written (or deleted)
            # if the version changes
            with open(core_js_file, 'w') as fp:
                fp.write('new stuff')
            init_static_path(static_path)
            # version file is the same, so it shouldn't touch it
            with open(core_js_file) as fp:
                self.assertEqual(fp.read(), 'new stuff')


            with open(version_file, 'w') as fp:
                fp.write('another_version_string')

            # let's also create another file (as it's from the old version)
            # and make sure that init will delete it
            new_file = os.path.join(static_path, 'extra-file.js')
            self.assertFalse(os.path.exists(new_file))
            with open(new_file, 'w') as fp:
                fp.write('blah')
            self.assertTrue(os.path.exists(new_file))

            # the version string is different, so we expect a complete resync
            # - extra files should be deleted, other files should be updated
            init_static_path(static_path)
            with open(core_js_file) as fp:
                self.assertNotEqual(fp.read(), 'new stuff')
            with open(version_file) as fp:
                self.assertEqual(fp.read(), sijax.__version__)
            self.assertFalse(os.path.exists(new_file))
示例#4
0
    def test_init_static_path_helper_works(self):
        import os
        import sijax

        with temporary_dir() as static_path:
            init_static_path(static_path)

            version_file = os.path.join(static_path, 'sijax_version')
            if not os.path.exists(version_file):
                self.fail('Version file %s does not exist' % version_file)
            with open(version_file) as fp:
                self.assertEqual(fp.read(), sijax.__version__)

            core_js_file = os.path.join(static_path, 'sijax.js')

            # let's ensure that files are only written (or deleted)
            # if the version changes
            with open(core_js_file, 'w') as fp:
                fp.write('new stuff')
            init_static_path(static_path)
            # version file is the same, so it shouldn't touch it
            with open(core_js_file) as fp:
                self.assertEqual(fp.read(), 'new stuff')

            with open(version_file, 'w') as fp:
                fp.write('another_version_string')

            # let's also create another file (as it's from the old version)
            # and make sure that init will delete it
            new_file = os.path.join(static_path, 'extra-file.js')
            self.assertFalse(os.path.exists(new_file))
            with open(new_file, 'w') as fp:
                fp.write('blah')
            self.assertTrue(os.path.exists(new_file))

            # the version string is different, so we expect a complete resync
            # - extra files should be deleted, other files should be updated
            init_static_path(static_path)
            with open(core_js_file) as fp:
                self.assertNotEqual(fp.read(), 'new stuff')
            with open(version_file) as fp:
                self.assertEqual(fp.read(), sijax.__version__)
            self.assertFalse(os.path.exists(new_file))