def get_context_data(self, *args, **kwargs): ctx = super(TeamDetailView, self).get_context_data(*args, **kwargs) ctx.update({ 'form_member_add': forms.TeamMemberAddForm(team=self.object), }) return ctx
def test_duplicate(self): user = UserFactory() team = TeamFactory() TeamMemberFactory(user=user, team=team, role='owner') data = { 'user': user.pk, 'role': 'owner', } form = forms.TeamMemberAddForm(data=data, team=team) assert not form.is_valid()
def test_save(self): user = UserFactory() team = TeamFactory() data = { 'user': user.pk, 'role': 'owner', } form = forms.TeamMemberAddForm(data=data, team=team) assert form.is_valid() form.save() assert team.users.count() == 1 member = team.members.first() assert member.user == user assert member.role == 'owner'