예제 #1
0
 def setUp(self):
     self.invite = InviteFactory(first_name='Peter', last_name='Pan')
     self.activation_url = self.invite.get_activation_url()
     self.password = '******'
     self.post_data = {
         "user": {
             "password1": self.password,
             "password2": self.password
         }
     }
     self.response = self.client.patch(self.activation_url, data=self.post_data, format='json')
예제 #2
0
    def setUp(self):
        self.invite = InviteFactory(first_name='Peter', last_name='Pan')
        self.retrieve_path = reverse(
            'rest_invite_retrieve',
            kwargs={'tenant_name': self.invite.tenant.name, 'pk': self.invite.pk}
        )

        no_name_invite = InviteFactory()
        self.no_name_retrieve_path = reverse(
            'rest_invite_retrieve',
            kwargs={'tenant_name': no_name_invite.tenant.name, 'pk': no_name_invite.pk}
        )
예제 #3
0
 def test_existing_user(self):
     existing_user = UserFactory()
     existing_user_invite = InviteFactory(email=existing_user.email)
     existing_user_retrieve_path = reverse(
         'rest_invite_retrieve',
         kwargs={'tenant_name': existing_user_invite.tenant.name, 'pk': existing_user_invite.pk}
     )
     response = self.client.get(existing_user_retrieve_path)
     assert response.data['detail'] == f'Your account is now successfully connected to {existing_user_invite.tenant.name}.'
예제 #4
0
 def test_not_active(self):
     expired_creation_date = timezone.now() - timedelta(days=settings.TENANT_INVITE_EXPIRATION_IN_DAYS, hours=1)
     old_invite = InviteFactory(time_created=expired_creation_date)
     old_retrieve_path = reverse(
         'rest_invite_retrieve',
         kwargs = {'tenant_name': old_invite.tenant.name, 'pk': old_invite.pk}
     )
     response = self.client.get(old_retrieve_path)
     assert response.data['is_active'] == False
예제 #5
0
class TestInviteActivation(APITestCase):

    def setUp(self):
        self.invite = InviteFactory(first_name='Peter', last_name='Pan')
        self.activation_url = self.invite.get_activation_url()
        self.password = '******'
        self.post_data = {
            "user": {
                "password1": self.password,
                "password2": self.password
            }
        }
        self.response = self.client.patch(self.activation_url, data=self.post_data, format='json')

    def test_activation(self):
        assert self.response.status_code == status.HTTP_200_OK

    def test_user_created(self):
        User.objects.get(email=self.invite.email)

    def test_user_tenant_relationship_created(self):
        user = User.objects.get(email=self.invite.email)
        tenant = self.invite.tenant
        assert user.usertenantrelationship_set.filter(tenant=tenant)

    def test_user_can_login(self):
        login_path = reverse('rest_login')
        post_data = {"email": self.invite.email, "password": self.password}
        response = self.client.post(login_path, post_data)
        assert response.status_code == status.HTTP_200_OK

    def test_invite_already_used(self):
        response = self.client.patch(self.activation_url, data=self.post_data, format='json')
        assert response.data['error'] == 'The invitation was already used.'

    def test_existing_user(self):
        existing_user = UserFactory()
        existing_user_invite = InviteFactory(email=existing_user.email)
        existing_user_activation_url = existing_user_invite.get_activation_url()
        response = self.client.patch(existing_user_activation_url, data=self.post_data, format='json')
        assert response.data['error'] == 'You are already a user, please use the link from the email.'

    def test_inactive_invite(self):
        expired_creation_date = timezone.now() - timedelta(days=settings.TENANT_INVITE_EXPIRATION_IN_DAYS, hours=1)
        old_invite = InviteFactory(time_created=expired_creation_date)
        old_invite_activation_url = old_invite.get_activation_url()
        response = self.client.patch(old_invite_activation_url, data=self.post_data, format='json')
        assert response.data['error'] == 'The invitation was not used while it was active.'
예제 #6
0
 def test_inactive_invite(self):
     expired_creation_date = timezone.now() - timedelta(days=settings.TENANT_INVITE_EXPIRATION_IN_DAYS, hours=1)
     old_invite = InviteFactory(time_created=expired_creation_date)
     old_invite_activation_url = old_invite.get_activation_url()
     response = self.client.patch(old_invite_activation_url, data=self.post_data, format='json')
     assert response.data['error'] == 'The invitation was not used while it was active.'
예제 #7
0
 def test_existing_user(self):
     existing_user = UserFactory()
     existing_user_invite = InviteFactory(email=existing_user.email)
     existing_user_activation_url = existing_user_invite.get_activation_url()
     response = self.client.patch(existing_user_activation_url, data=self.post_data, format='json')
     assert response.data['error'] == 'You are already a user, please use the link from the email.'
예제 #8
0
class TestInviteRetrieve(APITestCase):

    def setUp(self):
        self.invite = InviteFactory(first_name='Peter', last_name='Pan')
        self.retrieve_path = reverse(
            'rest_invite_retrieve',
            kwargs={'tenant_name': self.invite.tenant.name, 'pk': self.invite.pk}
        )

        no_name_invite = InviteFactory()
        self.no_name_retrieve_path = reverse(
            'rest_invite_retrieve',
            kwargs={'tenant_name': no_name_invite.tenant.name, 'pk': no_name_invite.pk}
        )

    def test_status(self):
        response = self.client.get(self.retrieve_path)
        assert response.status_code == status.HTTP_200_OK

    def test_first_name(self):
        response = self.client.get(self.retrieve_path)
        assert response.data['first_name'] == 'Peter'

    def test_last_name(self):
        response = self.client.get(self.retrieve_path)
        assert response.data['last_name'] == 'Pan'

    def test_active(self):
        response = self.client.get(self.retrieve_path)
        assert response.data['is_active'] == True

    def test_first_clicked(self):
        self.client.get(self.retrieve_path)
        self.invite.refresh_from_db()
        assert self.invite.first_clicked

    def test_first_clicked_not_updated(self):
        """Test whether clicking on the invite a second time would change the value of first_clicked."""
        self.client.get(self.retrieve_path)
        self.invite.refresh_from_db()
        first_clicked = deepcopy(self.invite.first_clicked)
        self.client.get(self.retrieve_path)
        self.invite.refresh_from_db()
        assert first_clicked == self.invite.first_clicked

    def test_no_first_name(self):
        response = self.client.get(self.no_name_retrieve_path)
        assert response.data['first_name'] == ''

    def test_no_last_name(self):
        response = self.client.get(self.no_name_retrieve_path)
        assert response.data['last_name'] == ''

    def test_not_active(self):
        expired_creation_date = timezone.now() - timedelta(days=settings.TENANT_INVITE_EXPIRATION_IN_DAYS, hours=1)
        old_invite = InviteFactory(time_created=expired_creation_date)
        old_retrieve_path = reverse(
            'rest_invite_retrieve',
            kwargs = {'tenant_name': old_invite.tenant.name, 'pk': old_invite.pk}
        )
        response = self.client.get(old_retrieve_path)
        assert response.data['is_active'] == False

    def test_existing_user(self):
        existing_user = UserFactory()
        existing_user_invite = InviteFactory(email=existing_user.email)
        existing_user_retrieve_path = reverse(
            'rest_invite_retrieve',
            kwargs={'tenant_name': existing_user_invite.tenant.name, 'pk': existing_user_invite.pk}
        )
        response = self.client.get(existing_user_retrieve_path)
        assert response.data['detail'] == f'Your account is now successfully connected to {existing_user_invite.tenant.name}.'
예제 #9
0
 def test_tenants_registration_rest_invite_activation_resolve(self):
     invite = InviteFactory()
     assert resolve(f'/api/sign-up/tenant/{self.tenant.name}/invite/{invite.pk}/activate/').view_name ==\
            'rest_invite_activation'
예제 #10
0
 def test_tenants_registration_rest_invite_activation_reverse(self):
     invite = InviteFactory()
     assert reverse('rest_invite_activation', kwargs={'tenant_name': self.tenant.name, 'pk': invite.pk}) ==\
            f'/api/sign-up/tenant/{self.tenant.name}/invite/{invite.pk}/activate/'