def test_post_request_bad_type(self): user = self.load_users_data().get_user(groups_id=3) data = { 'veterinary_school': 'CharField', 'graduating_year': get_current_year() - 10, 'veterinarian_type': 'other', 'area_interest': 'dogs' } req = self.factory.post('/', data=data) force_authenticate(req, user=user) resp = views.VeterinarianListCreateView.as_view()(req) assert resp.status_code == 400, ('Should return HTTP 400 Bad Request')
def save(self, *args, **kwargs): if (hasattr(self.user, 'groups') and int(self.veterinarian_type) != self.user.groups.id): raise ValidationError("Group error") if self.veterinarian_type != '4': if self.country is None or self.state is None: raise ValidationError("Country and state are required") if self.country != self.state.country: raise ValueError( "The state does not belong to the selected country.") else: if not self.graduating_year: raise ValueError('Graduating year is needed') if not self.veterinary_school: raise ValueError('Veterinarian School is needed') if self.graduating_year < get_limit_year(): raise ValueError('The graduating year cannot be lower than ' + str(get_limit_year())) if self.graduating_year > get_current_year() + 20: raise ValueError('The graduating year cannot be higher than ' + 'the year ' + str(get_current_year() + 20)) super(Veterinarian, self).save(*args, **kwargs)
def test_post_if_vet_verified(self): user = self.load_users_data().get_user(groups_id=3) country = mixer.blend('countries.country') state = mixer.blend('countries.state', country=country) mixer.blend('users.veterinarian', user=user, verified=True, graduating_year=get_current_year() - 11, country=country, state=state, veterinarian_type=3) obj = mixer.blend('posts.post', user=user) assert obj.visible_by_vet assert not obj.visible_by_owner
def test_post_request_no_country_student(self): user = self.load_users_data().get_user(groups_id=4) user = mixer.blend(models.User, groups_id=4) area_interest = mixer.blend(models.AreaInterest) data = { 'veterinary_school': 'CharField', 'graduating_year': get_current_year() - 10, 'veterinarian_type': '4', 'area_interest': area_interest.pk, } req = self.factory.post('/', data=data) force_authenticate(req, user=user) resp = views.VeterinarianListCreateView.as_view()(req) assert resp.status_code == 201, ('Should return object created (201)')
def test_post_request_bad_state(self): user = self.load_users_data().get_user(groups_id=5) area_interest = mixer.blend(models.AreaInterest) country = mixer.blend(models_c.Country) state = mixer.blend(models_c.State) data = { 'veterinary_school': 'CharField', 'graduating_year': get_current_year() - 5, 'veterinarian_type': 'vet', 'area_interest': area_interest.id, 'country': country.id, 'state': state.id } req = self.factory.post('/', data=data) force_authenticate(req, user=user) resp = views.VeterinarianListCreateView.as_view()(req) assert resp.status_code == 400, ('Should return HTTP 400 Bad Request')
def test_vet_follow_vet(self): vet = self.load_users_data().get_user(groups_id=3) vet1 = self.get_user(groups_id=3) area_interest = mixer.blend(models.AreaInterest) country = mixer.blend(models_c.Country) state = mixer.blend(models_c.State, country=country) data = { 'graduating_year': get_current_year() - 5, 'veterinarian_type': 5, 'area_interest': area_interest, 'country': country, 'state': state, 'veterinarian_type': '3' } mixer.blend('users.Veterinarian', user=vet, verified=True, **data) mixer.blend('users.Veterinarian', user=vet1, verified=True, **data) req = self.factory.post('/') force_authenticate(req, user=vet) resp = views.UserFollowView.as_view()(req, pk=vet1.pk) assert resp.status_code == 201