Exemplo n.º 1
0
    def test_edit_agreements_list(self):
        """edit view displays list of user's agreements"""
        test_user = UserModel.objects.create_user('Bob', '*****@*****.**', 'pass123')
        test_link = reverse(
            'misago:admin:users:accounts:edit', kwargs={
                'pk': test_user.pk,
            }
        )

        agreement = Agreement.objects.create(
            type=Agreement.TYPE_TOS,
            title="Test agreement!",
            text="Lorem ipsum!",
            is_active=True,
        )

        response = self.client.get(test_link)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, agreement.title)

        save_user_agreement_acceptance(test_user, agreement, commit=True)

        response = self.client.get(test_link)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, agreement.title)
def save_user_agreements(user, form):
    if not form.agreements:
        return

    for field_name in form.agreements.keys():
        agreement_id = form.cleaned_data[field_name]
        agreement = Agreement.objects.get(id=agreement_id)
        save_user_agreement_acceptance(user, agreement)

    user.save(update_fields=['agreements'])
Exemplo n.º 3
0
    def test_commit(self):
        user = self.get_authenticated_user()

        agreement = Agreement.objects.create(
            type=Agreement.TYPE_PRIVACY,
            link='https://somewhre.com',
            text='Lorem ipsum',
        )

        save_user_agreement_acceptance(user, agreement, commit=True)
        self.assertEqual(user.agreements, [agreement.id])

        user.refresh_from_db()
        self.assertEqual(user.agreements, [agreement.id])

        UserAgreement.objects.get(user=user, agreement=agreement)
        self.assertEqual(UserAgreement.objects.count(), 1)