def test_save_org(rf, plan_factory, organization_plan_factory, mocker): # pylint: disable=protected-access mocker.patch("stripe.Plan.create") mocker.patch( "squarelet.organizations.models.Organization.set_subscription") plan_factory() organization_plan_factory() data = { "name": "john doe", "username": "******", "email": "*****@*****.**", "password1": "squarelet", "stripe_pk": "key", "stripe_token": "token", "plan": "organization", "organization_name": "my organization", } request = rf.post("/accounts/signup/", data) request.session = {} # MagicMock() request._messages = MagicMock() form = forms.SignupForm(data) assert form.is_valid() form.save(request) assert User.objects.filter(username=data["username"], email=data["email"], name=data["name"]).exists() assert Organization.objects.filter(name=data["organization_name"]).exists()
def test_clean_good(plan_factory): plan = plan_factory() data = { "name": "john doe", "username": "******", "email": "*****@*****.**", "password1": "squarelet", "stripe_pk": "key", "plan": plan.slug, } form = forms.SignupForm(data) assert form.is_valid()
def test_clean_bad_no_pay(professional_plan_factory, mocker): mocker.patch("stripe.Plan.create") professional_plan_factory() data = { "name": "john doe", "username": "******", "email": "*****@*****.**", "password1": "squarelet", "stripe_pk": "key", "plan": "professional", } form = forms.SignupForm(data) assert not form.is_valid() assert len(form.errors["plan"]) == 1
def test_clean_bad_no_org_name(organization_plan_factory, mocker): mocker.patch("stripe.Plan.create") organization_plan_factory() data = { "name": "john doe", "username": "******", "email": "*****@*****.**", "password1": "squarelet", "stripe_pk": "key", "plan": "organization", "stripe_token": "token", } form = forms.SignupForm(data) assert not form.is_valid() assert len(form.errors["organization_name"]) == 1
def test_save(rf, plan_factory): plan = plan_factory() data = { "name": "john doe", "username": "******", "email": "*****@*****.**", "password1": "squarelet", "stripe_pk": "key", "plan": plan.slug, } request = rf.post("/accounts/signup/", data) request.session = MagicMock() form = forms.SignupForm(data) assert form.is_valid() form.save(request) assert User.objects.filter(username=data["username"], email=data["email"], name=data["name"]).exists()