class TestMessageCategories(unittest.TestCase): def setUp(self): self.message = MessageFactory(user=None) self.category = CategoryFactory() def tearDown(self): self.message.delete() self.category.delete() def test_add_category(self): before = len(self.message.category.all()) self.message.category.add(self.category) self.assertEqual(len(self.message.category.all()), before + 1) def test_added_category_stored(self): self.message.category.add(self.category) m = Message.objects.get(id=self.message.pk) self.assertIn(self.category, m.category.all()) def test_added_category_twice(self): before = len(self.message.category.all()) self.message.category.add(self.category) self.message.category.add(self.category) self.assertEqual(len(self.message.category.all()), before + 1) def test_remove_category(self): self.message.category.add(self.category) before = self.message.category.count() self.message.category.remove(self.category) self.assertNotIn(self.category, self.message.category.all()) self.assertEqual(self.message.category.count(), before - 1)
class TestMessageLocation(unittest.TestCase): def setUp(self): self.message = MessageFactory() def tearDown(self): user = self.message.user self.message.delete() user.delete() def test_location_latitude(self): self.assertIsNotNone(self.message.location.x) def test_location_longitude(self): self.assertIsNotNone(self.message.location.y) def test_location(self): self.assertIsNotNone(self.message.location)