def test_pages_generation(self): '''Tests generation of the page nested list''' class MockNode(object): def __init__(self, title): self.id = random.randint(1, 100) self.title = title self.children = MockQuerySet([]) self.is_root = False self.idevices = Mock() self.idevices.all.return_value = [] def unique_name(self): return "%s_%s" % (self.title, self.id) class MockQuerySet(object): def __init__(self, values): self.values = values def all(self): return self.values def exists(self): return bool(self.values) nodes = [MockNode("Node%s" % x) for x in range(4)] nodes[0].is_root = True nodes[0].children = MockQuerySet([nodes[1], nodes[2]]) nodes[2].children = MockQuerySet([nodes[3]]) mock_exporter = WebsiteExport(Mock(), Mock()) mock_exporter.generate_pages(nodes[0], 1) pages = mock_exporter.pages pages.insert(0, None) pages.append(None) for i in range(1, len(pages) - 1): page = pages[i] if i != 0: self.assertEquals(page.prev_page, pages[i - 1]) if i != len(pages): self.assertEquals(page.next_page, pages[i + 1])
def test_basic_export(self): '''Exports a package''' exporter = WebsiteExport(self.data, settings.MEDIA_ROOT + "/111.zip") exporter.export()
from exeapp.models import Package from exeapp.views.export.websiteexport import WebsiteExport data = Package.objects.get(id=3).get_data_package() we = WebsiteExport(data)