def test_page_status_for_non_doctor_user(self): tmp_user = create_test_user(username='******', password='******') patient = Patient() patient.save() SystemUser.objects.create(user=tmp_user, id_code='123456', role=patient) self.client.login(username='******', password='******') response = self.client.get(reverse_lazy('addClinic')) self.assertNotEqual(response.status_code, 200)
def post(request): username = request.POST.get('username', None) user = User.objects.get(username=username).system_user last_user_role = user.role patient_role = Patient() patient_role.save() user.role = patient_role user.save() last_user_role.delete() return JsonResponse({})
def form_valid(self, form): response = super(SystemUserCreateView, self).form_valid(form) username, password = form.cleaned_data.get( 'username'), form.cleaned_data.get('password') new_user = authenticate(username=username, password=password) user = User.objects.get(username=username) role = Patient() role.save() SystemUser.objects.filter(user=user).update(role=role) login(self.request, new_user) return response
def create_system_user(self, data=user_data, should_login=False): user_count = User.objects.all().count() system_user_count = SystemUser.objects.all().count() if should_login: self.client.post(reverse_lazy('register'), data) else: tmp_user = create_test_user(**data) role = Patient() role.save() SystemUser.objects.create(user=tmp_user, id_code=data['id_code']) SystemUser.objects.filter(user=tmp_user).update(role=role) user = User.objects.filter(username=data['username']) self.assertTrue(user.exists()) self.assertTrue(SystemUser.objects.filter(user=user[0]).exists()) self.assertTrue(SystemUser.objects.filter(id_code=data['id_code']).exists()) self.assertEqual(User.objects.all().count(), user_count + 1, "db doesn't changed") self.assertEqual(SystemUser.objects.all().count(), system_user_count + 1, "db doesn't changed") return SystemUser.objects.get(user=user)
def create_test_system_user(user, id_code): patient = Patient() patient.save() return SystemUser.objects.create(user=user, id_code=id_code, role=patient)