def test_convenience_need(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) needed = init_needed() assert get_needed() == needed assert get_needed().resources() == [] y1.need() assert get_needed().resources() == [x2, x1, y1]
def test_convenience_need(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) needed = init_needed() assert get_needed() == needed assert get_needed().resources() == [] y1.need() assert get_needed().resources() == [x2, x1, y1]
def test_resource_need_should_pass_slots_to_needed(): import fanstatic lib = Library('lib', '') c = Resource(lib, 'c.js') slot = Slot(lib, '.js', depends=[c]) a = Resource(lib, 'a.js', depends=[slot]) b = Resource(lib, 'b.js', depends=[c]) needed = fanstatic.init_needed() try: a.need({slot: c}) finally: fanstatic.del_needed() assert slot in needed._slots
def test_resource_need_should_pass_slots_to_needed(): import fanstatic lib = Library("lib", "") c = Resource(lib, "c.js") slot = Slot(lib, ".js", depends=[c]) a = Resource(lib, "a.js", depends=[slot]) b = Resource(lib, "b.js", depends=[c]) needed = fanstatic.init_needed() try: a.need({slot: c}) finally: fanstatic.del_needed() assert slot in needed._slots
def test_convenience_clear(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) z1 = Resource(foo, 'd.js') z2 = Resource(foo, 'e.js', depends=[z1, x1]) needed = init_needed(resources=[y1]) assert sort_resources(needed.resources()) == [x2, x1, y1] # For some reason,for example an error page needs to be rendered, # the currently needed resources need to be cleared. clear_needed() assert len(needed.resources()) == 0 z2.need() assert sort_resources(needed.resources()) == [x1, z1, z2]
def test_convenience_clear(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) z1 = Resource(foo, 'd.js') z2 = Resource(foo, 'e.js', depends=[z1, x1]) needed = init_needed(resources=[y1]) assert sort_resources(needed.resources()) == [x2, x1, y1] # For some reason,for example an error page needs to be rendered, # the currently needed resources need to be cleared. clear_needed() assert len(needed.resources()) == 0 z2.need() assert sort_resources(needed.resources()) == [x1, z1, z2]
class TestUnicodeError(unittest.TestCase): _custom_config = { 'fanstatic.publisher_signature': 'custom_sign', } def setUp(self): from fanstatic import Library, Resource from fanstatic import set_resource_file_existence_checking set_resource_file_existence_checking(False) self.lib = Library('foo', '') # When the resources contains an unicode string fanstatic may break # if the HTML is only str. self.resource = Resource(self.lib, u'resource.js') self.config = testing.setUp() self.config.registry.settings.update(self._custom_config) self.config.include("pyramid_fanstatic") self.config.add_route('home', '/') self.config.add_view(route_name='home', view=self.home) self.app = TestApp(self.config.make_wsgi_app()) def home(self, request): resp = request.response resp.content_type = 'text/html; charset=utf-8' resp.body = '''\ <html> <head> </head> <body> <p>Voil\xc3\xa0 !</p> </body> </html> ''' self.resource.need() return resp def test_unicode_error_should_not_be_raised(self): self.app.get('/') def tearDown(self): from fanstatic import set_resource_file_existence_checking testing.tearDown() set_resource_file_existence_checking(True)
from fanstatic import Resource, Group, Library library = Library('dummy', '.') library.need = lambda: 'No, sorry, that is a Library.' resource = Resource(library, 'fanstatic_dummy_resource.css') resource.need = lambda: 'needed resource' group = Group([resource]) group.need = lambda: 'needed group'