def test_publish_loops_through_all_resources(): mox = Mox() http_request, model_base, manager, model, queryset = get_mocks(mox) fs_mock = mox.CreateMockAnything() f = mox.CreateMockAnything() fs_mock.join( 'test_web_root', 'some_path_1/index.html').AndReturn('test_web_root/some_path_1') fs_mock.dirname('test_web_root/some_path_1').AndReturn('test_web_root') fs_mock.exists("test_web_root").AndReturn(True) filename = "some_temp_file" fs_mock.tempfile(directory="test_web_root").AndReturn([f, filename]) fs_mock.write(f, "some_content") fs_mock.close(f) fs_mock.chmod( filename, stat.S_IREAD | stat.S_IWRITE | stat.S_IWUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) fs_mock.rename('some_temp_file', 'test_web_root/some_path_1') fs_mock.join( 'test_web_root', 'some_path_2/index.html').AndReturn('test_web_root/some_path_2') fs_mock.dirname('test_web_root/some_path_2').AndReturn('test_web_root') fs_mock.exists("test_web_root").AndReturn(True) filename = "some_temp_file" fs_mock.tempfile(directory="test_web_root").AndReturn([f, filename]) fs_mock.write(f, "some_content") fs_mock.close(f) fs_mock.chmod( filename, stat.S_IREAD | stat.S_IWRITE | stat.S_IWUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) fs_mock.rename('some_temp_file', 'test_web_root/some_path_2') settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() try: get_content_from_path = StaticGenerator.get_content_from_path StaticGenerator.get_content_from_path = lambda self, path: "some_content" instance = StaticGenerator("some_path_1", "some_path_2", http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock) instance.publish() mox.VerifyAll() finally: StaticGenerator.get_content_from_path = get_content_from_path
def test_publish_loops_through_all_resources(self): instance = StaticGenerator('/some_path_1', '/some_path_2') rename = Mock(wraps=os.rename) with nested(patch('os.rename', rename), patch.object(instance, 'get_content_from_path', Mock(return_value='some_content'))): instance.publish() rename.assert_has_calls([ call(ANY, 'test_web_root/fresh/some_path_1'), call(ANY, 'test_web_root/fresh/some_path_2')])
def test_publish_loops_through_all_resources(): mox = Mox() http_request, model_base, manager, model, queryset = get_mocks(mox) fs_mock = mox.CreateMockAnything() f = mox.CreateMockAnything() fs_mock.join('test_web_root', 'some_path_1/index.html').AndReturn('test_web_root/some_path_1') fs_mock.dirname('test_web_root/some_path_1').AndReturn('test_web_root') fs_mock.exists("test_web_root").AndReturn(True) filename = "some_temp_file" fs_mock.tempfile(directory="test_web_root").AndReturn([f, filename]) fs_mock.write(f, "some_content") fs_mock.close(f) fs_mock.chmod(filename, stat.S_IREAD | stat.S_IWRITE | stat.S_IWUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) fs_mock.rename('some_temp_file', 'test_web_root/some_path_1') fs_mock.join('test_web_root', 'some_path_2/index.html').AndReturn('test_web_root/some_path_2') fs_mock.dirname('test_web_root/some_path_2').AndReturn('test_web_root') fs_mock.exists("test_web_root").AndReturn(True) filename = "some_temp_file" fs_mock.tempfile(directory="test_web_root").AndReturn([f, filename]) fs_mock.write(f, "some_content") fs_mock.close(f) fs_mock.chmod(filename, stat.S_IREAD | stat.S_IWRITE | stat.S_IWUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) fs_mock.rename('some_temp_file', 'test_web_root/some_path_2') settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() try: get_content_from_path = StaticGenerator.get_content_from_path StaticGenerator.get_content_from_path = lambda self, path: "some_content" instance = StaticGenerator("some_path_1", "some_path_2", http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock) instance.publish() mox.VerifyAll() finally: StaticGenerator.get_content_from_path = get_content_from_path
def handle(self, *args, **options): if options['front']: paths = frozenset(['/', '/about/', '/legal/']) else: paths = frozenset(['/about/', '/legal/']) if options['id']: ct = ContentType.objects.get(app_label="repo", model=options['type']) obj = ct.get_object_for_this_type(pk=options['id']) paths |= frozenset(obj.get_url_list()) else: lobj_classes = [Topic, Module, Lesson, Question] for klass in lobj_classes: for lobj in klass.objects.all(): paths |= frozenset(lobj.get_url_list()) paths |= frozenset([reverse( "video_timeline", kwargs={"pk": timeline.presentation.pk, }) \ for timeline in PresentationAction.objects.all()]) gen = StaticGenerator(*list(paths), fs=S3StaticFileSystem()) gen.publish()
def publish_learning_object(self, obj): paths = obj.get_url_list() gen = StaticGenerator(*paths, fs=S3StaticFileSystem()) gen.publish()