def test_saving_and_retrieving_vacancies(self): username1 = '*****@*****.**' password = '******' user1 = User.objects.create_user(username1, password) first_vacancy = Vacancy() first_vacancy.user = user1 first_vacancy.employer = self.employer first_vacancy.title = 'Welder TIG' first_vacancy.salary_min = 50000 first_vacancy.save() second_vacancy = Vacancy() username2 = '*****@*****.**' password = '******' user2 = User.objects.create_user(username2, password) second_vacancy.user = user2 second_vacancy.employer = self.employer second_vacancy.title = "Welder MIG-MAG" second_vacancy.salary_min = 60000 second_vacancy.save() saved_vacancies = Vacancy.objects.all() self.assertEqual(saved_vacancies.count(), 2) first_saved_vacancy = saved_vacancies[0] second_saved_vacancy = saved_vacancies[1] self.assertEqual(first_saved_vacancy.title, 'Welder TIG') self.assertEqual(second_saved_vacancy.title, 'Welder MIG-MAG')
def post(self, request, vacancy_id): user = request.user if user.is_anonymous: return redirect(reverse('login')) company = get_object_or_404(Company, owner=user) vacancy = Vacancy.objects.filter(id=vacancy_id).annotate(number_of_responses=Count('applications')).first() if vacancy is None: vacancy = Vacancy(company=company) applications = Application.objects.filter(vacancy=vacancy).all() form = VacancyEditForm(request.POST) context = {'form': form, 'company': company, 'vacancy': vacancy, 'applications': applications, 'title_left': 'Моя компания | Вакансия'} if form.is_valid(): data = form.cleaned_data vacancy.title = data['title'] specialty = Specialty.objects.filter(code=data['form_specialty']).first() if specialty is not None: vacancy.specialty = specialty vacancy.company = company vacancy.salary_min = data['salary_min'] vacancy.salary_max = data['salary_max'] vacancy.skills = data['skills'] vacancy.description = data['description'] vacancy.save() context['vacancy_specialty'] = data['specialty'] context['info_updated'] = True return render(request, 'vacancies/vacancy-edit.html', context)
def test_get_vacancy_count(self): username1 = '*****@*****.**' password = '******' user1 = User.objects.create_user(username1, password) first_vacancy = Vacancy() first_vacancy.user = user1 first_vacancy.employer = self.employer_1 first_vacancy.title = 'Welder TIG' first_vacancy.salary_min = 50000 first_vacancy.save() second_vacancy = Vacancy() username2 = '*****@*****.**' password = '******' user2 = User.objects.create_user(username2, password) second_vacancy.user = user2 second_vacancy.employer = self.employer_1 second_vacancy.title = "Welder MIG-MAG" second_vacancy.salary_min = 60000 second_vacancy.save() self.assertEqual(2, self.employer_1.get_vacancy_count())