def test_save(self): '''Make sure slugify works and is unique only per parent.''' # Parent tests basic slug creation. parent = Topic(text='Parent') parent.save() expected = 'parent' actual = parent.slug self.failUnlessEqual(expected, actual, 'Parent slug was %s but expected %s' % (actual, expected)) # Child tests slug with parent. child = Topic(text='Child', parent=parent) child.save() expected = 'child' actual = child.slug self.failUnlessEqual(actual, expected, 'Child slug was %s but expected %s' % (actual, expected)) # Child2 tests slug with same name under same parent. child2 = Topic(text='Child', parent=parent) try: child2.save() result = False except: result = True self.assertTrue(result, "Unique Together attribute of Topic failed.") # Try one with different parent name but same child name as another parent. parent2 = Topic(text='Parent2') parent2.save() child3 = Topic(text='Child', parent=parent2) child3.save() expected = 'child' actual = child3.slug self.failUnlessEqual(actual, expected, 'Child3 slug was %s but expected %s' % (actual, expected))
def import_catagories(self): '''Parses and imports the catagories from a blog posts.''' topics = self.chan.findall(self.wp_ns + 'category') for topic in topics: t = Topic() t.text = topic.find(self.wp_ns + 'cat_name').text t.slug = topic.find(self.wp_ns + 'category_nicename').text if topic.find(self.wp_ns + 'category_parent').text: t.parent = Topic.objects.get(slug=topic.find(self.wp_ns + 'category_parent').text) t.save()