def it_should_call_save_on_the_contact(mock_save): rf = helper.RequestFactory() mock_save.return_value = [{'status': '200'}, None] mock_request = rf.post('/notify/', dict(body=recurly_xml)) response = notify(mock_request, settings.RECURLY_API_KEY) assert response.status_code == 200 assert mock_save.called
def it_should_add_the_user_to_the_vault_on_sign_up(mock_email): vault = profile.create_vault(name='invitevault') email = '*****@*****.**' response = invite_to_vault(user, email, vault) token = re.search("/login/\?t=([a-fA-F0-9]{20})", repr(mock_email.call_args_list)).group(1) factory = helper.RequestFactory() params = {'name': 'Testier Monsenur', 'username': '******', 'email': '*****@*****.**', 'password1': 'pass', 'password2': 'pass', 'tos': 'checked', 'token': token, 'register': 'yes', } request = factory.post('/login/', params) response = login(request) testier = User.objects.get(username='******') assert testier assert testier in vault.members.all()
def it_should_call_save_on_the_invoice(mock_save): from recurly_parse_spec import recurly_successful_payment mock_save.return_value = [{'status': '200'}, None] rf = helper.RequestFactory() mock_request = rf.post('/notify/', dict(body=recurly_successful_payment)) response = notify(mock_request, settings.RECURLY_API_KEY) assert response.status_code == 200 assert mock_save.called
def ensure_premium_account_holder_key_returns_valid_response(): for plan in ('individual', 'business', 'corporate'): profile.plan = plan profile.save() rf = helper.RequestFactory() mock_request = rf.get('/froth/check_key') response = check_key(mock_request, profile.apikey) assert response.status_code == 200 profile.plan = 'free' profile.save()
def ensure_staff_key_returns_valid_response(): user.is_staff = True user.save() rf = helper.RequestFactory() mock_request = rf.get('/froth/check_key') response = check_key(mock_request, profile.apikey) assert response.status_code == 200 user.is_staff = False user.save()
def it_should_pass_the_notification_to_the_notification_parser(mock_parse): class TestObject: def save(self): return [{'status': '200'}, None] rf = helper.RequestFactory() mock_parse.return_value = TestObject() mock_request = rf.post('/notify/', dict(body=recurly_xml)) response = notify(mock_request, settings.RECURLY_API_KEY) assert response.status_code == 200 assert mock_parse.called
def ensure_vault_owner_can_invite_new_member_by_email(mock_invite): mock_invite.return_value = 'ok' profile.change_plan('corporate') vault = profile.create_vault(name='invitevault') email = '*****@*****.**' factory = helper.RequestFactory() url = '/vaults/%s/adduser/%s/' % (vault.id, urllib.quote(email)) request = factory.get(url, dict(HTTP_X_REQUESTED_WITH='XMLHttpRequest')) request.user = user response = vault_users(request, vault.id, email, 'adduser') assert mock_invite.called
def ensure_peasant_key_returns_invalid_response(): """Users who are not staff and not holders of premium accounts should not have valid API keys.""" # We don't actually need the next four lines. profile.plan = 'free' profile.save() user.is_staff = False user.save() rf = helper.RequestFactory() mock_request = rf.get('/froth/check_key') response = check_key(mock_request, profile.apikey) assert response.status_code == 402 # PaymentRequired
def ensure_valid_key_returns_org(): # We understand that the org returned by froth is the scraperwiki.com # username. profile.plan = 'business' profile.save() rf = helper.RequestFactory() mock_request = rf.get('/froth/check_key') response = check_key(mock_request, profile.apikey) assert response.status_code == 200 profile.plan = 'free' profile.save() j = json.loads(response.content) assert 'org' in j assert j['org'] == user.username
def ensure_invalid_key_returns_invalid_response(): rf = helper.RequestFactory() mock_request = rf.get('/froth/check_key') response = check_key(mock_request, "There's no way this is a valid api key.") assert response.status_code == 403 # Forbidden
def it_errors_if_apikey_wrong(): from recurly_parse_spec import recurly_successful_payment rf = helper.RequestFactory() mock_request = rf.post('/notify/', dict(body=recurly_successful_payment)) response = notify(mock_request, "sdfsdfsd") assert response.status_code == 403
def rendered_subscribe_page(): rf = helper.RequestFactory() mock_request = rf.get('/subscribe/') mock_request.user = user response = subscribe(mock_request, 'individual') return response