Example #1
0
	def setUp(self):
		clean_db_datas()

		org_setting = OrganizationSetting()
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type", organization_setting=org_setting, is_public=True)
		org_type.save()
		self.org = PracticeLocation(
			practice_name="Test1",
			practice_address1='555 Pleasant Pioneer Grove',
			practice_address2='Trailer Q615',
			practice_city='Mountain View',
			practice_state='CA',
			practice_zip='94040-4104',
			practice_lat=37.36876,
			practice_longit= -122.081864)
		self.org.organization_type = org_type
		self.org.save()

		for i in range(10):
			user_name = "".join(["Staff1_", str(i)])
			first_name = "".join(["Test1_", str(i)])
			user = create_user(user_name, first_name, 'S', 'demo', uklass=OfficeStaff)
			self.org_staff.append(user)

			# IntegrityError: column username is not unique
#			provider_name = "".join(["Pravider1_", str(i)])
#			pro = create_user(provider_name, 'Provider', 'P', 'demo', uklass=Provider)
#			self.org_providers.append(pro)

		self.staff = create_user("Staff2", 'Test2', 'S', 'demo', uklass=OfficeStaff)
		self.staff.save()
		self.provider = create_user("Pravider2", 'Provider', 'P', 'demo', uklass=Provider)
		self.provider.save()
Example #2
0
def create_organization(auto_type=True, org_type=None, org_type_id=None, org_name="Test Org"):
	if not org_type:
		if auto_type:
			org_setting = OrganizationSetting(can_have_luxury_logo=True,
											display_in_contact_list_tab=True)
			org_setting.save()
			type_name = "Test Org Type1"
			if org_type_id:
				org_type = OrganizationType(id=org_type_id, 
					name=type_name, organization_setting=org_setting)
				org_type.save()
			else:
				org_type = OrganizationType(name=type_name, organization_setting=org_setting)
				# force id for test - MySQL UT's don't re-use ids after cleanup 
				org_type.id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE
				# TODO: issue 2030, reserved id's is a hazardous approach, the UT's 
				# were working with SQLlite but not with MySQL, DB engines recycle
				# id's differently and we should not rely on reserved id fields.  This 
				# should be addressed in a separate Redmine as model changes may occur.
				org_type.save()

	_organization = PracticeLocation(
		practice_name="Test Org",
		practice_address1='555 Pleasant Pioneer Grove',
		practice_address2='Trailer Q615',
		practice_city='Mountain View',
		practice_state='CA',
		practice_zip='94040-4104',
		practice_lat=37.36876,
		practice_longit=-122.081864,
		organization_type=org_type)
	_organization.save()
	return _organization
Example #3
0
	def setUp(self):
		clean_db_datas()

		org_setting = OrganizationSetting()
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type", organization_setting=org_setting, is_public=True)
		org_type.save()
		self.org = create_organization()

		user1 = create_user(get_random_username(), 'Test1', 'S', 'demo')
		staff1 = OfficeStaff()
		staff1.user = user1
		staff1.office_lat = 0.0
		staff1.office_longit = 0.0
		staff1.current_practice = self.org
		staff1.save()
		staff1.practices.add(self.org)
		self.manager = Office_Manager(user=staff1, practice=self.org, manager_role=1)

		user = create_user(get_random_username(), 'Test1', 'S', 'demo')
		staff = OfficeStaff()
		staff.user = user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.save()
		self.staff = staff
		
		self.provider = create_user("Pravider2", 'Provider', 'P', 'demo', uklass=Provider)
		self.provider.save()
Example #4
0
class CanWeCreateThisTypeUnderThatTypeTest(TestCase):
	org_type = None
	sub_type = None

	def setUp(self):
		clean_db_datas()
		org_setting = OrganizationSetting()
		org_setting.save()
		self.org_type = OrganizationType(name="Test Org Type1", 
			organization_setting=org_setting, is_public=True)
		self.org_type.save()
		self.sub_type = OrganizationType(name="Test Org Type2", 
			organization_setting=org_setting, is_public=True)
		self.sub_type.save()

	def test_can_we_create_this_type_under_that_type_cant(self):
		self.assertFalse(can_we_create_this_type_under_that_type(-1, None))
		self.assertFalse(can_we_create_this_type_under_that_type(self.sub_type.id, self.org_type.id))

	def test_can_we_create_this_type_under_that_type_can(self):
		OrganizationTypeSubs.objects.create(from_organizationtype=self.org_type, 
			to_organizationtype=self.sub_type)
		self.assertTrue(can_we_create_this_type_under_that_type(self.sub_type.id, self.org_type.id))

	def tearDown(self):
		pass
Example #5
0
	def setUp(self):
		clean_db_datas()

		org_setting = OrganizationSetting()
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type", organization_setting=org_setting, is_public=True)
		org_type.save()
		self.org = create_organization()

		for i in range(10):
			user_name = "".join(["Staff1_", str(i)])
			first_name = "".join(["Test1_", str(i)])
			user = create_user(user_name, first_name, 'S', 'demo')
			self.staff = OfficeStaff()
			self.staff.user = user
			self.staff.office_lat = 0.0
			self.staff.office_longit = 0.0
			self.staff.save()
			self.org_staff.append(self.staff)

			# IntegrityError: column username is not unique
#			provider_name = "".join(["Pravider1_", str(i)])
#			pro = create_user(provider_name, 'Provider', 'P', 'demo', uklass=Provider)
#			self.org_providers.append(pro)
		self.user = create_user(get_random_username(), 'staff', 'S', 'demo')
		staff = OfficeStaff()
		staff.user = self.user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.save()
		self.staff = staff
		self.provider = create_user("Pravider2", 'Provider', 'P', 'demo', uklass=Provider)
		self.provider.save()
Example #6
0
class CanWeCreateThisTypeUnderThatTypeTest(TestCase):
    org_type = None
    sub_type = None

    def setUp(self):
        clean_db_datas()
        org_setting = OrganizationSetting()
        org_setting.save()
        self.org_type = OrganizationType(name="Test Org Type1",
                                         organization_setting=org_setting,
                                         is_public=True)
        self.org_type.save()
        self.sub_type = OrganizationType(name="Test Org Type2",
                                         organization_setting=org_setting,
                                         is_public=True)
        self.sub_type.save()

    def test_can_we_create_this_type_under_that_type_cant(self):
        self.assertFalse(can_we_create_this_type_under_that_type(-1, None))
        self.assertFalse(
            can_we_create_this_type_under_that_type(self.sub_type.id,
                                                    self.org_type.id))

    def test_can_we_create_this_type_under_that_type_can(self):
        OrganizationTypeSubs.objects.create(
            from_organizationtype=self.org_type,
            to_organizationtype=self.sub_type)
        self.assertTrue(
            can_we_create_this_type_under_that_type(self.sub_type.id,
                                                    self.org_type.id))

    def tearDown(self):
        pass
Example #7
0
class OrganizationSettingTest(TestCase):
    organization = None
    org_setting = None
    org_type = None
    org_type_setting = None

    def setUp(self):
        clean_db_datas()
        self.organization = create_organization(auto_type=False)

        self.org_setting = OrganizationSetting()
        self.org_setting.save()

        self.org_type_setting = OrganizationSetting()
        self.org_type_setting.save()
        self.org_type = OrganizationType(
            name="Test Org Type", organization_setting=self.org_type_setting)
        self.org_type.save()

    def testOrganizationSetting_None(self):
        self.assertIsNone(self.organization.get_setting())

        self.organization.organization_setting = self.org_setting
        self.organization.save()
        self.org_setting.delete_flag = True
        self.org_setting.save()
        self.assertIsNone(self.organization.get_setting())

    def testOrganizationSetting_FromOrganization(self):
        self.organization.organization_setting = self.org_setting
        self.organization.save()
        self.org_setting.delete_flag = False
        self.org_setting.save()
        self.assertEqual(self.org_setting, self.organization.get_setting())

        self.organization.organization_type = self.org_type
        self.organization.save()
        setting = self.organization.get_setting()
        self.assertEqual(self.org_setting, setting)
        self.assertNotEqual(self.org_type_setting, setting)

    def testOrganizationSetting_FromOrganizationType(self):
        self.organization.organization_type = self.org_type
        self.organization.organization_setting = None
        self.organization.save()
        self.assertEqual(self.org_type_setting,
                         self.organization.get_setting())

        self.org_setting.delete_flag = True
        self.org_setting.save()
        self.organization.organization_type = self.org_type
        self.organization.organization_setting = self.org_setting
        self.organization.save()
        setting = self.organization.get_setting()
        self.assertEqual(self.org_type_setting, setting)
        self.assertNotEqual(self.org_setting, setting)

    def tearDown(self):
        clean_db_datas()
Example #8
0
class OrganizationSettingTest(TestCase):
	organization = None
	org_setting = None
	org_type = None
	org_type_setting = None

	def setUp(self):
		clean_db_datas()
		self.organization = create_organization(auto_type=False)

		self.org_setting = OrganizationSetting()
		self.org_setting.save()

		self.org_type_setting = OrganizationSetting()
		self.org_type_setting.save()
		self.org_type = OrganizationType(name="Test Org Type", organization_setting=self.org_type_setting)
		self.org_type.save()

	def testOrganizationSetting_None(self):
		self.assertIsNone(self.organization.get_setting())

		self.organization.organization_setting = self.org_setting
		self.organization.save()
		self.org_setting.delete_flag = True
		self.org_setting.save()
		self.assertIsNone(self.organization.get_setting())

	def testOrganizationSetting_FromOrganization(self):
		self.organization.organization_setting = self.org_setting
		self.organization.save()
		self.org_setting.delete_flag = False
		self.org_setting.save()
		self.assertEqual(self.org_setting, self.organization.get_setting())

		self.organization.organization_type = self.org_type
		self.organization.save()
		setting = self.organization.get_setting()
		self.assertEqual(self.org_setting, setting)
		self.assertNotEqual(self.org_type_setting, setting)

	def testOrganizationSetting_FromOrganizationType(self):
		self.organization.organization_type = self.org_type
		self.organization.organization_setting = None
		self.organization.save()
		self.assertEqual(self.org_type_setting, self.organization.get_setting())

		self.org_setting.delete_flag = True
		self.org_setting.save()
		self.organization.organization_type = self.org_type
		self.organization.organization_setting = self.org_setting
		self.organization.save()
		setting = self.organization.get_setting()
		self.assertEqual(self.org_type_setting, setting)
		self.assertNotEqual(self.org_setting, setting)

	def tearDown(self):
		clean_db_datas()
Example #9
0
class GetParentTypesByTypeidTest(TestCase):
    org_type = None
    admin = None
    manager = None
    organization = None

    def setUp(self):
        clean_db_datas()

        OrganizationType.objects.all().delete()
        org_setting = OrganizationSetting()
        org_setting.save()
        self.org_type = OrganizationType(name="Test Org Type1",
                                         organization_setting=org_setting,
                                         is_public=True)
        self.org_type.save()

        self.organization = create_organization()

        self.admin = create_user('admin',
                                 'Morris',
                                 'Kelly',
                                 'demo',
                                 uklass=Administrator)
        staff = create_user('practicemgr1',
                            'Practice',
                            'Mgr',
                            'demo',
                            uklass=OfficeStaff)
        staff.practices.add(self.organization)
        staff.save()

        self.manager = Office_Manager(user=staff,
                                      practice=self.organization,
                                      manager_role=1)
        self.manager.save()

    def test_get_parent_types_by_typeid(self):
        create_multiple_organization_types(self.org_type, num=10)
        self.assertEqual(1, len(get_parent_types_by_typeid(self.org_type.id)))
        with self.assertRaises(Exception):
            get_parent_types_by_typeid('2sadfa')
        with self.assertRaises(Exception):
            get_parent_types_by_typeid('')

        create_multiple_organization_types(self.org_type,
                                           num=10,
                                           is_public=False)
        self.assertEqual(1, len(get_parent_types_by_typeid(self.org_type.id)))
        self.assertEqual(
            0, len(get_parent_types_by_typeid(self.org_type.id,
                                              is_public=True)))
        self.assertEqual(0, len(get_parent_types_by_typeid(None)))

    def tearDown(self):
        pass
Example #10
0
class GetSubTypesICanUseTest(TestCase):
	org_type = None
	admin = None
	manager = None
	organization = None

	def setUp(self):
		clean_db_datas()

		OrganizationType.objects.all().delete()
		org_setting = OrganizationSetting()
		org_setting.save()
		self.org_type = OrganizationType(name="Test Org Type1", 
			organization_setting=org_setting, is_public=True)
		# TODO: issue 2030, reserved id's is a hazardous approach, the UT's 
		# were working with SQLlite but not with MySQL, DB engines recycle
		# id's differently and we should not rely on reserved id fields.  This 
		# should be addressed in a separate Redmine as model changes may occur.
		self.org_type.id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE
		self.org_type.save()

		self.organization = create_organization()
		self.organization = PracticeLocation(
			practice_name=get_random_username(),
			practice_address1='555 Pleasant Pioneer Grove',
			practice_address2='Trailer Q615',
			practice_city='Mountain View',
			practice_state='CA',
			practice_zip='94040-4104',
			practice_lat=37.36876,
			practice_longit=-122.081864)
		self.organization.save()

		self.admin = create_user('admin', 'Morris', 'Kelly', 'demo', uklass=Administrator)
		staff = create_user('practicemgr1', 'Practice', 'Mgr', 'demo', uklass=OfficeStaff)
		staff.practices.add(self.organization)
		staff.save()

		self.manager = Office_Manager(user=staff, practice=self.organization, manager_role=1)
		self.manager.save()

	def test_get_sub_types_I_can_use_empty(self):
		self.assertEqual(0, len(get_sub_types_by_typeid(self.org_type.id)))

	def test_get_sub_types_I_can_use(self):
		create_multiple_organization_types(self.org_type, num=10)
		self.assertEqual(10, len(get_sub_types_by_typeid(self.org_type.id)))

		create_multiple_organization_types(self.org_type, num=10, is_public=False)
		self.assertEqual(10, len(get_sub_types_by_typeid(self.org_type.id)))
		self.assertEqual(0, len(get_sub_types_by_typeid(self.org_type.id, is_public=True)))

	def tearDown(self):
		pass
Example #11
0
def create_org_type(org_setting=None):
	if not org_setting:
		org_setting = OrganizationSetting() 
		org_setting.save()
	type_name = "Test Org Type"
	organization_type = OrganizationType(name=type_name, organization_setting=org_setting)
	# force id for test - MySQL UT's don't re-use ids after cleanup 
	organization_type.id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE
	# TODO: issue 2030, reserved id's is a hazardous approach, the UT's 
	# were working with SQLlite but not with MySQL, DB engines recycle
	# id's differently and we should not rely on reserved id fields.  This 
	# should be addressed in a separate Redmine as model changes may occur.
	organization_type.save()
	return organization_type
Example #12
0
def create_org_type(org_setting=None):
    if not org_setting:
        org_setting = OrganizationSetting()
        org_setting.save()
    type_name = "Test Org Type"
    organization_type = OrganizationType(name=type_name,
                                         organization_setting=org_setting)
    # force id for test - MySQL UT's don't re-use ids after cleanup
    organization_type.id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE
    # TODO: issue 2030, reserved id's is a hazardous approach, the UT's
    # were working with SQLlite but not with MySQL, DB engines recycle
    # id's differently and we should not rely on reserved id fields.  This
    # should be addressed in a separate Redmine as model changes may occur.
    organization_type.save()
    return organization_type
Example #13
0
    def setUp(self):
        clean_db_datas()

        org_setting = OrganizationSetting()
        org_setting.save()
        org_type = OrganizationType(name="Test Org Type",
                                    organization_setting=org_setting,
                                    is_public=True)
        org_type.save()
        self.org = PracticeLocation(
            practice_name="Test1",
            practice_address1='555 Pleasant Pioneer Grove',
            practice_address2='Trailer Q615',
            practice_city='Mountain View',
            practice_state='CA',
            practice_zip='94040-4104',
            practice_lat=37.36876,
            practice_longit=-122.081864)
        self.org.organization_type = org_type
        self.org.save()

        for i in range(10):
            user_name = "".join(["Staff1_", str(i)])
            first_name = "".join(["Test1_", str(i)])
            user = create_user(user_name,
                               first_name,
                               'S',
                               'demo',
                               uklass=OfficeStaff)
            self.org_staff.append(user)

            # IntegrityError: column username is not unique
#			provider_name = "".join(["Pravider1_", str(i)])
#			pro = create_user(provider_name, 'Provider', 'P', 'demo', uklass=Provider)
#			self.org_providers.append(pro)

        self.staff = create_user("Staff2",
                                 'Test2',
                                 'S',
                                 'demo',
                                 uklass=OfficeStaff)
        self.staff.save()
        self.provider = create_user("Pravider2",
                                    'Provider',
                                    'P',
                                    'demo',
                                    uklass=Provider)
        self.provider.save()
Example #14
0
	def test_get_orgs_I_can_manage_user(self):
		user = create_user('yangpeng','yang','peng','demo')
		org_setting = OrganizationSetting()
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type", \
				organization_setting=org_setting, is_public=True)
		org_type.save()
		staff = OfficeStaff()
		staff.user = user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.current_practice = self.organization
		staff.save()
		staff.practices.add(self.organization)
		mgr = Office_Manager(user=staff, practice=self.organization, manager_role=2)
		mgr.save()
		get_orgs_I_can_manage(mgr.id,parent_id=self.parent_organization.id,\
				org_type_id=org_type.id,clear_no_type_org=True)
Example #15
0
    def setUpClass(cls):
        clean_db_datas()
        cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo')
        org_setting = OrganizationSetting()
        org_setting.save()
        org_type = OrganizationType(name="Test Org Type",
                                    organization_setting=org_setting,
                                    is_public=True)
        org_type.save()
        cls.org_type = org_type
        sub_types = create_multiple_organization_types(org_type)
        cls.sub_types = sub_types

        practice = PracticeLocation(
            practice_name='test',
            practice_longit='0.1',
            practice_lat='0.0',
            organization_type=org_type,
        )
        practice.save()
        practice1 = PracticeLocation(
            practice_name='test1',
            practice_longit='0.1',
            practice_lat='0.0',
            organization_type=org_type,
        )
        practice1.save()
        OrganizationRelationship.objects.create(organization=practice,
                                                parent=practice1,
                                                create_time=int(time.time()),
                                                billing_flag=True)
        cls.practice = practice
        cls.practice1 = practice1

        staff = OfficeStaff()
        staff.user = cls.user
        staff.office_lat = 0.0
        staff.office_longit = 0.0
        staff.current_practice = practice
        staff.save()
        staff.practices.add(practice)

        mgr = Office_Manager(user=staff, practice=practice, manager_role=2)
        mgr.save()
Example #16
0
def create_multiple_organization_types(parent_type, num=10, is_public=True):
	sub_types = []
	OrganizationType.objects.all().delete()
	org_setting = OrganizationSetting()
	org_setting.save()
	for i in xrange(num):
		type_name = "".join(["Test Org Type2_", str(i)])
		_org_type = OrganizationType(name=type_name, 
			organization_setting=org_setting, is_public=is_public)
		_org_type.id = i + 1
		# TODO: issue 2030, reserved id's is a hazardous approach, the UT's 
		# were working with SQLlite but not with MySQL, DB engines recycle
		# id's differently and we should not rely on reserved id fields.  This 
		# should be addressed in a separate Redmine as model changes may occur.
		_org_type.save()
		sub_types.append(_org_type)
		OrganizationTypeSubs.objects.create(from_organizationtype=parent_type, 
			to_organizationtype=_org_type)
	return sub_types
Example #17
0
 def test_get_orgs_I_can_manage_user(self):
     user = create_user('yangpeng', 'yang', 'peng', 'demo')
     org_setting = OrganizationSetting()
     org_setting.save()
     org_type = OrganizationType(name="Test Org Type", \
       organization_setting=org_setting, is_public=True)
     org_type.save()
     staff = OfficeStaff()
     staff.user = user
     staff.office_lat = 0.0
     staff.office_longit = 0.0
     staff.current_practice = self.organization
     staff.save()
     staff.practices.add(self.organization)
     mgr = Office_Manager(user=staff,
                          practice=self.organization,
                          manager_role=2)
     mgr.save()
     get_orgs_I_can_manage(mgr.id,parent_id=self.parent_organization.id,\
       org_type_id=org_type.id,clear_no_type_org=True)
Example #18
0
	def setUpClass(cls):
		clean_db_datas()
		cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo')
		cls.admin = create_user("sduper", "super", "duper", "demo", 
							"Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator)
		cls.admin.save()
		org_setting = OrganizationSetting(can_have_manager=True,\
						can_have_nurse=True,can_have_dietician=True)
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type", \
						organization_setting=org_setting, is_public=True)
		org_type.save()
		cls.org_type = org_type
		cls.org_setting = org_setting
		
		practice = PracticeLocation(practice_name='test',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_setting =org_setting,
								organization_type = org_type)
		practice.save()
		practice1 = PracticeLocation(practice_name='test1',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_setting =org_setting,
								organization_type = org_type)
		practice1.save()
		cls.practice = practice
		cls.practice1 = practice1
		
		staff = OfficeStaff()
		staff.user = cls.user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.current_practice = practice
		staff.save()
		staff.practices.add(practice)
		cls.staff = staff
		
		mgr = Office_Manager(user=staff, practice=practice, manager_role=2)
		mgr.save()
Example #19
0
    def setUp(self):
        clean_db_datas()

        org_setting = OrganizationSetting()
        org_setting.save()
        org_type = OrganizationType(name="Test Org Type",
                                    organization_setting=org_setting,
                                    is_public=True)
        org_type.save()
        self.org = create_organization()

        for i in range(10):
            user_name = "".join(["Staff1_", str(i)])
            first_name = "".join(["Test1_", str(i)])
            user = create_user(user_name, first_name, 'S', 'demo')
            self.staff = OfficeStaff()
            self.staff.user = user
            self.staff.office_lat = 0.0
            self.staff.office_longit = 0.0
            self.staff.save()
            self.org_staff.append(self.staff)

            # IntegrityError: column username is not unique


#			provider_name = "".join(["Pravider1_", str(i)])
#			pro = create_user(provider_name, 'Provider', 'P', 'demo', uklass=Provider)
#			self.org_providers.append(pro)
        self.user = create_user(get_random_username(), 'staff', 'S', 'demo')
        staff = OfficeStaff()
        staff.user = self.user
        staff.office_lat = 0.0
        staff.office_longit = 0.0
        staff.save()
        self.staff = staff
        self.provider = create_user("Pravider2",
                                    'Provider',
                                    'P',
                                    'demo',
                                    uklass=Provider)
        self.provider.save()
Example #20
0
	def setUp(self):
		clean_db_datas()
		org_setting = OrganizationSetting(can_have_physician=True)
		org_setting.save()
		self.org_setting = org_setting
		org_type = OrganizationType(name="Test Org Type", 
			organization_setting=org_setting, is_public=True)
		org_type.save()
		self.org_type = org_type

		practice = PracticeLocation(practice_name='test',
						practice_longit='0.1',
						practice_lat='0.0',
						organization_type=org_type,
						organization_setting=org_setting,)
		practice.save()
		self.practice = practice

		user = create_user('admin', 'Morris', 'Kelly', 'demo', uklass=Administrator)
		user.save()
		self.client.post('/login/', {'username': user.user.username, 'password': '******'})
Example #21
0
class HowManyInstancesTest(TestCase):
	org_type = None

	def setUp(self):
		clean_db_datas()
		org_setting = OrganizationSetting()
		org_setting.save()
		self.org_type = OrganizationType(name="Test Org Type1", 
			organization_setting=org_setting, is_public=True)
		self.org_type.save()

	def test_how_many_instances_empty(self):
		create_multiple_organizations()
		self.assertEqual(0, len(how_many_instances(self.org_type.id)))

	def test_how_many_instances(self):
		create_multiple_organizations(num=10, org_type=self.org_type)
		self.assertEqual(10, len(how_many_instances(self.org_type.id)))

	def tearDown(self):
		pass
Example #22
0
    def test_get_practices_by_position(self):
        lat = 0.0
        longit = 0.0
        distance = None
        result = get_practices_by_position(lat, longit, distance)
        self.assertEqual(len(result), 0)

        lat = 12.1
        longit = 12.0
        distance = 2
        result = get_practices_by_position(lat, longit, distance)
        self.assertEqual(len(result), 0)

        try:
            org_type = OrganizationType.objects.get(
                pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
        except OrganizationType.DoesNotExist:
            setting = OrganizationSetting()
            setting.save()
            org_type = OrganizationType(
                pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE,
                organization_setting=setting)
            org_type.save()

        location = PracticeLocation(
            practice_address1='555 Pleasant Pioneer Grove',
            practice_address2='Trailer Q615',
            practice_city='Mountain View',
            practice_state='CA',
            practice_zip='94040-4104',
            practice_lat=37.36876,
            practice_longit=-122.081864,
            organization_type=org_type)
        location.save()

        lat = 37
        longit = -122.0
        distance = None
        result = get_practices_by_position(lat, longit, distance)
        self.assertEqual(len(result), 1)
Example #23
0
class HowManyInstancesTest(TestCase):
    org_type = None

    def setUp(self):
        clean_db_datas()
        org_setting = OrganizationSetting()
        org_setting.save()
        self.org_type = OrganizationType(name="Test Org Type1",
                                         organization_setting=org_setting,
                                         is_public=True)
        self.org_type.save()

    def test_how_many_instances_empty(self):
        create_multiple_organizations()
        self.assertEqual(0, len(how_many_instances(self.org_type.id)))

    def test_how_many_instances(self):
        create_multiple_organizations(num=10, org_type=self.org_type)
        self.assertEqual(10, len(how_many_instances(self.org_type.id)))

    def tearDown(self):
        pass
Example #24
0
class GetParentTypesByTypeidTest(TestCase):
	org_type = None
	admin = None
	manager = None
	organization = None

	def setUp(self):
		clean_db_datas()

		OrganizationType.objects.all().delete()
		org_setting = OrganizationSetting()
		org_setting.save()
		self.org_type = OrganizationType(name="Test Org Type1", organization_setting=org_setting, is_public=True)
		self.org_type.save()

		self.organization = create_organization()

		self.admin = create_user('admin', 'Morris', 'Kelly', 'demo', uklass=Administrator)
		staff = create_user('practicemgr1', 'Practice', 'Mgr', 'demo', uklass=OfficeStaff)
		staff.practices.add(self.organization)
		staff.save()

		self.manager = Office_Manager(user=staff, practice=self.organization, manager_role=1)
		self.manager.save()

	def test_get_parent_types_by_typeid(self):
		create_multiple_organization_types(self.org_type, num=10)
		self.assertEqual(1, len(get_parent_types_by_typeid(self.org_type.id)))
		with self.assertRaises(Exception):get_parent_types_by_typeid('2sadfa')
		with self.assertRaises(Exception):get_parent_types_by_typeid('')

		create_multiple_organization_types(self.org_type, num=10, is_public=False)
		self.assertEqual(1, len(get_parent_types_by_typeid(self.org_type.id)))
		self.assertEqual(0, len(get_parent_types_by_typeid(self.org_type.id, is_public=True)))
		self.assertEqual(0, len(get_parent_types_by_typeid(None)))

	def tearDown(self):
		pass
Example #25
0
    def setUp(self):
        clean_db_datas()

        org_setting = OrganizationSetting()
        org_setting.save()
        org_type = OrganizationType(name="Test Org Type",
                                    organization_setting=org_setting,
                                    is_public=True)
        org_type.save()
        self.org = create_organization()

        user1 = create_user(get_random_username(), 'Test1', 'S', 'demo')
        staff1 = OfficeStaff()
        staff1.user = user1
        staff1.office_lat = 0.0
        staff1.office_longit = 0.0
        staff1.current_practice = self.org
        staff1.save()
        staff1.practices.add(self.org)
        self.manager = Office_Manager(user=staff1,
                                      practice=self.org,
                                      manager_role=1)

        user = create_user(get_random_username(), 'Test1', 'S', 'demo')
        staff = OfficeStaff()
        staff.user = user
        staff.office_lat = 0.0
        staff.office_longit = 0.0
        staff.save()
        self.staff = staff

        self.provider = create_user("Pravider2",
                                    'Provider',
                                    'P',
                                    'demo',
                                    uklass=Provider)
        self.provider.save()
Example #26
0
	def test_get_practices_by_position(self):
		lat = 0.0
		longit = 0.0
		distance = None
		result = get_practices_by_position(lat, longit, distance)
		self.assertEqual(len(result), 0)
		
		lat = 12.1
		longit = 12.0
		distance = 2
		result = get_practices_by_position(lat, longit, distance)
		self.assertEqual(len(result), 0)

		try:
			org_type = OrganizationType.objects.get(pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
		except OrganizationType.DoesNotExist:
			setting= OrganizationSetting()
			setting.save()
			org_type = OrganizationType(pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE, organization_setting=setting)
			org_type.save()

		location = PracticeLocation(
			practice_address1='555 Pleasant Pioneer Grove',
			practice_address2='Trailer Q615',
			practice_city='Mountain View',
			practice_state='CA',
			practice_zip='94040-4104',
			practice_lat=37.36876,
			practice_longit= -122.081864,
			organization_type=org_type)
		location.save()
		
		lat = 37
		longit = -122.0
		distance = None
		result = get_practices_by_position(lat, longit, distance)
		self.assertEqual(len(result), 1)
Example #27
0
	def setUpClass(cls):
		clean_db_datas()
		cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo')

		org_setting = OrganizationSetting()
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type", 
			organization_setting=org_setting, is_public=True)
		org_type.save()
		cls.org_type = org_type
		sub_types = create_multiple_organization_types(org_type)
		cls.sub_types = sub_types

		practice = PracticeLocation(practice_name='test',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_type = org_type)
		practice.save()
		practice1 = PracticeLocation(practice_name='test1',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_type = org_type)
		practice1.save()

		OrganizationRelationship.objects.create(organization=practice,\
				parent=practice1,create_time=int(time.time()),billing_flag=True)
		cls.practice = practice
		staff = OfficeStaff()
		staff.user = cls.user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.current_practice = practice
		staff.save()
		staff.practices.add(practice)

		mgr = Office_Manager(user=staff, practice=practice, manager_role=2)
		mgr.save()
Example #28
0
def create_multiple_organizations(num=10, org_type=None):
	orgs = []
	if not org_type:
		org_setting = OrganizationSetting()
		org_setting.save()
		org_type = OrganizationType(name="Test Org Type2", 
			organization_setting=org_setting, is_public=True)
		org_type.save()

	for i in xrange(num):
		practice_name = "".join(["Test1_", str(i)])
		_organization = PracticeLocation(
			practice_name=practice_name,
			practice_address1='555 Pleasant Pioneer Grove',
			practice_address2='Trailer Q615',
			practice_city='Mountain View',
			practice_state='CA',
			practice_zip='94040-4104',
			practice_lat=37.36876,
			practice_longit=-122.081864,
			organization_type=org_type)
		_organization.save()
		orgs.append(_organization)
	return orgs
Example #29
0
    def setUpClass(cls):
        clean_db_datas()
        cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo')
        cls.provider = create_user("dholiday",
                                   "doc",
                                   "holiday",
                                   "demo",
                                   uklass=Provider)

        org_setting = OrganizationSetting(can_have_physician=True,
                                          can_have_nppa=True,
                                          can_have_medical_student=True)
        org_setting.save()
        cls.org_setting = org_setting
        org_type = OrganizationType(name="Test Org Type",
                                    organization_setting=org_setting,
                                    is_public=True)
        org_type.save()
        cls.org_type = org_type

        practice = PracticeLocation(
            practice_name='test',
            practice_longit='0.1',
            practice_lat='0.0',
            organization_type=org_type,
            organization_setting=org_setting,
        )
        practice.save()
        practice1 = PracticeLocation(
            practice_name='test1',
            practice_longit='0.1',
            practice_lat='0.0',
            organization_type=org_type,
            organization_setting=org_setting,
        )
        practice1.save()

        OrganizationRelationship.objects.create(organization=practice,
                                                parent=practice1,
                                                create_time=int(time.time()),
                                                billing_flag=True)

        cls.practice = practice
        staff = OfficeStaff()
        staff.user = cls.user
        staff.office_lat = 0.0
        staff.office_longit = 0.0
        staff.current_practice = practice
        staff.save()
        staff.practices.add(practice)

        mgr = Office_Manager(user=staff, practice=practice, manager_role=2)
        mgr.save()
        datadict = {
            'user_type': 1,
            'org_id': cls.practice.id,
            'username': get_random_username(),
            'first_name': 'yang',
            'last_name': 'peng',
            'mobile_phone': 9001111111,
            'gender': 'M',
            'email': '*****@*****.**',
            'lat': 0.0,
            'longit': 0.0,
            'address1': 'address1',
            'address2': 'address2',
            'city': 'Chicago',
            'state': 'IL',
            'zip': 60601,
            'user_type': 1,
            'office_lat': 41.885805,
            'office_longit': -87.6229106,
        }
        cls.datadict = datadict
Example #30
0
	def setUpClass(cls):
		from MHLogin.MHLOrganization.tests.utils import create_multiple_organization_types
		clean_db_datas()
		cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo')
		org_setting = OrganizationSetting(can_have_staff=True, 
			can_have_nurse=True, can_have_dietician=True)
		org_setting.save()

		org_type = OrganizationType(name="Test Org Type - old type", 
				organization_setting=org_setting, is_public=True)
		org_type.save()
		cls.org_type = org_type

		parent_org_type = OrganizationType(name="Test Org Type - parent type", organization_setting=org_setting, is_public=True)
		parent_org_type.save()
		cls.parent_org_type = parent_org_type

		sub_types = create_multiple_organization_types(parent_org_type)
		cls.sub_types = sub_types

		old_parent_practice = PracticeLocation(practice_name='old org parent',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_setting=org_setting,
								organization_type=parent_org_type,)
		old_parent_practice.save()
		OrganizationRelationship.objects.create(organization=old_parent_practice,
			parent=None, create_time=int(time.time()), billing_flag=True)
		cls.old_parent_practice = old_parent_practice

		practice = PracticeLocation(practice_name='test org',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_setting=org_setting,
								organization_type=org_type,)
		practice.save()

		OrganizationRelationship.objects.create(organization=practice,\
			parent=old_parent_practice, create_time=int(time.time()), billing_flag=True)

		new_parent_practice = PracticeLocation(practice_name='new org parent',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_setting=org_setting,
								organization_type=parent_org_type,)
		new_parent_practice.save()
		OrganizationRelationship.objects.create(organization=new_parent_practice,
			parent=None, create_time=int(time.time()), billing_flag=True)

		cls.new_parent_practice = new_parent_practice
		cls.practice = practice

		staff = OfficeStaff()
		staff.user = cls.user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.current_practice = practice
		staff.save()
		staff.practices.add(practice)
		staff.practices.add(old_parent_practice)
		staff.practices.add(new_parent_practice)
		cls.staff = staff
		Office_Manager.objects.create(user=staff, practice=practice, manager_role=2)

		datadict = {
			'user_type':1,
			'org_id': practice.id,
			'username':get_random_username(),
			'first_name':'yang',
			'last_name':'peng',
			'mobile_phone':9001111111,
			'gender':'M',
			'email':'*****@*****.**',
			'lat':0.0, 
			'longit':0.0, 
			'address1':'address1', 
			'address2':'address2', 
			'city':'Chicago', 
			'state':'IL', 
			'zip':60601,
			'user_type':1,
			'office_lat':41.885805,
			'office_longit':-87.6229106,
		}
		cls.datadict = datadict
Example #31
0
class WhichOrgsContainThisUserByIdTest(TestCase):
	orgs = []
	org = None
	org_type = None
	staff = None
	def setUp(self):
		clean_db_datas()
		self.user = create_user(get_random_username(),'yang','peng','demo')
		org_setting = OrganizationSetting(display_in_contact_list_tab=True)
		org_setting.save()
		self.org_type = OrganizationType(name="Test Org Type", organization_setting=org_setting, is_public=True)
		self.org_type.save()
		self.org = create_organization()
		staff = OfficeStaff()
		staff.user = self.user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.save()
		self.staff = staff

		self.org_members = []
		self.org_members = create_multiple_organizations(10)

	def test_which_orgs_contain_this_user(self):
		org_ids = []
		for p in self.orgs:
			self.staff.practices.add(p)
			org_ids.append(p.id)
		self.staff.save()

		orgs_contain = which_orgs_contain_this_user(self.staff.user.id, in_tab=False)
		orgs_contain_ids = [p.id for p in orgs_contain]
		self.assertEqual(len(org_ids), len(orgs_contain_ids))
		self.assertListEqual(org_ids, orgs_contain_ids)
		self.assertNotIn(self.org.id, orgs_contain_ids)

	def test_which_orgs_contain_this_user_in_tab(self):
		org_ids = []
		for p in self.orgs:
			org_setting = OrganizationSetting(display_in_contact_list_tab=True)
			org_setting.save()
			p.organization_setting = org_setting
			p.save()
			self.staff.practices.add(p)
			org_ids.append(p.id)
		self.staff.save()

		orgs_contain = which_orgs_contain_this_user(self.staff.user.id, in_tab=True)
		orgs_contain_ids = [p.id for p in orgs_contain]
		self.assertEqual(len(org_ids), len(orgs_contain_ids))
		self.assertListEqual(org_ids, orgs_contain_ids)
		self.assertNotIn(self.org.id, orgs_contain_ids)

	def test_which_orgs_contain_this_user_in_tab_from_org_type(self):
		org_ids = []
		for p in self.orgs:
			p.organization_type = self.org_type
			p.save()
			self.staff.practices.add(p)
			org_ids.append(p.id)
		self.staff.save()

		orgs_contain = which_orgs_contain_this_user(self.staff.user.id, in_tab=True)
		orgs_contain_ids = [p.id for p in orgs_contain]
		self.assertEqual(len(org_ids), len(orgs_contain_ids))
		self.assertListEqual(org_ids, orgs_contain_ids)
		self.assertNotIn(self.org.id, orgs_contain_ids)

	def tearDown(self):
		clean_db_datas()
Example #32
0
	def setUpClass(cls):
		clean_db_datas()
		cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo')
		cls.provider = create_user("dholiday", "doc", "holiday", "demo", uklass=Provider)

		org_setting = OrganizationSetting(can_have_physician=True, can_have_nppa=True,
				can_have_medical_student=True)
		org_setting.save()
		cls.org_setting = org_setting
		org_type = OrganizationType(name="Test Org Type", 
				organization_setting=org_setting, is_public=True)
		org_type.save()
		cls.org_type = org_type

		practice = PracticeLocation(practice_name='test',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_type=org_type,
								organization_setting=org_setting,)
		practice.save()
		practice1 = PracticeLocation(practice_name='test1',
								practice_longit='0.1',
								practice_lat='0.0',
								organization_type=org_type,
								organization_setting=org_setting,)
		practice1.save()

		OrganizationRelationship.objects.create(organization=practice,
			parent=practice1, create_time=int(time.time()), billing_flag=True)

		cls.practice = practice
		staff = OfficeStaff()
		staff.user = cls.user
		staff.office_lat = 0.0
		staff.office_longit = 0.0
		staff.current_practice = practice
		staff.save()
		staff.practices.add(practice)

		mgr = Office_Manager(user=staff, practice=practice, manager_role=2)
		mgr.save()
		datadict = {
			'user_type':1,
			'org_id': cls.practice.id,
			'username':get_random_username(),
			'first_name':'yang',
			'last_name':'peng',
			'mobile_phone':9001111111,
			'gender':'M',
			'email':'*****@*****.**',
			'lat':0.0, 
			'longit':0.0, 
			'address1':'address1', 
			'address2':'address2', 
			'city':'Chicago', 
			'state':'IL', 
			'zip':60601,
			'user_type':1,
			'office_lat':41.885805,
			'office_longit':-87.6229106,
		}
		cls.datadict = datadict
Example #33
0
class GetSubTypesICanUseTest(TestCase):
    org_type = None
    admin = None
    manager = None
    organization = None

    def setUp(self):
        clean_db_datas()

        OrganizationType.objects.all().delete()
        org_setting = OrganizationSetting()
        org_setting.save()
        self.org_type = OrganizationType(name="Test Org Type1",
                                         organization_setting=org_setting,
                                         is_public=True)
        # TODO: issue 2030, reserved id's is a hazardous approach, the UT's
        # were working with SQLlite but not with MySQL, DB engines recycle
        # id's differently and we should not rely on reserved id fields.  This
        # should be addressed in a separate Redmine as model changes may occur.
        self.org_type.id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE
        self.org_type.save()

        self.organization = create_organization()
        self.organization = PracticeLocation(
            practice_name=get_random_username(),
            practice_address1='555 Pleasant Pioneer Grove',
            practice_address2='Trailer Q615',
            practice_city='Mountain View',
            practice_state='CA',
            practice_zip='94040-4104',
            practice_lat=37.36876,
            practice_longit=-122.081864)
        self.organization.save()

        self.admin = create_user('admin',
                                 'Morris',
                                 'Kelly',
                                 'demo',
                                 uklass=Administrator)
        staff = create_user('practicemgr1',
                            'Practice',
                            'Mgr',
                            'demo',
                            uklass=OfficeStaff)
        staff.practices.add(self.organization)
        staff.save()

        self.manager = Office_Manager(user=staff,
                                      practice=self.organization,
                                      manager_role=1)
        self.manager.save()

    def test_get_sub_types_I_can_use_empty(self):
        self.assertEqual(0, len(get_sub_types_by_typeid(self.org_type.id)))

    def test_get_sub_types_I_can_use(self):
        create_multiple_organization_types(self.org_type, num=10)
        self.assertEqual(10, len(get_sub_types_by_typeid(self.org_type.id)))

        create_multiple_organization_types(self.org_type,
                                           num=10,
                                           is_public=False)
        self.assertEqual(10, len(get_sub_types_by_typeid(self.org_type.id)))
        self.assertEqual(
            0, len(get_sub_types_by_typeid(self.org_type.id, is_public=True)))

    def tearDown(self):
        pass
Example #34
0
class WhichOrgsContainThisUserByIdTest(TestCase):
    orgs = []
    org = None
    org_type = None
    staff = None

    def setUp(self):
        clean_db_datas()
        self.user = create_user(get_random_username(), 'yang', 'peng', 'demo')
        org_setting = OrganizationSetting(display_in_contact_list_tab=True)
        org_setting.save()
        self.org_type = OrganizationType(name="Test Org Type",
                                         organization_setting=org_setting,
                                         is_public=True)
        self.org_type.save()
        self.org = create_organization()
        staff = OfficeStaff()
        staff.user = self.user
        staff.office_lat = 0.0
        staff.office_longit = 0.0
        staff.save()
        self.staff = staff

        self.org_members = []
        self.org_members = create_multiple_organizations(10)

    def test_which_orgs_contain_this_user(self):
        org_ids = []
        for p in self.orgs:
            self.staff.practices.add(p)
            org_ids.append(p.id)
        self.staff.save()

        orgs_contain = which_orgs_contain_this_user(self.staff.user.id,
                                                    in_tab=False)
        orgs_contain_ids = [p.id for p in orgs_contain]
        self.assertEqual(len(org_ids), len(orgs_contain_ids))
        self.assertListEqual(org_ids, orgs_contain_ids)
        self.assertNotIn(self.org.id, orgs_contain_ids)

    def test_which_orgs_contain_this_user_in_tab(self):
        org_ids = []
        for p in self.orgs:
            org_setting = OrganizationSetting(display_in_contact_list_tab=True)
            org_setting.save()
            p.organization_setting = org_setting
            p.save()
            self.staff.practices.add(p)
            org_ids.append(p.id)
        self.staff.save()

        orgs_contain = which_orgs_contain_this_user(self.staff.user.id,
                                                    in_tab=True)
        orgs_contain_ids = [p.id for p in orgs_contain]
        self.assertEqual(len(org_ids), len(orgs_contain_ids))
        self.assertListEqual(org_ids, orgs_contain_ids)
        self.assertNotIn(self.org.id, orgs_contain_ids)

    def test_which_orgs_contain_this_user_in_tab_from_org_type(self):
        org_ids = []
        for p in self.orgs:
            p.organization_type = self.org_type
            p.save()
            self.staff.practices.add(p)
            org_ids.append(p.id)
        self.staff.save()

        orgs_contain = which_orgs_contain_this_user(self.staff.user.id,
                                                    in_tab=True)
        orgs_contain_ids = [p.id for p in orgs_contain]
        self.assertEqual(len(org_ids), len(orgs_contain_ids))
        self.assertListEqual(org_ids, orgs_contain_ids)
        self.assertNotIn(self.org.id, orgs_contain_ids)

    def tearDown(self):
        clean_db_datas()