def test_get_related_return_manager_fail_no_related(self): relationship = Relationship(self.active_client, related_name='financial_planning') with self.assertRaisesMessage( AttributeError, "'return_manager' is valid only for" " \"to many\" relationships"): relationship.get_related(return_manager=True)
def test_get_related_many_wrong_pk(self): second_client = ActiveClientFactory() self.financial_adviser.clients.add(self.active_client, second_client) wrong_pk = 12312312 relationship = Relationship(self.financial_adviser, related_name='clients', pk=wrong_pk) with self.assertRaisesMessage( ObjectDoesNotExist, "Was not possible to get the object" " indicated by the information passed." " 'pk' not found."): relationship.get_related()
def test_get_related_many_none(self): self.assertIsNone(self.financial_adviser.clients.last()) relationship = Relationship(self.financial_adviser, related_name='clients') related = relationship.get_related() self.assertIsNone(related)
def test_get_related_not_many_none(self): self.assertFalse(hasattr(self.active_client, 'financial_planning')) relationship = Relationship(self.active_client, related_name='financial_planning') related = relationship.get_related() self.assertIsNone(related)
def test_get_related_not_many(self): self.active_client.financial_planning = self.financial_planning relationship = Relationship(self.active_client, related_name='financial_planning') related = relationship.get_related() self.assertEqual(related, self.financial_planning)
def test_get_related_many(self): second_client = ActiveClientFactory() self.financial_adviser.clients.add(self.active_client, second_client) relationship = Relationship(self.financial_adviser, related_name='clients') related = relationship.get_related() self.assertEqual(related, second_client)
def test_get_related_return_manager(self): relationship = Relationship(self.financial_adviser, related_name='clients') related_manager = relationship.get_related(return_manager=True) self.assertEqual(related_manager, self.financial_adviser.clients)