def test_add_tag(self):
    apple = self.food_model.objects.create(name='apple')
    self.assertEqual(list(apple.tags.all()), [])
    self.assertEqual(list(self.food_model.tags.all()), [])
    apple.tags.add('green')
    self.assert_tags_equal(apple.tags.all(), ['green'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green'])
    pear = self.food_model.objects.create(name='pear')
    pear.tags.add('green')
    self.assert_tags_equal(pear.tags.all(), ['green'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green'])
    apple.tags.add('red')
    self.assert_tags_equal(apple.tags.all(), ['green', 'red'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green', 'red'])
    self.assert_tags_equal(self.food_model.tags.most_common(), ['green', 'red'], sort=False)
    apple.tags.remove('green')
    self.assert_tags_equal(apple.tags.all(), ['red'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green', 'red'])
    tag = self.tag_model.objects.create(name='delicious')
    apple.tags.add(tag)
    self.assert_tags_equal(apple.tags.all(), ['red', 'delicious'])
    apple.delete()
    self.assert_tags_equal(self.food_model.tags.all(), ['green'])
def test_add_tag(self):
    apple = self.food_model.objects.create(name='apple')
    self.assertEqual(list(apple.tags.all()), [])
    self.assertEqual(list(self.food_model.tags.all()), [])
    apple.tags.add('green')
    self.assert_tags_equal(apple.tags.all(), ['green'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green'])
    pear = self.food_model.objects.create(name='pear')
    pear.tags.add('green')
    self.assert_tags_equal(pear.tags.all(), ['green'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green'])
    apple.tags.add('red')
    self.assert_tags_equal(apple.tags.all(), ['green', 'red'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green', 'red'])
    self.assert_tags_equal(self.food_model.tags.most_common(), ['green', 'red'], sort=False)
    apple.tags.remove('green')
    self.assert_tags_equal(apple.tags.all(), ['red'])
    self.assert_tags_equal(self.food_model.tags.all(), ['green', 'red'])
    tag = self.tag_model.objects.create(name='delicious')
    apple.tags.add(tag)
    self.assert_tags_equal(apple.tags.all(), ['red', 'delicious'])
    apple.delete()
    self.assert_tags_equal(self.food_model.tags.all(), ['green'])