def test_suggestion_when_name_provided(self): Name.objects.create(user=self.user, given_name="First name", family_name="Last name") suggestions = Name.get_suggestion(self.user) self.assertEqual(len(suggestions), 0)
def test_suggestion_when_name_blank(self): suggestions = Name.get_suggestion(self.user) self.assertEqual(len(suggestions), 1) suggestion = suggestions[0] self.assertEqual(suggestion['msg'], "Please add your name.") self.assertEqual(suggestion['priority'], 5)
def save(self, u): first = self.cleaned_data.get("given_name", None) last = self.cleaned_data.get("family_name", None) try: obj = Name.objects.get(user=u, primary=True) if not first and not last: obj.delete() else: obj.given_name = first obj.family_name = last obj.save() except Name.DoesNotExist: obj = Name(user=u, primary=True, given_name=first, family_name=last) obj.save() u.gravatar = self.cleaned_data["gravatar"] u.save()