def post(self, request): if 'save_settings' not in request.POST: return HttpResponseBadRequest() errors = {} data = {'company_auto_index' : SettingsManager.get_property('company_auto_index'), 'bill_auto_index' : SettingsManager.get_property('bill_auto_index'), 'verify_bill_price' : SettingsManager.get_property('verify_bill_price'), 'registration_promo_action_amount' : SettingsManager.get_property('registration_promo_action_amount'), 'rnes' : SettingsManager.get_property('rnes'), 'rmax' : SettingsManager.get_property('rmax'), 'rtimeout' : SettingsManager.get_property('rtimeout'), 'verifylettercount' : SettingsManager.get_property('verifylettercount'), 'verifyletterdelaydays' : SettingsManager.get_property('verifyletterdelaydays'), 'invite_bonus' : SettingsManager.get_property('invite_bonus'), 'errors' : errors} verify_bill_price = request.POST.get('verify_bill_price').strip() registration_promo_action_amount = request.POST.get('registration_promo_action_amount').strip() if len(verify_bill_price): try: verify_bill_price_int = int(verify_bill_price) if verify_bill_price_int <= 0 or verify_bill_price_int > 1000000: raise Exception() if verify_bill_price_int != data['verify_bill_price']: SettingsManager.set_property('verify_bill_price', verify_bill_price_int) data['verify_bill_price'] = verify_bill_price_int except ValueError: errors['verify_bill_price'] = "Введите корректную сумму" if len(registration_promo_action_amount): try: registration_promo_action_amount_int = int(registration_promo_action_amount) if registration_promo_action_amount_int <= 0 or registration_promo_action_amount_int > 1000000: raise Exception() if registration_promo_action_amount_int != data['registration_promo_action_amount']: SettingsManager.set_property('registration_promo_action_amount', registration_promo_action_amount_int) data['registration_promo_action_amount'] = registration_promo_action_amount_int except ValueError: errors['registration_promo_action_amount'] = "Введите корректную сумму" rnes = request.POST.get('rnes', '').strip() rmax = request.POST.get('rmax', '').strip() rtimeout = request.POST.get('rtimeout', '').strip() verifylettercount = request.POST.get('verifylettercount', '').strip() verifyletterdelaydays = request.POST.get('verifyletterdelaydays', '').strip() invite_bonus = request.POST.get('invite_bonus', '').strip() self.update_int_setting('rnes', rnes, 1, 100, errors, data) self.update_int_setting('rmax', rmax, 1, 100, errors, data) self.update_int_setting('rtimeout', rtimeout, 1, 24 * 365, errors, data) self.update_int_setting('verifylettercount', verifylettercount, 0, 100, errors, data) self.update_int_setting('verifyletterdelaydays', verifyletterdelaydays, 1, 366, errors, data) self.update_int_setting('invite_bonus', invite_bonus, 0, 3000, errors, data) if not len(errors): return HttpResponseRedirect(request.path) return render_to_response('settings/manage_settings.html', data, context_instance=RequestContext(request))
def test_remove_old_recommendations_timeout(self): SettingsManager.set_property('rtimeout', 24 * 10) r = RecommendationRequest({'requester' : ObjectId(), 'recipient' : ObjectId(), 'message' : 'message', 'requester_email' : '*****@*****.**', 'status' : RecommendationStatusEnum.DECLINED, 'send_date' : timezone.now() - timedelta(days = 1)}) r.save() rr = RecommendationRequest.objects.get_one({'_id' : r._id}) self.assertIsNotNone(rr) self.assertEqual(rr.status, RecommendationStatusEnum.DECLINED) task = RemoveOldRecRequestsTask() task.execute() rr = RecommendationRequest.objects.get_one({'_id' : r._id}) self.assertIsNotNone(rr) SettingsManager.set_property('rtimeout', 1) task.execute() rr = RecommendationRequest.objects.get_one({'_id' : r._id}) self.assertIsNone(rr)
def testAcceptRec(self): SettingsManager.set_property('rnes', 3) self.register() requester_company, requester_employee, requester_user, request = self.register_verification_requesters(self.company, 3)[0] self.login() mail.outbox = [] self.assertEqual(RecommendationRequest.objects.count(), 3) response = self.client.post('/recommendations/accept/%s/' % str(request._id)) self.assertEqual(response.status_code, 200) data = simplejson.loads(response.content) self.assertTrue(isinstance(data, dict)) self.assertIn('error', data) self.assertFalse(data['error']) self.assertEqual(len(mail.outbox), 0) request_post = RecommendationRequest.objects.get_one({'_id' : request._id}) self.assertIsNotNone(request_post) self.assertEqual(request_post.status, RecommendationStatusEnum.ACCEPTED) self.assertEqual(request_post.requester, requester_company._id) self.assertEqual(request_post.recipient, self.company._id) self.assertEqual(request_post.viewed, False) self.assertEqual(request_post.requester_email, requester_user.email) self.assertEqual(RecommendationRequest.objects.count(), 3)
def test_twice_register_after_invite(self): SettingsManager.set_property('rnes', 3) self.register() self.login() data = {'msg' : 'Come on! Join us now!', 'email' : '*****@*****.**'} notifications = Notification.objects.get({}) self.assertEqual(len(notifications), 0) response = self.client.post('/invites/send/', data) self.assertEquals(response.status_code, 200) invites = Invite.objects.get({}) self.assertEqual(len(invites), 1) invite = invites[0] self.assertEqual(invite.message, 'Come on! Join us now!') self.assertEqual(invite.email, '*****@*****.**') data = simplejson.loads(response.content) self.assertTrue(isinstance(data, dict)) self.assertIn('success', data) self.assertTrue(data['success']) self.logout() response = self.client.get(u'/invites/join/%s/' % invite.cookie_code) self.assertEquals(response.status_code, 302) self.assertTrue(self.client.cookies.has_key('invite')) self.assertEqual(Company.objects.count(), 1) self.assertEqual(RecommendationRequest.objects.count(), 0) self.register(email="*****@*****.**", verified=False) self.login() self.assertEqual(Company.objects.count(), 2) invite = Invite.objects.get_one({}) self.assertEqual(RecommendationRequest.objects.count(), 1) self.assertEqual(invite.rec_request, RecommendationRequest.objects.get_one({})._id) user = User(User.collection.find_one({'email' : "*****@*****.**"})) company = get_user_company(user) self.assertEqual(company.account_status, CompanyAccountStatus.JUST_REGISTERED) self.logout() self.client = Client() response = self.client.get(u'/invites/join/%s/' % invite.cookie_code) self.assertEquals(response.status_code, 302) self.assertFalse(self.client.cookies.has_key('invite')) self.assertEqual(Company.objects.count(), 2) self.assertEqual(RecommendationRequest.objects.count(), 1) self.register(email="*****@*****.**", verified=False) self.login() self.assertEqual(Company.objects.count(), 3) self.assertEqual(RecommendationRequest.objects.count(), 1) trans = Transaction.objects.get_one({}) self.assertIsNone(trans)
def test_register_after_invite_and_verify(self): account = Account({"system_id" : Account.FIXED_PROMO_ACCOUNT_ID, "name" : "Счет промо-акцийг", "type" : Account.TYPE_VIRTUAL}) account.save() SettingsManager.set_property('rnes', 1) self.register() self.login() data = {'msg' : 'Come on! Join us now!', 'email' : '*****@*****.**'} notifications = Notification.objects.get({}) self.assertEqual(len(notifications), 0) response = self.client.post('/invites/send/', data) self.assertEquals(response.status_code, 200) invites = Invite.objects.get({}) self.assertEqual(len(invites), 1) invite = invites[0] self.assertEqual(invite.message, 'Come on! Join us now!') self.assertEqual(invite.email, '*****@*****.**') data = simplejson.loads(response.content) self.assertTrue(isinstance(data, dict)) self.assertIn('success', data) self.assertTrue(data['success']) self.logout() response = self.client.get(u'/invites/join/%s/' % invite.cookie_code) self.assertEquals(response.status_code, 302) self.assertTrue(self.client.cookies.has_key('invite')) self.assertEqual(Company.objects.count(), 1) self.assertEqual(RecommendationRequest.objects.count(), 0) self.register(email="*****@*****.**", verified=False) self.login() self.assertEqual(Company.objects.count(), 2) invite = Invite.objects.get_one({}) self.assertEqual(RecommendationRequest.objects.count(), 1) self.assertEqual(invite.rec_request, RecommendationRequest.objects.get_one({})._id) user = User(User.collection.find_one({'email' : "*****@*****.**"})) company = get_user_company(user) self.assertEqual(company.account_status, CompanyAccountStatus.VERIFIED) trans = Transaction.objects.get_one({}) self.assertIsNotNone(trans) self.assertEqual(trans.state, Transaction.STATE_DONE) self.assertEqual(trans.amount.amount, SettingsManager.get_property('invite_bonus')) self.assertEqual(trans.source_account, account._id) dest_account = Account.objects.get_one({'type' : Account.TYPE_COMPANY, 'details.subject_id' : invite.sender}) self.assertEqual(trans.dest_account, dest_account._id)
def update_int_setting(self, setting_name, string_val, min_value, max_value, errors_dict, data_dict, error_msg = None): try: val_i = int(string_val) if val_i < min_value or val_i > max_value: raise Exception() if val_i != SettingsManager.get_property(setting_name): SettingsManager.set_property(setting_name, val_i) data_dict[setting_name] = val_i except Exception: errors_dict[setting_name] = "Введите целочисленное значение [%d - %d]" % (min_value, max_value) if not error_msg else error_msg
def testAcceptRecAndVerify(self): SettingsManager.set_property('rnes', 3) self.register() requesters = self.register_verification_requesters(self.company, 1) requester_company, requester_employee, requester_user, request = requesters[0] self.login() mail.outbox = [] response = self.client.post('/recommendations/accept/%s/' % str(request._id)) self.assertEqual(response.status_code, 200) self.assertEqual(len(mail.outbox), 0) company_data = Company.objects.collection.find_one({'_id' : requester_company._id}, {'account_status' : 1}) self.assertEqual(company_data['account_status'], CompanyAccountStatus.JUST_REGISTERED) self.logout() self.register(email='*****@*****.**') request = RecommendationRequest({'requester' : requester_company._id, 'recipient' : self.company._id, 'status' : RecommendationStatusEnum.RECEIVED, 'message' : 'Please recommend me.', 'requester_email' : '*****@*****.**'}) request.save() self.login_as(email='*****@*****.**') mail.outbox = [] response = self.client.post('/recommendations/accept/%s/' % str(request._id)) self.assertEqual(response.status_code, 200) self.assertEqual(len(mail.outbox), 0) company_data = Company.objects.collection.find_one({'_id' : requester_company._id}, {'account_status' : 1}) self.assertEqual(company_data['account_status'], CompanyAccountStatus.JUST_REGISTERED) self.logout() self.register(email='*****@*****.**') request = RecommendationRequest({'requester' : requester_company._id, 'recipient' : self.company._id, 'status' : RecommendationStatusEnum.RECEIVED, 'message' : 'Please recommend me.', 'requester_email' : '*****@*****.**'}) request.save() self.login_as(email='*****@*****.**') mail.outbox = [] response = self.client.post('/recommendations/accept/%s/' % str(request._id)) self.assertEqual(response.status_code, 200) self.assertEqual(len(mail.outbox), 1) company_data = Company.objects.collection.find_one({'_id' : requester_company._id}, {'account_status' : 1}) self.assertEqual(company_data['account_status'], CompanyAccountStatus.VERIFIED)
def testInitialModuleDataAccept(self): SettingsManager.set_property('rnes', 3) self.register() requesters = self.register_verification_requesters(self.company, 3) requester_company, requester_employee, requester_user, request = requesters[0] self.login() mail.outbox = [] self.assertEqual(RecommendationRequest.objects.count(), 3) response = self.client.post('/recommendations/accept/%s/' % str(request._id)) self.assertEqual(response.status_code, 200) data = simplejson.loads(response.content) self.assertTrue(isinstance(data, dict)) self.assertIn('error', data) self.assertFalse(data['error']) self.assertEqual(len(mail.outbox), 0) request_post = RecommendationRequest.objects.get_one({'_id' : request._id}) self.assertIsNotNone(request_post) self.assertEqual(request_post.status, RecommendationStatusEnum.ACCEPTED) self.assertEqual(request_post.requester, requester_company._id) self.assertEqual(request_post.recipient, self.company._id) self.assertEqual(request_post.viewed, False) self.assertEqual(request_post.requester_email, requester_user.email) self.assertEqual(RecommendationRequest.objects.count(), 3) data = RecommendInitialsView.generate_data_obj(self.company, self.company, self.employee) self.assertIsNotNone(data) self.assertIn('sent_not_accepted_list', data) self.assertIn('sent_accepted_list', data) self.assertIn('received_accepted', data) self.assertIn('received_not_accepted', data) self.assertIn('max_req_count_reached', data) sent_not_accepted_list = data['sent_not_accepted_list'] sent_accepted_list = data['sent_accepted_list'] received_accepted = data['received_accepted'] received_not_accepted = data['received_not_accepted'] max_req_count_reached = data['max_req_count_reached'] self.assertEqual(max_req_count_reached, False) self.assertEqual(len(sent_not_accepted_list), 0) self.assertEqual(len(sent_accepted_list), 0) self.assertEqual(len(received_accepted), 1) self.assertEqual(len(received_not_accepted), 2)
def test_register_after_invite(self): SettingsManager.set_property('rnes', 3) self.register() self.login() data = {'msg': 'Come on! Join us now!', 'email': '*****@*****.**'} notifications = Notification.objects.get({}) self.assertEqual(len(notifications), 0) response = self.client.post('/invites/send/', data) self.assertEquals(response.status_code, 200) invites = Invite.objects.get({}) self.assertEqual(len(invites), 1) invite = invites[0] self.assertEqual(invite.message, 'Come on! Join us now!') self.assertEqual(invite.email, '*****@*****.**') data = simplejson.loads(response.content) self.assertTrue(isinstance(data, dict)) self.assertIn('success', data) self.assertTrue(data['success']) self.logout() response = self.client.get(u'/invites/join/%s/' % invite.cookie_code) self.assertEquals(response.status_code, 302) self.assertTrue(self.client.cookies.has_key('invite')) self.assertEqual(Company.objects.count(), 1) self.assertEqual(RecommendationRequest.objects.count(), 0) self.register(email="*****@*****.**", verified=False) self.login() self.assertEqual(Company.objects.count(), 2) invite = Invite.objects.get_one({}) self.assertEqual(RecommendationRequest.objects.count(), 1) self.assertEqual(invite.rec_request, RecommendationRequest.objects.get_one({})._id) user = User( User.collection.find_one({'email': "*****@*****.**"})) company = get_user_company(user) self.assertEqual(company.account_status, CompanyAccountStatus.JUST_REGISTERED)
def testInitialModuleDataRequest(self): SettingsManager.set_property('rnes', 3) SettingsManager.set_property('rmax', 3) self.register(verified=False) self.login() mail.outbox = [] companies = self.register_companies(3) response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : companies[0].rek_id}, {'message' : "!"}) self.assertEqual(response.status_code, 200) self.assertEqual(RecommendationRequest.objects.count(), 1) response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : companies[1].rek_id}, {'message' : "!"}) self.assertEqual(response.status_code, 200) self.assertEqual(RecommendationRequest.objects.count(), 2) response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : companies[2].rek_id}, {'message' : "!"}) self.assertEqual(response.status_code, 200) self.assertEqual(RecommendationRequest.objects.count(), 3) RecommendationRequest.objects.update({'_id' : RecommendationRequest.objects.get_one({})._id}, {'$set' : {'status' : RecommendationStatusEnum.ACCEPTED}}) data = RecommendInitialsView.generate_data_obj(self.company, self.company, self.employee) self.assertIsNotNone(data) self.assertIn('sent_not_accepted_list', data) self.assertIn('sent_accepted_list', data) self.assertIn('received_accepted', data) self.assertIn('received_not_accepted', data) self.assertIn('max_req_count_reached', data) sent_not_accepted_list = data['sent_not_accepted_list'] sent_accepted_list = data['sent_accepted_list'] received_accepted = data['received_accepted'] received_not_accepted = data['received_not_accepted'] max_req_count_reached = data['max_req_count_reached'] self.assertEqual(max_req_count_reached, True) self.assertEqual(len(sent_not_accepted_list), 2) self.assertEqual(len(sent_accepted_list), 1) self.assertEqual(len(received_accepted), 0) self.assertEqual(len(received_not_accepted), 0)
def test_remove_old_recommendations_not_old(self): SettingsManager.set_property('rtimeout', 1) r = RecommendationRequest({'requester' : ObjectId(), 'recipient' : ObjectId(), 'message' : 'message', 'requester_email' : '*****@*****.**'}) r.save() rr = RecommendationRequest.objects.get_one({'_id' : r._id}) self.assertIsNotNone(rr) self.assertEqual(rr.status, RecommendationStatusEnum.RECEIVED) task = RemoveOldRecRequestsTask() task.execute() rr = RecommendationRequest.objects.get_one({'_id' : r._id}) self.assertIsNotNone(rr) self.assertEqual(rr.status, RecommendationStatusEnum.RECEIVED)
def testRequestMaxNumOfRecs(self): SettingsManager.set_property('rnes', 3) SettingsManager.set_property('rmax', 3) message = "Could you please recommend me." self.register(verified=False) self.login() companies = self.register_companies(6) for x in xrange(3): company = companies[x] response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : company.rek_id}, {'message' : message}) self.assertEqual(response.status_code, 200) self.assertEqual(RecommendationRequest.objects.count(), x + 1) company = companies[-1] response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : company.rek_id}, {'message' : message}) self.assertEqual(response.status_code, 403) self.assertEqual(RecommendationRequest.objects.count(), 3)
def test_register_after_invite_and_verify(self): account = Account({ "system_id": Account.FIXED_PROMO_ACCOUNT_ID, "name": "Счет промо-акцийг", "type": Account.TYPE_VIRTUAL }) account.save() SettingsManager.set_property('rnes', 1) self.register() self.login() data = {'msg': 'Come on! Join us now!', 'email': '*****@*****.**'} notifications = Notification.objects.get({}) self.assertEqual(len(notifications), 0) response = self.client.post('/invites/send/', data) self.assertEquals(response.status_code, 200) invites = Invite.objects.get({}) self.assertEqual(len(invites), 1) invite = invites[0] self.assertEqual(invite.message, 'Come on! Join us now!') self.assertEqual(invite.email, '*****@*****.**') data = simplejson.loads(response.content) self.assertTrue(isinstance(data, dict)) self.assertIn('success', data) self.assertTrue(data['success']) self.logout() response = self.client.get(u'/invites/join/%s/' % invite.cookie_code) self.assertEquals(response.status_code, 302) self.assertTrue(self.client.cookies.has_key('invite')) self.assertEqual(Company.objects.count(), 1) self.assertEqual(RecommendationRequest.objects.count(), 0) self.register(email="*****@*****.**", verified=False) self.login() self.assertEqual(Company.objects.count(), 2) invite = Invite.objects.get_one({}) self.assertEqual(RecommendationRequest.objects.count(), 1) self.assertEqual(invite.rec_request, RecommendationRequest.objects.get_one({})._id) user = User( User.collection.find_one({'email': "*****@*****.**"})) company = get_user_company(user) self.assertEqual(company.account_status, CompanyAccountStatus.VERIFIED) trans = Transaction.objects.get_one({}) self.assertIsNotNone(trans) self.assertEqual(trans.state, Transaction.STATE_DONE) self.assertEqual(trans.amount.amount, SettingsManager.get_property('invite_bonus')) self.assertEqual(trans.source_account, account._id) dest_account = Account.objects.get_one({ 'type': Account.TYPE_COMPANY, 'details.subject_id': invite.sender }) self.assertEqual(trans.dest_account, dest_account._id)
def setUp(self): super(InvitesTestCase, self).setUp() SettingsManager.set_property('verifylettercount', 0)
def setUp(self): super(InvitesRecsTestCase, self).setUp() SettingsManager.set_property('verifylettercount', 0)