Esempio n. 1
0
def create_user(username, first_name, last_name, password, 
			addr="", city="", state="", zipcode="", uklass=None):
	""" 
	Helper to create a user but will not work for all user types.  If this is 
	useful to add to common area we can make more generic to support all users.
	"""
	mhu = MHLUser(username=username, first_name=first_name, last_name=last_name)
	mhu.address1, mhu.city, mhu.state, mhu.zip = addr, city, state, zipcode
	mhu.is_active = mhu.is_staff = mhu.tos_accepted = mhu.mobile_confirmed = True
	mhu.set_password(password)
	if uklass != None and uklass == Administrator:
		mhu.is_superuser = True

	try:
		result = geocode2(mhu.address1, mhu.city, mhu.state, mhu.zip)
		mhu.lat, mhu.longit = result['lat'], result['lng']
	except Exception:
		# For unittests when geocode not avail for any reason set coords 0.0.  If a 
		# test depends on valid values make special case for that in those tests.
		mhu.lat, mhu.longit = 0.0, 0.0 
	mhu.save()

	if uklass != None:
		user = uklass(user=mhu)
		if hasattr(user, 'office_lat'):
			user.office_lat = 0.0
		if hasattr(user, 'office_longit'):
			user.office_longit = 0.0
		user.save()

	return user if uklass != None else mhu 
Esempio n. 2
0
	def setUpClass(cls):
		cls.request = Client()
		pl = PracticeLocation.objects.create(practice_lat=0.0, practice_longit=0.0)
		cls.provider = Provider(username="******", first_name="tester", 
								last_name="meister", office_lat=0.0, office_longit=0.0)
		cls.provider.set_password("maestro")
		cls.provider.save()
		cls.provider2 = Provider(username="******", first_name="doc", 
								last_name="holiday", office_lat=0.0, office_longit=0.0)
		cls.provider2.set_password("holiday")
		cls.provider2.save()
		cls.userm = MHLUser(username="******", first_name="important", 
							last_name="manager", is_active=True)
		cls.userm.set_password("monkey")
		cls.userm.save()

		cls.userstaff = OfficeStaff(current_practice=pl)
		cls.userstaff.user = cls.userm
		cls.userstaff.save()
		adminguy = MHLUser(username="******", first_name="super", 
							last_name="duper", is_active=True)
		adminguy.set_password("crackerjax")
		adminguy.save()
		cls.adminguy = Administrator.objects.create(user=adminguy)
		generate_keys_for_users(output=DevNull())
		# needed by our login

		VMBox_Config(owner=cls.provider).save()
		VMBox_Config(owner=cls.provider2).save()
		VMBox_Config(owner=cls.userstaff).save()
Esempio n. 3
0
    def setUpClass(cls):
        cls.request = Client()
        pl = PracticeLocation.objects.create(practice_lat=0.0,
                                             practice_longit=0.0)
        cls.provider = Provider(username="******",
                                first_name="tester",
                                last_name="meister",
                                office_lat=0.0,
                                office_longit=0.0)
        cls.provider.set_password("maestro")
        cls.provider.save()
        cls.provider2 = Provider(username="******",
                                 first_name="doc",
                                 last_name="holiday",
                                 office_lat=0.0,
                                 office_longit=0.0)
        cls.provider2.set_password("holiday")
        cls.provider2.save()
        cls.userm = MHLUser(username="******",
                            first_name="important",
                            last_name="manager",
                            is_active=True)
        cls.userm.set_password("monkey")
        cls.userm.save()

        cls.userstaff = OfficeStaff(current_practice=pl)
        cls.userstaff.user = cls.userm
        cls.userstaff.save()
        generate_keys_for_users(output=DevNull())
        # needed by our login

        VMBox_Config(owner=cls.provider).save()
        VMBox_Config(owner=cls.provider2).save()
        VMBox_Config(owner=cls.userstaff).save()
Esempio n. 4
0
	def setUp(self):
		# Create users to test against
		for i in range(10):
			mhl = MHLUser()
			mhl.lat = 0
			mhl.longit = 0
			mhl.username=str(i)
			mhl.save()
Esempio n. 5
0
	def test_update_mobile_phone(self):
		request = generateHttpRequest()
		staff = OfficeStaff(user=request.user)
		staff.save()

		#get method
		request.method = 'GET'
		result = update_mobile_phone(request)
		self.assertEqual(result.status_code, 400)
		msg = json.loads(result.content)
		self.assertEqual(msg['errno'], 'GE002')

		#post method
		request.method = 'POST'

		#invalid mobile phone number
		request.POST['mobile_phone'] = '1236'
		result = update_mobile_phone(request)
		self.assertEqual(result.status_code, 400)
		msg = json.loads(result.content)
		self.assertEqual(msg['errno'], 'GE031')

		#valid mobile phone number but someone has been used
		temp = settings.CALL_ENABLE
		settings.CALL_ENABLE = False
		mobile_phone = '8005550094'
		user = MHLUser(mobile_phone=mobile_phone, username='******', 
			first_name='sa', last_name='as', password='******')
		user.save()
		request.POST['mobile_phone'] = mobile_phone
		result = update_mobile_phone(request)
		self.assertEqual(result.status_code, 400)
		msg = json.loads(result.content)
		self.assertEqual(msg['errno'], 'AM020')

		#valid mobile phone number and nobody use it
		mobile_phone2 = '8007750094'
		request.POST['mobile_phone'] = mobile_phone2
		result = update_mobile_phone(request)
		self.assertEqual(result.status_code, 200)
		settings.CALL_ENABLE = temp
Esempio n. 6
0
def generate_users(request):
	if (not settings.DEBUG):
		return HttpResponseRedirect(reverse('MHLogin.Administration.views.home'))
	context = get_context(request)
	if (request.method == 'GET'):
		context["form"] = GenerateUsersForm()
		return render_to_response('qa_tools/genereate_users.html', context)
	else:
		form = GenerateUsersForm(request.POST)
		if form.is_valid():
			current_practice = form.cleaned_data["practices"]
			user_type = int(form.cleaned_data["user_types"])
			number = int(form.cleaned_data["number"])
			user_name_start = form.cleaned_data["user_name_start"]
			generate_user = None
			for i in range(number):
				username = "******" % (user_name_start, i)
				first_name = "%s_f_%d" % (user_name_start, i)
				last_name = "%s_f_%d" % (user_name_start, i)
				email = "*****@*****.**" % (username)
				password = "******"
				if USER_TYPE_DOCTOR == user_type \
					or USER_TYPE_NPPA == user_type \
					or USER_TYPE_MEDICAL_STUDENT == user_type:
					provider = Provider(
						username=username,
						first_name=first_name,
						last_name=last_name,
						email=email,
						email_confirmed=True,
						lat=current_practice.practice_lat,
						longit=current_practice.practice_longit,

						address1=current_practice.practice_address1,
						address2=current_practice.practice_address2,
						city=current_practice.practice_city,
						state=current_practice.practice_state,
						zip=current_practice.practice_zip,

						current_practice=current_practice,
						is_active=1,
						office_lat=current_practice.practice_lat,
						office_longit=current_practice.practice_longit,

						mdcom_phone="8004664411"
					)
					provider.save()
					provider.set_password(password)

					provider.practices.add(current_practice)
					provider.user_id = provider.pk
					provider.save()

					if USER_TYPE_DOCTOR == user_type:
						#Physician
						ph = Physician(user=provider)
						ph.save()
					elif USER_TYPE_NPPA == user_type:
						#NP/PA/Midwife
						np = NP_PA(user=provider)
						np.save()
					elif USER_TYPE_MEDICAL_STUDENT == user_type:
						ph = Physician(user=provider)
						ph.save()

					create_default_keys(provider.user, password)
					# Generating the user's voicemail box configuration
					config = VMBox_Config(pin='')
					config.owner = provider
					config.save()
					generate_user = provider
				elif USER_TYPE_OFFICE_MANAGER == user_type \
					or USER_TYPE_NURSE == user_type \
					or USER_TYPE_DIETICIAN == user_type:
					mhluser = MHLUser(
						username = username,
						first_name = first_name,
						last_name = last_name,
						email = email,
						email_confirmed = True,

						is_active = 1,
						address1 = current_practice.practice_address1,
						address2 = current_practice.practice_address2,
						city = current_practice.practice_city,
						state = current_practice.practice_state,
						zip = current_practice.practice_zip,
						lat = current_practice.practice_lat,
						longit = current_practice.practice_longit
					)
					mhluser.save()
					mhluser.set_password(password)

					staff = OfficeStaff(
								user=mhluser,
								current_practice=current_practice
							)
					staff.user = mhluser
					staff.current_practice = current_practice
					staff.save()

					staff.practices.add(current_practice)
					staff.save()

					if USER_TYPE_OFFICE_MANAGER == user_type:
						manager = Office_Manager(user=staff, practice=current_practice)
						manager.save()
					if USER_TYPE_NURSE == user_type:
						nurse = Nurse(user=staff)
						nurse.save()
					elif USER_TYPE_DIETICIAN == user_type:
						dietician = Dietician(user=staff)
						dietician.save()
					generate_user = mhluser
				log_str = 'Generate user %d: for %s' % (i, str(generate_user))
				logger.debug(log_str)
				print log_str

			return render_to_response('qa_tools/genereate_users_success.html', context)
		else:
			context["form"] = form
			return render_to_response('qa_tools/genereate_users.html', context)
Esempio n. 7
0
def generate_users(request):
    if (not settings.DEBUG):
        return HttpResponseRedirect(
            reverse('MHLogin.Administration.views.home'))
    context = get_context(request)
    if (request.method == 'GET'):
        context["form"] = GenerateUsersForm()
        return render_to_response('qa_tools/genereate_users.html', context)
    else:
        form = GenerateUsersForm(request.POST)
        if form.is_valid():
            current_practice = form.cleaned_data["practices"]
            user_type = int(form.cleaned_data["user_types"])
            number = int(form.cleaned_data["number"])
            user_name_start = form.cleaned_data["user_name_start"]
            generate_user = None
            for i in range(number):
                username = "******" % (user_name_start, i)
                first_name = "%s_f_%d" % (user_name_start, i)
                last_name = "%s_f_%d" % (user_name_start, i)
                email = "*****@*****.**" % (username)
                password = "******"
                if USER_TYPE_DOCTOR == user_type \
                 or USER_TYPE_NPPA == user_type \
                 or USER_TYPE_MEDICAL_STUDENT == user_type:
                    provider = Provider(
                        username=username,
                        first_name=first_name,
                        last_name=last_name,
                        email=email,
                        email_confirmed=True,
                        lat=current_practice.practice_lat,
                        longit=current_practice.practice_longit,
                        address1=current_practice.practice_address1,
                        address2=current_practice.practice_address2,
                        city=current_practice.practice_city,
                        state=current_practice.practice_state,
                        zip=current_practice.practice_zip,
                        current_practice=current_practice,
                        is_active=1,
                        office_lat=current_practice.practice_lat,
                        office_longit=current_practice.practice_longit,
                        mdcom_phone="8004664411")
                    provider.save()
                    provider.set_password(password)

                    provider.practices.add(current_practice)
                    provider.user_id = provider.pk
                    provider.save()

                    if USER_TYPE_DOCTOR == user_type:
                        #Physician
                        ph = Physician(user=provider)
                        ph.save()
                    elif USER_TYPE_NPPA == user_type:
                        #NP/PA/Midwife
                        np = NP_PA(user=provider)
                        np.save()
                    elif USER_TYPE_MEDICAL_STUDENT == user_type:
                        ph = Physician(user=provider)
                        ph.save()

                    create_default_keys(provider.user, password)
                    # Generating the user's voicemail box configuration
                    config = VMBox_Config(pin='')
                    config.owner = provider
                    config.save()
                    generate_user = provider
                elif USER_TYPE_OFFICE_MANAGER == user_type \
                 or USER_TYPE_NURSE == user_type \
                 or USER_TYPE_DIETICIAN == user_type:
                    mhluser = MHLUser(
                        username=username,
                        first_name=first_name,
                        last_name=last_name,
                        email=email,
                        email_confirmed=True,
                        is_active=1,
                        address1=current_practice.practice_address1,
                        address2=current_practice.practice_address2,
                        city=current_practice.practice_city,
                        state=current_practice.practice_state,
                        zip=current_practice.practice_zip,
                        lat=current_practice.practice_lat,
                        longit=current_practice.practice_longit)
                    mhluser.save()
                    mhluser.set_password(password)

                    staff = OfficeStaff(user=mhluser,
                                        current_practice=current_practice)
                    staff.user = mhluser
                    staff.current_practice = current_practice
                    staff.save()

                    staff.practices.add(current_practice)
                    staff.save()

                    if USER_TYPE_OFFICE_MANAGER == user_type:
                        manager = Office_Manager(user=staff,
                                                 practice=current_practice)
                        manager.save()
                    if USER_TYPE_NURSE == user_type:
                        nurse = Nurse(user=staff)
                        nurse.save()
                    elif USER_TYPE_DIETICIAN == user_type:
                        dietician = Dietician(user=staff)
                        dietician.save()
                    generate_user = mhluser
                log_str = 'Generate user %d: for %s' % (i, str(generate_user))
                logger.debug(log_str)
                print log_str

            return render_to_response('qa_tools/genereate_users_success.html',
                                      context)
        else:
            context["form"] = form
            return render_to_response('qa_tools/genereate_users.html', context)
Esempio n. 8
0
    def setUpClass(cls):
        PracticeLocation.objects.all().delete()

        # practice group
        cls.practice_group_new = PracticeLocation(practice_name="test Group",
                                                  practice_lat=1000,
                                                  practice_longit=1000)
        cls.practice_group_new.save()

        # practice location
        cls.practice_location = PracticeLocation(practice_name="test1",
                                                 practice_lat=1000,
                                                 practice_longit=1000)
        cls.practice_location.save()

        OrganizationRelationship.objects.create(
            organization=cls.practice_location,
            parent=cls.practice_group_new,
            create_time=int(time.time()))

        # location without group
        cls.old_style_practice_location = PracticeLocation(
            practice_name="test2", practice_lat=1001, practice_longit=1000)
        cls.old_style_practice_location.save()
        # user
        user = MHLUser(username="******",
                       first_name="bill",
                       last_name="test")
        user.is_active = user.is_staff = user.tos_accepted = True
        user.set_password("demo")
        user.save()
        # user 2
        cls.user_alt = MHLUser(username="******",
                               first_name="will",
                               last_name="test")
        cls.user_alt.is_active = cls.user_alt.is_staff = cls.user_alt.tos_accepted = True
        cls.user_alt.set_password("demo")
        cls.user_alt.save()
        # make him office staff first
        cls.officestaff = OfficeStaff(user=user,
                                      current_practice=cls.practice_location)
        cls.officestaff.save()
        cls.officestaff.practices.add(cls.practice_location)
        # make him office manager
        cls.office_manager = Office_Manager(user=cls.officestaff,
                                            practice=cls.practice_location,
                                            manager_role=2)
        cls.office_manager.save()
        # products
        p1 = Products(description="Answering Service Active",
                      code="ANS",
                      price="75")
        p1.save()
        p2 = Products(description="File Sharing Prorated",
                      code="FSP",
                      price="100")
        p2.save()
        p3 = Products(description="Old Product Inactive",
                      code="OP",
                      price="14.95")
        p3.save()
        p4 = Products(description="Future Product See Date",
                      code="FP",
                      price="25.95")
        p4.save()
        p5 = Products(description="Future Product NOT subscribed",
                      code="FPNS",
                      price="1.00")
        p5.save()
        # subscription - at this point manual, we will create add product function later on
        now = datetime.datetime(2011, 12, 1, 9, 30, 45)
        Subscription(practice_group_new=cls.practice_group_new,
                     product=p1,
                     practice_location=cls.practice_location,
                     is_active=True,
                     price="75",
                     start_date=now).save()
        Subscription(practice_group_new=cls.practice_group_new,
                     product=p3,
                     is_active=False,
                     price="14.95",
                     start_date=now).save()
        now = datetime.datetime(2012, 5, 29, 10, 00, 00)
        Subscription(practice_group_new=cls.practice_group_new,
                     product=p2,
                     is_active=True,
                     price="38.75",
                     start_date=now).save()
        now = datetime.datetime(2012, 7, 1, 10, 00, 00)
        s = Subscription(practice_group_new=cls.practice_group_new,
                         product=p4,
                         is_active=True,
                         price="29.95",
                         start_date=now)
        s.save()
        s.__unicode__()
Esempio n. 9
0
	def setUpClass(cls):
		PracticeLocation.objects.all().delete()

		# practice group
		cls.practice_group_new = PracticeLocation(practice_name="test Group", 
			practice_lat=1000, practice_longit=1000)
		cls.practice_group_new.save()

		# practice location
		cls.practice_location = PracticeLocation(practice_name="test1", 
			practice_lat=1000, practice_longit=1000)
		cls.practice_location.save()

		OrganizationRelationship.objects.create(organization=cls.practice_location, 
			parent=cls.practice_group_new, create_time=int(time.time()))

		# location without group
		cls.old_style_practice_location = PracticeLocation(practice_name="test2", 
			practice_lat=1001, practice_longit=1000)
		cls.old_style_practice_location.save()
		# user
		user = MHLUser(username="******", first_name="bill", last_name="test")
		user.is_active = user.is_staff = user.tos_accepted = True
		user.set_password("demo")
		user.save()
		# user 2
		cls.user_alt = MHLUser(username="******", first_name="will", last_name="test")
		cls.user_alt.is_active = cls.user_alt.is_staff = cls.user_alt.tos_accepted = True
		cls.user_alt.set_password("demo")
		cls.user_alt.save()
		# make him office staff first
		cls.officestaff = OfficeStaff(user=user, current_practice=cls.practice_location)
		cls.officestaff.save()
		cls.officestaff.practices.add(cls.practice_location)
		# make him office manager
		cls.office_manager = Office_Manager(user=cls.officestaff, 
			practice=cls.practice_location, manager_role=2)
		cls.office_manager.save()
		# products
		p1 = Products(description="Answering Service Active", code="ANS", price="75")
		p1.save()
		p2 = Products(description="File Sharing Prorated", code="FSP", price="100")
		p2.save()
		p3 = Products(description="Old Product Inactive", code="OP", price="14.95")
		p3.save()
		p4 = Products(description="Future Product See Date", code="FP", price="25.95")
		p4.save()
		p5 = Products(description="Future Product NOT subscribed", code="FPNS", price="1.00")
		p5.save()
		# subscription - at this point manual, we will create add product function later on
		now = datetime.datetime(2011, 12, 1, 9, 30, 45)
		Subscription(practice_group_new=cls.practice_group_new, product=p1, 
			practice_location=cls.practice_location, is_active=True, price="75", start_date=now).save()
		Subscription(practice_group_new=cls.practice_group_new, 
			product=p3, is_active=False, price="14.95", start_date=now).save()
		now = datetime.datetime(2012, 5, 29, 10, 00, 00)
		Subscription(practice_group_new=cls.practice_group_new, product=p2, 
			is_active=True, price="38.75", start_date=now).save()
		now = datetime.datetime(2012, 7, 1, 10, 00, 00)
		s = Subscription(practice_group_new=cls.practice_group_new, product=p4, 
			is_active=True, price="29.95", start_date=now)
		s.save()
		s.__unicode__()