def test_service_list(self): avail_s_list = service_list(Client()) tools.assert_true(self.d2 in avail_s_list) tools.assert_false(self.d1 in avail_s_list) all_s_list = service_list() tools.assert_true(self.d2 in all_s_list) tools.assert_true(self.d1 in all_s_list)
def generate(): print "Generating Regions..." for i in xrange(1, REGION_CNT + 1): fields = { "title": 'Region%i' % i, } r = Region(**fields) r.save() print "Generating Districts..." regions = list(Region.objects.all()) for i in xrange(1, DISTRICT_CNT + 1): fields = { "title": 'District%i' % i, "region": choice(regions), } d = District(**fields) d.save() print "Generating Towns..." districts = list(District.objects.all()) for i in xrange(1, TOWN_CNT + 1): fields = { "title": 'Town%i' % i, "district": choice(districts), } t = Town(**fields) t.save() print "Generating Clients..." drug = Drug.objects.create(title='hero') towns = list(Town.objects.all()) ctype = ContentType.objects.get_by_natural_key('clients', 'client') for i in xrange(1, CLIENT_CNT + 1): client_drug = choice([None, drug]) fields = { "code": "CODE%s" % i, "sex": choice([SEXES.FEMALE, SEXES.MALE]), "town": choice(towns), "title": 'Client%i' % i, "content_type": ctype, "primary_drug": client_drug, "primary_drug_usage": choice([ DRUG_APPLICATION_TYPES.VEIN_INJECTION, DRUG_APPLICATION_TYPES.UNKNOWN, ]), } c = Client(**fields) c.save() print "Generating Practitioners..." towns = list(Town.objects.all()) ctype = ContentType.objects.get_by_natural_key('clients', 'practitioner') for i in xrange(1, PRACTITIONER_CNT + 1): fields = { "sex": choice([SEXES.FEMALE, SEXES.MALE]), "town": choice(towns), "last_name": 'sroubek%i' % i, "content_type": ctype, } p = Practitioner(**fields) p.save() clients = list(Client.objects.all()) anonyms = list(Anonymous.objects.all()) practitioners = list(Practitioner.objects.all()) days = [BASE_YEAR + timedelta(days=i) for i in xrange(1, 350)] print "Generating Encounters..." client_encounters = [] for i in xrange(1, CLIENT_ENCOUNTERS_CNT + 1): fields = { "person": choice(clients), "performed_on": choice(days), "where": choice(towns), } e = Encounter(**fields) e.save() client_encounters.append(e) anonymous_encounters = [] for i in xrange(1, ANONYMOUS_ENCOUNTERS_CNT + 1): fields = { "person": choice(anonyms), "performed_on": choice(days), "where": choice(towns), } e = Encounter(**fields) e.save() anonymous_encounters.append(e) person_encounters = client_encounters + anonymous_encounters practitioner_encounters = [] for i in xrange(1, PRACTITIONER_ENCOUNTERS_CNT + 1): fields = { "person": choice(practitioners), "performed_on": choice(days), "where": choice(towns), } e = Encounter(**fields) e.save() practitioner_encounters.append(e) person_encounters = client_encounters + anonymous_encounters + practitioner_encounters print "Generating Services..." ctypes = {} for model in ('harmreduction', 'incomeexamination', 'informationservice', 'contactwork', 'individualcounseling', 'phonecounseling', 'address', 'diseasetest'): ctypes[model] = ContentType.objects.get_by_natural_key('services', model) for i in xrange(1, SERVICE_CNT + 1): fields = { "encounter": choice(client_encounters), "content_type": ctypes['harmreduction'], "in_count": randint(1, 100), "out_count": randint(1, 100), } s = HarmReduction(**fields) s.save() fields = { "content_type": ctypes['incomeexamination'], "encounter": choice(client_encounters), } s = IncomeExamination(**fields) s.save() fields = { "content_type": ctypes['contactwork'], "encounter": choice(client_encounters), } s = ContactWork(**fields) s.save() fields = { "content_type": ctypes['informationservice'], "safe_usage": choice([False, True]), "safe_sex": choice([False, True]), "medical": choice([False, True]), "socio_legal": choice([False, True]), "cure_possibilities": choice([False, True]), "literature": choice([False, True]), "other": choice([False, True]), "encounter": choice(person_encounters), } s = InformationService(**fields) s.save() fields = { "content_type": ctypes['individualcounseling'], "encounter": choice(client_encounters), } s = IndividualCounseling(**fields) s.save() fields = { "content_type": ctypes['address'], "encounter": choice(person_encounters), } s = Address(**fields) s.save() fields = { "content_type": ctypes['phonecounseling'], "encounter": choice(person_encounters), } s = PhoneCounseling(**fields) s.save() fields = { "content_type": ctypes['diseasetest'], "encounter": choice(person_encounters), "disease": choice(list(DISEASES))[0], } s = DiseaseTest(**fields) s.save()
def generate(): print "Generating Regions..." for i in xrange(1, REGION_CNT + 1): fields = { "title": 'Region%i' % i, } r = Region(**fields) r.save() print "Generating Districts..." regions = list(Region.objects.all()) for i in xrange(1, DISTRICT_CNT + 1): fields = { "title": 'District%i' % i, "region": choice(regions), } d = District(**fields) d.save() print "Generating Towns..." districts = list(District.objects.all()) for i in xrange(1, TOWN_CNT + 1): fields = { "title": 'Town%i' % i, "district": choice(districts), } t = Town(**fields) t.save() print "Generating Clients..." drug = Drug.objects.create(title='hero') towns = list(Town.objects.all()) ctype = ContentType.objects.get_by_natural_key('clients', 'client') for i in xrange(1, CLIENT_CNT + 1): client_drug = choice([None, drug]) fields = { "code": "CODE%s" % i, "sex": choice([SEXES.FEMALE, SEXES.MALE]), "town": choice(towns), "title": 'Client%i' % i, "content_type": ctype, "primary_drug": client_drug, "primary_drug_usage": choice([ DRUG_APPLICATION_TYPES.VEIN_INJECTION, DRUG_APPLICATION_TYPES.UNKNOWN, ]), } c = Client(**fields) c.save() print "Generating Practitioners..." towns = list(Town.objects.all()) ctype = ContentType.objects.get_by_natural_key('clients', 'practitioner') for i in xrange(1, PRACTITIONER_CNT + 1): fields = { "sex": choice([SEXES.FEMALE, SEXES.MALE]), "town": choice(towns), "last_name": 'sroubek%i' % i, "content_type": ctype, } p = Practitioner(**fields) p.save() clients = list(Client.objects.all()) anonyms = list(Anonymous.objects.all()) practitioners = list(Practitioner.objects.all()) days = [BASE_YEAR + timedelta(days=i) for i in xrange(1, 350)] print "Generating Encounters..." client_encounters = [] for i in xrange(1, CLIENT_ENCOUNTERS_CNT + 1): fields = { "person": choice(clients), "performed_on": choice(days), "where": choice(towns), } e = Encounter(**fields) e.save() client_encounters.append(e) anonymous_encounters = [] for i in xrange(1, ANONYMOUS_ENCOUNTERS_CNT + 1): fields = { "person": choice(anonyms), "performed_on": choice(days), "where": choice(towns), } e = Encounter(**fields) e.save() anonymous_encounters.append(e) person_encounters = client_encounters + anonymous_encounters practitioner_encounters = [] for i in xrange(1, PRACTITIONER_ENCOUNTERS_CNT + 1): fields = { "person": choice(practitioners), "performed_on": choice(days), "where": choice(towns), } e = Encounter(**fields) e.save() practitioner_encounters.append(e) person_encounters = client_encounters + anonymous_encounters + practitioner_encounters print "Generating Services..." ctypes = {} for model in ('harmreduction', 'incomeexamination', 'informationservice', 'contactwork', 'individualcounseling', 'phonecounseling', 'address', 'diseasetest'): ctypes[model] = ContentType.objects.get_by_natural_key( 'services', model) for i in xrange(1, SERVICE_CNT + 1): fields = { "encounter": choice(client_encounters), "content_type": ctypes['harmreduction'], "in_count": randint(1, 100), "out_count": randint(1, 100), } s = HarmReduction(**fields) s.save() fields = { "content_type": ctypes['incomeexamination'], "encounter": choice(client_encounters), } s = IncomeExamination(**fields) s.save() fields = { "content_type": ctypes['contactwork'], "encounter": choice(client_encounters), } s = ContactWork(**fields) s.save() fields = { "content_type": ctypes['informationservice'], "safe_usage": choice([False, True]), "safe_sex": choice([False, True]), "medical": choice([False, True]), "socio_legal": choice([False, True]), "cure_possibilities": choice([False, True]), "literature": choice([False, True]), "other": choice([False, True]), "encounter": choice(person_encounters), } s = InformationService(**fields) s.save() fields = { "content_type": ctypes['individualcounseling'], "encounter": choice(client_encounters), } s = IndividualCounseling(**fields) s.save() fields = { "content_type": ctypes['address'], "encounter": choice(person_encounters), } s = Address(**fields) s.save() fields = { "content_type": ctypes['phonecounseling'], "encounter": choice(person_encounters), } s = PhoneCounseling(**fields) s.save() fields = { "content_type": ctypes['diseasetest'], "encounter": choice(person_encounters), "disease": choice(list(DISEASES))[0], } s = DiseaseTest(**fields) s.save()
def test_is_available_works_with_limited_to(self): c = Client() c.failme = True tools.assert_false(self.subcls_limited.service.is_available(c))
def test_limited_to_passes(self): tools.assert_true(self.subcls_limited.service.is_available(Client()))