Esempio n. 1
0
    def test_validate_email_to_link_normal(self):
        email = FAKER.email()
        assert len(PendingEnterpriseCustomerUser.objects.filter(user_email=email)) == 0, \
            "Precondition check - should not have PendingEnterpriseCustomerUser"
        assert len(EnterpriseCustomerUser.objects.all()) == 0, \
            "Precondition check - should not have EnterpriseCustomerUser"

        exists = validate_email_to_link(email)  # should not raise any Exceptions
        assert exists is False
    def test_validate_email_to_link_normal(self):
        email = FAKER.email()  # pylint: disable=no-member
        assert PendingEnterpriseCustomerUser.objects.filter(user_email=email).count() == 0, \
            "Precondition check - should not have PendingEnterpriseCustomerUser"
        assert EnterpriseCustomerUser.objects.count() == 0, \
            "Precondition check - should not have EnterpriseCustomerUser"

        exists = validate_email_to_link(email)  # should not raise any Exceptions
        assert exists is False
Esempio n. 3
0
    def test_delete_not_linked(self):
        assert self.client.login(
            username=self.user.username,
            password="******")  # make sure we've logged in
        email = FAKER.email()
        query_string = six.moves.urllib.parse.urlencode(
            {"unlink_email": email})

        response = self.client.delete(self.view_url + "?" + query_string)

        assert response.status_code == 404
        expected_message = "Email {email} is not linked to Enterprise Customer {ec_name}".format(
            email=email, ec_name=self.enterprise_customer.name)
        assert response.content.decode("utf-8") == expected_message
Esempio n. 4
0
    def test_post_existing_record(self):
        # precondition checks:
        assert self.client.login(
            username=self.user.username,
            password="******")  # make sure we've logged in

        email = FAKER.email()

        user = UserFactory(email=email)
        EnterpriseCustomerUserFactory(user_id=user.id)
        assert len(EnterpriseCustomerUser.objects.filter(user_id=user.id)) == 1
        response = self.client.post(self.view_url, data={"email": email})
        self._test_post_existing_record_response(response)
        assert len(EnterpriseCustomerUser.objects.filter(user_id=user.id)) == 1
    def test_validate_email_to_link_existing_pending_record(self, ignore_existing):
        email = FAKER.email()  # pylint: disable=no-member
        existing_record = PendingEnterpriseCustomerUserFactory(user_email=email)
        assert PendingEnterpriseCustomerUser.objects.get(user_email=email) == existing_record, \
            "Precondition check - should have PendingEnterpriseCustomerUser"
        assert not EnterpriseCustomerUser.objects.exists(), \
            "Precondition check - should not have EnterpriseCustomerUser"

        if ignore_existing:
            exists = validate_email_to_link(email, ignore_existing=True)
            assert exists
        else:
            expected_message = ValidationMessages.USER_ALREADY_REGISTERED.format(
                email=email, ec_name=existing_record.enterprise_customer.name
            )

            with raises(ValidationError, match=expected_message):
                exists = validate_email_to_link(email)
Esempio n. 6
0
    def test_delete_linked(self):
        assert self.client.login(
            username=self.user.username,
            password="******")  # make sure we've logged in

        email = FAKER.email()
        user = UserFactory(email=email)
        EnterpriseCustomerUserFactory(
            enterprise_customer=self.enterprise_customer, user_id=user.id)
        query_string = six.moves.urllib.parse.urlencode(
            {"unlink_email": email})

        assert len(EnterpriseCustomerUser.objects.filter(user_id=user.id)) == 1

        response = self.client.delete(self.view_url + "?" + query_string)

        assert response.status_code == 200
        assert json.loads(response.content.decode("utf-8")) == {}
        assert len(EnterpriseCustomerUser.objects.filter(user_id=user.id)) == 0
    def test_email_or_username__to__email_something_else(self):
        email_or_username = FAKER.email()  # pylint: disable=no-member

        assert email_or_username__to__email(email_or_username) == email_or_username
Esempio n. 8
0
    def test_email_or_username__to__email_something_else(self):
        email_or_username = FAKER.email()

        assert email_or_username__to__email(email_or_username) == email_or_username