Пример #1
0
    def test_write_items_duplicate(self, write_mock):
        template_path = "item.html"
        units = make_units_mock()[:2]
        units[1].path = units[0].path

        assert units[0].path == units[1].path
        with open(units[1].path, "w"):
            self.assertRaises(IOError, self.engine._write_items, units, template_path)
        os.remove(units[1].path)
Пример #2
0
    def test_chain_item_permalinks_ok(self):
        units = make_units_mock()[1:-1]
        assert [unit.id for unit in units] == ['2', '3', '4']
        chain_item_permalinks(units)

        self.assertEqual(units[0].permalink_next, units[1].permalink)
        self.assertFalse(hasattr(units[0], 'permalink_prev'))

        self.assertEqual(units[1].permalink_next, units[2].permalink)
        self.assertEqual(units[1].permalink_prev, units[0].permalink)

        self.assertFalse(hasattr(units[-1], 'permalink_next'))
        self.assertEqual(units[-1].permalink_prev, units[1].permalink)
Пример #3
0
    def test_write_items_ok(self, write_mock):
        template_path = 'item.html'
        units = make_units_mock()[:2]
        self.engine._write_items(units, template_path)

        if sys.version_info[0] < 3:
            rendered = '\xd1\x8e\xd0\xbd\xd0\xb8\xd0\xba\xd0\xbe\xd0\xb4\xd0\xb0'
        else:
            rendered = 'юникода'

        call1 = call(os.path.join(USER_DIR, '1'), rendered + '|1')
        call2 = call(os.path.join(USER_DIR, '2'), rendered + '|2')
        self.assertEqual([call1, call2], write_mock.call_args_list)
Пример #4
0
    def test_chain_item_permalinks_ok(self):
        units = make_units_mock()[1:-1]
        assert [unit.id for unit in units] == ["2", "3", "4"]
        chain_item_permalinks(units)

        self.assertEqual(units[0].permalink_next, units[1].permalink)
        self.assertFalse(hasattr(units[0], "permalink_prev"))

        self.assertEqual(units[1].permalink_next, units[2].permalink)
        self.assertEqual(units[1].permalink_prev, units[0].permalink)

        self.assertFalse(hasattr(units[-1], "permalink_next"))
        self.assertEqual(units[-1].permalink_prev, units[1].permalink)
Пример #5
0
    def test_write_items_ok(self, write_mock):
        template_path = "item.html"
        units = make_units_mock()[:2]
        self.engine._write_items(units, template_path)

        if sys.version_info[0] < 3:
            rendered = "\xd1\x8e\xd0\xbd\xd0\xb8\xd0\xba\xd0\xbe\xd0\xb4\xd0\xb0"
        else:
            rendered = "юникода"

        call1 = call(os.path.join(USER_DIR, "1"), rendered + "|1")
        call2 = call(os.path.join(USER_DIR, "2"), rendered + "|2")
        self.assertEqual([call1, call2], write_mock.call_args_list)
Пример #6
0
 def units(self):
     if not hasattr(self, '_lazy_units'):
         setattr(self, '_lazy_units', make_units_mock())
     return self._lazy_units
Пример #7
0
 def units(self):
     if not hasattr(self, "_lazy_units"):
         setattr(self, "_lazy_units", make_units_mock())
     return self._lazy_units