Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_addOnItem(self):
'''
Create a free add-on item and ensure that it is applied correctly.
'''
updateConstant('general__discountsEnabled', True)
test_combo, test_component = self.create_discount(
discountType=DiscountCombo.DiscountType.addOn,
name='Test Free Add-On',
)
s = self.create_series(pricingTier=self.defaultPricing)
response = self.register_to_check_discount(s)
self.assertEqual(response.redirect_chain,[(reverse('showRegSummary'), 302)])
self.assertEqual(response.context_data.get('totalPrice'), s.getBasePrice())
self.assertEqual(response.context_data.get('netPrice'), response.context_data.get('totalPrice'))
self.assertEqual(response.context_data.get('is_free'),False)
self.assertEqual(response.context_data.get('total_discount_amount'),0)
self.assertTrue(response.context_data.get('addonItems'))
self.assertFalse(response.context_data.get('discount_codes'))
def setUp(self):
self.user = self.create_user(email="boop@example.com")
self.org = self.create_organization(owner=self.user, name="My Org")
self.project = self.create_project(organization=self.org)
self.internal_sentry_app = self.create_internal_integration(
name="My Internal App", organization=self.org
)
self.url = reverse(
"sentry-api-0-sentry-internal-app-tokens", args=[self.internal_sentry_app.slug]
)
def test_search_query(self):
response = self.client.get(reverse('haystack_basic_search'), {'q': 'haystack'})
self.assertEqual(response.status_code, 200)
self.assertEqual(type(response.context[-1]['form']), ModelSearchForm)
self.assertEqual(len(response.context[-1]['page'].object_list), 3)
self.assertEqual(response.context[-1]['page'].object_list[0].content_type(), u'core.mockmodel')
self.assertEqual(response.context[-1]['page'].object_list[0].pk, '1')
self.assertEqual(response.context[-1]['query'], u'haystack')
'software_version': self.software_version.id}
response = self.client.post(reverse("emg_setting_edit", args=(emg_setting.id,)), self.data)
self.assertEqual(response.status_code, 302)
self.assertTrue(EMGSetting.objects.filter(name=name, description=description).exists())
name = 'EMG setting name updated'
description = 'EMG setting description updated'
self.data = {'action': 'save', 'name': name, 'description': description,
'software_version': self.software_version.id}
response = self.client.post(reverse("emg_setting_edit", args=(emg_setting.id,)), self.data)
self.assertEqual(response.status_code, 302)
self.assertTrue(EMGSetting.objects.filter(name=name, description=description).exists())
# remove an emg setting
self.data = {'action': 'remove'}
response = self.client.post(reverse("emg_setting_view", args=(emg_setting.id,)), self.data)
self.assertEqual(response.status_code, 302)
form = SubmitHousingForm(request.POST, needs_email=needs_email, needs_name=needs_name)
if form.is_valid():
submission = form.save(commit=False)
profile = get_user_profile(request)
submission.student = profile
submission.save()
if needs_email:
profile.user.email = form.cleaned_data['email']
if needs_name:
names = (form.cleaned_data['name'] + ' ').split(' ', 1)
profile.user.first_name, profile.user.last_name = names
if needs_email or needs_name:
profile.user.save()
profile.save()
form.save_m2m()
return HttpResponseRedirect(reverse(list_housing))
else:
form = SubmitHousingForm(needs_email=needs_email,needs_name=needs_name)
else:
form = SubmitHousingForm(needs_email=False,needs_name=False)
return render_to_response('listings/housing/list.html', {
'housing': housing,
'form': form,
'person': profile,
'newuser': newuser,
'GMAPS_API_KEY': settings.GMAPS_API_KEY,
}, context_instance=RequestContext(request))
def get(self, request, *args, **kwargs):
"""
GET method used to generate form, and prepare page before user fills the data in the form and POST it for
DB storage.
"""
uform = self.uform_class()
upform = self.upform_class(initial=get_initial_data(request))
return render(request, self.template_name, {
'uform': uform,
'upform': upform,
'tos_link': reverse('tos'),
'failed_registration': False,
})
def get(self, request, *args, **kwargs):
# hack to redirect to proper legislator if sponsor_id is an alias
if 'sponsor__leg_id' in request.GET:
_id = request.GET.get('sponsor__leg_id')
leg = db.legislators.find_one({'_all_ids': _id})
if leg and leg['_id'] != _id:
new_get = request.GET.copy()
new_get['sponsor__leg_id'] = leg['_id']
return HttpResponseRedirect('?'.join(
(reverse('bills', args=args, kwargs=kwargs),
new_get.urlencode())))
return super(RelatedBillsList, self).get(request, *args, **kwargs)
def shared_load_pool(request, client, form_acess=None, external=False):
try:
is_copy = request.GET.get('is_copy', 1)
pool_id = request.GET.get('pool_id')
action = reverse('external.save.pool') if external else reverse('save.pool')
load_pool_url = reverse('pool.modal.ips.ajax.external') if external else reverse('pool.modal.ips.ajax')
pool = client.create_api_pool().get_pool_details(pool_id)['server_pools'][0]
environment_id = pool['environment']['id']
group_users_list_selected = []
for group in pool["groups_permissions"]:
group_users_list_selected.append(group["user_group"]["id"])
group_users_list = client.create_grupo_usuario().listar()
forms_aux = {}
forms_aux['group_users'] = group_users_list
server_pool_members = list()
server_pool_members_raw = pool.get('server_pool_members')
if server_pool_members_raw:
for obj_member in server_pool_members_raw:
req_choices = [(u'', u'\u2014')] + [(r.id, r.description) for r in missing_req]
if request.method == 'POST':
form = CompletedRequirementForm(request.POST)
form.fields['requirement'].choices = req_choices
if form.is_valid():
req = form.save(commit=False)
req.student = grad
req.save()
messages.success(request, "Completed requirement for %s sucessfully saved." % (grad))
l = LogEntry(userid=request.user.username,
description="added completed requirement of %s for %s" % (req.requirement.description, grad.slug),
related_object=req )
l.save()
return HttpResponseRedirect(reverse('grad.views.manage_requirements', kwargs={'grad_slug':grad.slug}))
else:
form = CompletedRequirementForm(initial={'student':grad, 'semester':Semester.get_semester()})
form.fields['requirement'].choices = req_choices
context = {
'grad':grad,
'form': form,
'completed_req': completed_req,
'missing_req': missing_req,
}
return render(request, 'grad/manage_requirements.html', context)
provider_data = {
'affiliation': pending_user_params.get('affiliation', provider_module),
'info_data': provider_info
}
provider = auth_providers.get_provider(provider_module, request.user,
userid, **provider_data)
# user wants to add another third party login method
if third_party_key:
messages.error(request, provider.get_invalid_login_msg)
return HttpResponseRedirect(reverse('login') + "?key=%s" %
third_party_key)
if not provider.get_create_policy:
messages.error(request, provider.get_disabled_for_create_msg)
return HttpResponseRedirect(reverse('login'))
# TODO: this could be stored in session
# TODO: create a management command to clean old PendingThirdPartyUser
user, created = PendingThirdPartyUser.objects.get_or_create(
third_party_identifier=userid,
provider=provider_module,
)
# update pending user
for param, value in pending_user_params.iteritems():
setattr(user, param, value)
user.info = json.dumps(provider_info)
user.generate_token()
# skip non required fields validation errors. Reset the field instead of