예제 #1
0
파일: tests.py 프로젝트: hspandher/my_shine
class LoginPageTest(PageTestMethodsMixin, TestCase):

    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()

        self.work_experience = WorkExperience(
            candidate = self.candidate,
            is_experienced = True,
            years_of_experience = 3,
            months_of_experience = 10)

        self.work_experience.save()

        self.education_qualifications = EducationQualifications(
            candidate = self.candidate,
            highest_qualification = '10+2',
            education_specialization = 'Non-Medical',
            institute_name = 'CBSE')

        self.education_qualifications.save()
        self.url = '/login/'
        self.response = login(HttpRequest())

        self.form_details = {
            'email': '*****@*****.**',
            'password': '******'
        }


    def test_login_url_resolves_to_right_view(self):
        found = resolve(self.url)
        self.assertEqual(found.func, login)

    def test_login_view_returns_http_response(self):
        self.assertIsInstance(self.response, HttpResponse)

    def test_login_view_uses_right_template(self):
        expected_response = render_to_response('login.html', { 'form': LoginForm(), 'authentication_error': None })
        self.assertEqual(expected_response.content, self.response.content)

    def test_login_view_has_right_title(self):
        self.assertIn('<title>Login</title>', self.response.content)

    def test_login_view_has_right_header(self):
        self.assertIn('<h1>Login</h1>', self.response.content)

    def test_login_view_has_correct_form_fields(self):
        input_fields_names = ['email', 'password', 'Login']
        for field_name in input_fields_names:
            self.assertIn(field_name, self.response.content)
예제 #2
0
파일: tests.py 프로젝트: hspandher/my_shine
class WorkExperiencePageTest(PageTestMethodsMixin, TestCase):

    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()
        self.url = "/candidate/{id}/add-work-experience/".format(id = self.candidate.id)
        self.response = add_work_experience(HttpRequest(), self.candidate.id)
        self.form_details = {
            'is_experienced': True,
            'years_of_experience': 4,
            'months_of_experience': 5
        }

    def test_work_url_resolves_to_right_view(self):
        found = resolve(self.url)
        self.assertEqual(found.func, add_work_experience)

    def test_work_view_returns_http_response_object(self):
        self.assertIsInstance(self.response, HttpResponse)

    def test_work_view_uses_right_template(self):
        expected_response = render_to_response('work_experience.html', { 'form': WorkExperienceForm()})
        self.assertEqual(expected_response.content, self.response.content)

    def test_work_view_has_right_title(self):
        self.assertIn('<title>Add Work Experience</title>', self.response.content)

    def test_work_view_has_right_header(self):
        self.assertIn('<h1>Add Work Experience</h1>', self.response.content)

    def test_work_view_has_correct_form_fields(self):
        input_fields_names = ['years_of_experience', 'months_of_experience', 'is_experienced']
        for field_name in input_fields_names:
            self.assertIn(field_name, self.response.content)

    def test_work_view_redirects_after_successful_submission(self):
        response, _ = self.submit_post_form_to_view(self.url, self.form_details, add_work_experience, self.candidate.id)
        self.assertEqual(response.status_code, 302)

    def test_work_view_updates_database_after_successful_submission(self):
        response, form = self.submit_post_form_to_view(self.url, self.form_details, add_work_experience, self.candidate.id)
        self.assertTrue(WorkExperience.objects.get(candidate = self.candidate))
        self.assertTrue(WorkExperience.objects.get(years_of_experience = 4))
        self.assertTrue(WorkExperience.objects.get(months_of_experience = 5))
예제 #3
0
파일: tests.py 프로젝트: hspandher/my_shine
class ProfilePageTest(PageTestMethodsMixin, TestCase):

    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')
        self.candidate.save()

        self.url = "/candidate/{id}/profile/".format(id = self.candidate.id)

        self.work_experience = WorkExperience(
            candidate = self.candidate,
            is_experienced = True,
            years_of_experience = 3,
            months_of_experience = 10)

        self.work_experience.save()

        self.education_qualifications = EducationQualifications(
            candidate = self.candidate,
            highest_qualification = '10+2',
            education_specialization = 'Non-Medical',
            institute_name = 'CBSE')

        self.education_qualifications.save()

        self.response = profile(HttpRequest(), self.candidate.id)


    def test_profile_url_resolves_to_right_view(self):
        found = resolve(self.url)
        self.assertEqual(found.func, profile)

    def test_profile_view_returns_http_response(self):
        self.assertIsInstance(self.response, HttpResponse)

    def test_profile_view_uses_right_template(self):
        expected_response = render_to_response('profile.html', { 'candidate': self.candidate, 'work_experience': self.work_experience, 'qualifications': self.education_qualifications})
        self.assertEqual(expected_response.content, self.response.content)

    def test_profile_view_has_right_title(self):
        self.assertIn('<title>Profile</title>', self.response.content)

    def test_profile_view_has_right_header(self):
        self.assertIn("<h1>{first_name} {last_name}</h1>".format(first_name = self.candidate.first_name, last_name = self.candidate.last_name), self.response.content)
예제 #4
0
파일: tests.py 프로젝트: hspandher/my_shine
class QualificationsPageTest(PageTestMethodsMixin, TestCase):

    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')
        self.candidate.save()
        self.url = "/candidate/{id}/add-qualifications/".format(id = self.candidate.id)
        self.response = add_qualifications(HttpRequest(), self.candidate.id)
        self.form_details = {
            'highest_qualification': '10+2',
            'education_specialization': 'Non-Medical',
            'institute_name': 'Anything'
        }

    def test_qualification_url_resolves_to_right_view(self):
        found = resolve(self.url)
        self.assertEqual(found.func, add_qualifications)

    def test_qualifications_view_returns_http_response(self):
        self.assertIsInstance(self.response, HttpResponse)

    def test_qualifications_view_uses_right_template(self):
        expected_response = render_to_response('qualifications.html', { 'form': QualificationsForm() })
        self.assertEqual(expected_response.content, self.response.content)

    def test_qualifications_view_has_right_title(self):
        self.assertIn('<title>Add Qualifications</title>', self.response.content)

    def test_qualifications_view_has_right_header(self):
        self.assertIn('<h1>Add Qualifications</h1>', self.response.content)

    def test_qualifications_view_has_correct_form_fields(self):
        input_fields_names = ['highest_qualification', 'education_specialization', 'institute_name']
        for field_name in input_fields_names:
            self.assertIn(field_name, self.response.content)

    def test_qualifications_view_redirects_after_successful_submission(self):
        response, _ = self.submit_post_form_to_view(self.url, self.form_details, add_qualifications, self.candidate.id)
        self.assertTrue(EducationQualifications.objects.get(candidate = self.candidate))
        self.assertTrue(EducationQualifications.objects.get(highest_qualification = self.form_details['highest_qualification']))
        self.assertTrue(EducationQualifications.objects.get(education_specialization = self.form_details['education_specialization']))
        self.assertTrue(EducationQualifications.objects.get(institute_name = self.form_details['institute_name']))
예제 #5
0
파일: tests.py 프로젝트: hspandher/my_shine
class EducationQualificationsModelTest(ModelTestMethodsMixin, TestCase):

    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()

        self.work_experience = WorkExperience(
            candidate = self.candidate,
            is_experienced = True,
            years_of_experience = 3,
            months_of_experience = 10)

        self.work_experience.save()

        self.education_qualifications = EducationQualifications(
            candidate = self.candidate,
            highest_qualification = '10+2',
            education_specialization = 'Non-Medical',
            institute_name = 'CBSE')

    def are_qualifications_valid(self):
        return self.is_valid('qualifications')

    def has_appropriate_validation(self, attribute_name, invalid_attributes = ['a'*51, 'aa', '', 'a']):
        self.verify_all_validations('education_qualifications', attribute_name, invalid_attributes)

    def test_qualifications_belong_to_valid_candidate(self):
        Candidate.objects.get(email = self.candidate.email).delete()
        self.assertFalse(self.are_qualifications_valid(), 'Candidate with created qualifications does not exists in the database')

    def test_qualifications_rejects_invalid_highest_qualification(self):
        invalid_highest_qualifications = ['ldfjdslf', 'sdjfdls', '10+2ldsjfl']
        self.has_appropriate_validation('highest_qualification', invalid_highest_qualifications)

    def test_qualifications_rejects_invalid_education_specialiazation(self):
        self.has_appropriate_validation('education_specialization')

    def test_qualifications_rejects_invalid_institute_name(self):
        self.has_appropriate_validation('institute_name')
예제 #6
0
파일: tests.py 프로젝트: hspandher/my_shine
    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()

        self.work_experience = WorkExperience(
            candidate = self.candidate,
            is_experienced = True,
            years_of_experience = 3,
            months_of_experience = 10)

        self.work_experience.save()

        self.education_qualifications = EducationQualifications(
            candidate = self.candidate,
            highest_qualification = '10+2',
            education_specialization = 'Non-Medical',
            institute_name = 'CBSE')

        self.education_qualifications.save()
        self.url = '/login/'
        self.response = login(HttpRequest())

        self.form_details = {
            'email': '*****@*****.**',
            'password': '******'
        }
예제 #7
0
파일: tests.py 프로젝트: hspandher/my_shine
class WorkExperienceModelTest(ModelTestMethodsMixin, TestCase):

    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()

        self.work_experience = WorkExperience(
            candidate = self.candidate,
            is_experienced = True,
            years_of_experience = 3,
            months_of_experience = 10)

    def is_work_experience_valid(self):
        return self.is_valid('work_experience')

    def has_appropriate_validation(self, attribute_name, invalid_attributes):
        self.verify_all_validations('work_experience', attribute_name, invalid_attributes)

    def test_work_experience_belongs_to_valid_candidate(self):
        Candidate.objects.get(email = self.work_experience.candidate.email).delete()
        self.assertFalse(self.is_work_experience_valid(), 'Work Experience Candidate does not exist in the database')

    def test_work_experience_rejects_invalid_years_of_experience(self):
        invalid_years = [342, -10, -4, 100, 1700, -1, 99]
        self.has_appropriate_validation('years_of_experience', invalid_years)

    def test_work_experience_rejects_invalid_months_of_experience(self):
        invalid_months = [-2, 13, -1, 234]
        self.has_appropriate_validation('months_of_experience', invalid_months)

    def test_work_experience_rejects_invalid_is_experienced_value(self):
        invalid_is_experienced_values = [32, '2', 'yes', 4]
        self.has_appropriate_validation('is_experienced', invalid_is_experienced_values)
예제 #8
0
파일: tests.py 프로젝트: hspandher/my_shine
 def setUp(self):
     self.candidate = Candidate(
         email = '*****@*****.**',
         first_name = 'Hakampreet Singh',
         last_name = 'Pandher',
         country = 'India',
         city = 'Ludhiana',
         gender = 'M',
         password = '******',
         mobile_number = '9738472222')
     self.candidate.save()
     self.url = "/candidate/{id}/add-qualifications/".format(id = self.candidate.id)
     self.response = add_qualifications(HttpRequest(), self.candidate.id)
     self.form_details = {
         'highest_qualification': '10+2',
         'education_specialization': 'Non-Medical',
         'institute_name': 'Anything'
     }
예제 #9
0
파일: tests.py 프로젝트: hspandher/my_shine
    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()

        self.work_experience = WorkExperience(
            candidate = self.candidate,
            is_experienced = True,
            years_of_experience = 3,
            months_of_experience = 10)
예제 #10
0
파일: tests.py 프로젝트: hspandher/my_shine
    def setUp(self):
        self.candidate = Candidate(
            email = '*****@*****.**',
            first_name = 'Hakampreet Singh',
            last_name = 'Pandher',
            country = 'India',
            city = 'Ludhiana',
            gender = 'M',
            password = '******',
            mobile_number = '9738472222')

        self.candidate.save()
        self.url = "/candidate/{id}/add-work-experience/".format(id = self.candidate.id)
        self.response = add_work_experience(HttpRequest(), self.candidate.id)
        self.form_details = {
            'is_experienced': True,
            'years_of_experience': 4,
            'months_of_experience': 5
        }