Exemplo n.º 1
0
class WorkExperienceTranslationFormTest(TestCase):
    def setUp(self):
        self.factory = Factory()
        self.user = self.factory.make_user()

    def test_language_field_label(self):
        form = WorkExperienceTranslationForm()
        self.assertEqual(form.fields['language'].label, '')

    def test_unsupported_language_raise_error(self):
        data = {
            'date_start': timezone.now(),
            'position': 'position',
            'company': 'company',
            'location': 'location',
            'language': 'INVALID',
        }
        related_model = self.factory.make_work_experience()
        data['related_model'] = related_model.id

        form = WorkExperienceTranslationForm(data=data)
        self.assertFalse(form.is_valid())
        expected_error = _('Select a valid choice. INVALID is not one of the '
                           'available choices.')

        self.assertIn(expected_error, form.errors['language'])

    def test_override_language_field(self):
        data = {
            'date_start': timezone.now(),
            'position': 'position',
            'company': 'company',
            'location': 'location',
        }

        related_model = self.factory.make_work_experience()
        data['related_model'] = related_model.id

        new_languages = [
            ('en', _('English')),
        ]
        form = WorkExperienceTranslationForm(override_languages=new_languages)

        self.assertListEqual(new_languages,
                             form.fields.get('language').choices)
Exemplo n.º 2
0
class WorkExperienceTranslationUpdateViewTestCase(TestCase):

    credentials = {
        'password': '******',
        'email': '*****@*****.**',
    }

    factory = Factory()
    work_experience_list = []

    def setUp(self):
        self.user = self.factory.make_user(**self.credentials)
        self.work_experience = self.factory.make_work_experience(
            user=self.user)
        self.translation = self.factory.make_work_experience_translation(
            related_model=self.work_experience)
        self._url = reverse('work-experience-translation-update',
                            kwargs={'pk': self.translation.id})

    def _update_translation(self, language='en'):
        post_data = {
            'language': language,
            'position': 'position',
            'company': 'company',
            'location': 'location',
            'contribution': 'some contribution description',
            'keywords': 'keyword1, keyword2',
            'date_start': timezone.now().date(),
            'date_end': timezone.now().date()
        }

        resp = self.client.post(self._url, post_data)
        return resp

    def test_view_with_render_form(self):
        self.client.login(**self.credentials)
        resp = self.client.get(self._url)
        self.assertEqual(200, resp.status_code)
        self.assertEqual(resp.context['form'].initial['company'],
                         self.translation.company)
        self.assertEqual(resp.context['form'].initial['location'],
                         self.translation.location)
        self.assertEqual(resp.context['form'].initial['date_start'],
                         self.work_experience.date_end)

    def test_post_form_with_valid_data(self):
        self.client.login(**self.credentials)

        resp = self._update_translation()

        self.assertEqual(302, resp.status_code)

        self.assertRedirects(
            resp,
            reverse('work-experience-translation-list',
                    args=(self.work_experience.id, )))
Exemplo n.º 3
0
class WorkExperienceCreateTestCase(TestCase):
    credentials = {
        'password': '******',
        'email': '*****@*****.**',
    }

    factory = Factory()
    work_experience_list = []

    def setUp(self):
        self.user = self.factory.make_user(**self.credentials)

    def test_redirect_to_translation_list_on_success(self):
        self.client.login(**self.credentials)
        post_data = {
            'language': 'en',
            'position': 'position',
            'company': 'company',
            'location': 'location',
            'date_start': timezone.now().strftime('%Y-%m-%d'),
            'date_end': timezone.now().strftime('%Y-%m-%d'),
            'contribution': 'some contribution description',
            'keywords': 'keyword1, keyword2',
        }
        resp = self.client.post(reverse('work-experience-add'), post_data)
        self.assertEqual(302, resp.status_code)

        # check the redirect url format looks like:
        # ./resume/work-experience/13/translations/
        self.assertTrue(resp.url.startswith('/resume/work-experience/'))
        self.assertTrue(resp.url.endswith('/translations/'))

    def test_form_invalid_start_date_later_than_end_date(self):
        self.client.login(**self.credentials)
        post_data = {
            'language':
            'en',
            'position':
            'position',
            'company':
            'company',
            'location':
            'location',
            'date_start':
            (timezone.now() + datetime.timedelta(days=5)).strftime('%Y-%m-%d'),
            'date_end':
            timezone.now().strftime('%Y-%m-%d'),
        }
        resp = self.client.post(reverse('work-experience-add'), post_data)
        self.assertEqual(200, resp.status_code)
        self.assertFormError(
            resp, 'form', 'date_end',
            'End date should not be earlier than start date!')
Exemplo n.º 4
0
class GoogleTagManagerSetupTestCase(TestCase):
    factory = Factory()

    def test_analytic_setup_context(self):
        with self.settings(GOOGLE_TAG_MANAGER_ID='test_id'):
            request = self.factory.make_request()
            context = context_processors.google_tag_manager_setup(request)
            self.assertEqual(context, {'google_tag_manager_id': 'test_id'})

    def test_analytic_setup_context_without_config(self):
        with self.settings(GOOGLE_TAG_MANAGER_ID=None):
            request = self.factory.make_request()
            context = context_processors.google_tag_manager_setup(request)
            self.assertEqual(context, {'google_tag_manager_id': None})
Exemplo n.º 5
0
class WorkExperienceTranslationListTestCase(TestCase):
    credentials = {
        'password': '******',
        'email': '*****@*****.**',
    }

    factory = Factory()
    work_experience_list = []

    def setUp(self):
        user = self.factory.make_user(**self.credentials)
        subfix = ['a', 'b', 'c', 'd']
        for i in range(4):
            work_experience = self.factory.make_work_experience(user=user)
            self.factory.make_work_experience_translation(
                language='en',
                position='position-{}'.format(subfix[i]),
                company='company-{}'.format(subfix[i]),
                location='location-{}'.format(subfix[i]),
                user=user,
                related_model=work_experience)
            self.work_experience_list.append(work_experience.id)

    def _login(self):
        self.client.login(**self.credentials)

    def test_view_show_translations_under_work_experience(self):
        self._login()
        work_experience_id = self.work_experience_list[0]
        resp = self.client.get(
            reverse('work-experience-translation-list',
                    args=(work_experience_id, )))
        self.assertEqual(200, resp.status_code)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.context['work_experience'].id,
                         work_experience_id)
        self.assertEqual(resp.context['work_experience'].company, 'company-a')
        self.assertEqual(resp.context['work_experience'].location,
                         'location-a')

    def test_view_when_invalid_work_experience_id_passed(self):
        self._login()
        invalid_id = 99999
        resp = self.client.get(
            reverse('work-experience-translation-list', args=(invalid_id, )))
        self.assertEqual(200, resp.status_code)
        self.assertEqual(resp.context['error'],
                         'The related work experience do not exist!')
Exemplo n.º 6
0
class WorkExperienceMixin(TestCase):
    credentials = {
        'email': '*****@*****.**',
        'password': '******',
    }

    factory = Factory()
    element_number = 12

    def setUp(self):
        self.user = self.factory.make_user(**self.credentials)
        for i in range(self.element_number):
            work_experience = self.factory.make_work_experience(user=self.user)
            self.factory.make_multi_work_experience_translations(
                user=self.user, work_experience=work_experience)

    def _login(self):
        self.client.login(**self.credentials)
Exemplo n.º 7
0
class WorkExperienceDeleteViewTestCase(WorkExperienceMixin):
    factory = Factory()

    def setUp(self):
        self.user = self.factory.make_user(**self.credentials)
        for i in range(6):
            work_experience = self.factory.make_work_experience(user=self.user)
            self.factory.make_multi_work_experience_translations(
                user=self.user, work_experience=work_experience)

        self.experience = WorkExperience.objects.filter(user=self.user).first()
        self.experience_id = self.experience.id

    def test_it_should_redirect_to_signin_without_auth(self):  # noqa
        _url = reverse('work-experience-delete', args=(self.experience_id, ))
        resp = self.client.get(_url)
        expected_url = '/signin?next=/resume/work-experience/{}/delete/'.format(
            self.experience_id)
        self.assertRedirects(resp, expected_url)

    def test_delete_experience_with_auth(self):  # noqa
        self._login()
        _url = reverse('work-experience-delete', args=(self.experience_id, ))
        resp = self.client.get(_url)
        self.assertTemplateUsed(resp, 'confirm_delete.html')
        self.assertEqual(resp.context['object'], self.experience)

        to_be_deleted_translations = self.experience.translations.all()
        self.assertEqual(list(resp.context['delete_object_list']),
                         list(to_be_deleted_translations))

        resp = self.client.post(_url)
        self.assertEqual(resp.status_code, 302)
        self.assertRedirects(resp, reverse('work-experience-list'))

        # we created 6 object with factory method, delete one by DeleteView,
        # after we redirect to the list page, we should have 5 ones
        resp = self.client.get(reverse('work-experience-list'))
        self.assertEqual(len(resp.context['work_experience_list']), 5)
Exemplo n.º 8
0
 def setUp(self):
     self.factory = Factory()
     self.user = self.factory.make_user()
Exemplo n.º 9
0
class WorkExperienceTranslationCreateViewTestCase(TestCase):

    credentials = {
        'password': '******',
        'email': '*****@*****.**',
    }

    factory = Factory()
    work_experience_list = []

    def setUp(self):
        self.user = self.factory.make_user(**self.credentials)
        self.work_experience = self.factory.make_work_experience(
            user=self.user)
        self._url = reverse(
            'work-experience-translation-new',
            kwargs={'work_experience_id': self.work_experience.id})

    def test_dispaly_view_with_valid_work_experience_id(self):
        self.client.login(**self.credentials)
        resp = self.client.get(self._url)
        self.assertEqual(resp.status_code, 200)

    def test_redirect_to_trans_list_view_when_pass_invalid_work_experience_id(
            self):
        invalid_id = 999
        self.client.login(**self.credentials)
        resp = self.client.get(
            reverse('work-experience-translation-new',
                    kwargs={'work_experience_id': invalid_id}))
        self.assertEqual(resp.status_code, 302)
        self.assertRedirects(resp, reverse('work-experience-add'))

    def _create_translation(self, language='en'):
        post_data = dict({
            'language': language,
            'position': 'position',
            'company': 'company',
            'location': 'location',
            'contribution': 'some contribution description',
            'keywords': 'keyword1, keyword2',
        })

        # get the date info from the related model
        post_data['date_start'] = self.work_experience.date_start
        post_data['date_end'] = self.work_experience.date_end

        resp = self.client.post(self._url, post_data)
        return resp

    def test_post_form_with_valid_data(self):
        self.client.login(**self.credentials)

        resp = self._create_translation('en')

        self.assertEqual(302, resp.status_code)
        self.assertRedirects(
            resp,
            reverse('work-experience-translation-list',
                    args=(self.work_experience.id, )))

    def test_check_language_selection_option_update_based_on_existing_lang(
            self):
        self.client.login(**self.credentials)

        self._create_translation(language='en')

        resp = self.client.get(self._url)
        self.assertEqual(resp.context['form'].fields['language'].choices,
                         [('zh-hans', 'Chinese')])