Ejemplo n.º 1
0
class CommentTestCase(VLiveTestCase):

    fixtures = [
        'vlive/tests/auth/fixtures/sample.json',
        'vlive/tests/article/fixtures/sample.json',
    ]

    def setUp(self):
        self.article = Article.published_objects.latest()
        self.article_url = reverse('article_detail', kwargs={
            'pk': self.article.pk,
        })

        self.msisdn = '27123456789'
        self.pin = '1234'
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)
        self.client.login(remote_user=self.msisdn)

    def place_comment(self, obj, **kwargs):
        params = params_for_comments(obj)
        params.update(kwargs)
        resp = self.client.post(reverse('comments-post-comment'),
            params)
        self.assertVLiveRedirects(resp, reverse('article_detail',
                                                args=[self.article.pk]))
        return UserComment.objects.latest('submit_date')

    def test_comment_paging(self):
        """Test pagination for comments"""
        for i in range(0, 20):
            self.place_comment(self.article, comment='hello world %s' % i,
            next=self.article_url)

        resp = self.client.get(reverse('article_detail_redo',
                                        args=[self.article.pk]))

        self.assertContains(resp, '20 comments')
        self.assertContains(resp, 'Next')
Ejemplo n.º 2
0
class ProfileTestCase(VLiveTestCase):
    fixtures = [
        'vlive/tests/auth/fixtures/sample.json',
        'fixtures/skills.json',
    ]

    def setUp(self):
        cleandb()

        self.msisdn = '27123456789'
        self.pin = '1234'
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)
        settings.CELERY_ALWAYS_EAGER = True

    def tearDown(self):
        cleandb()
        settings.CELERY_ALWAYS_EAGER = settings.DEBUG

    def test_own_profile_page(self):
        self.login()
        self.fill_in_basic_info()

        resp = self.client.get(reverse('profile'))
        self.assertEquals(resp.status_code, 200)

        self.assertContains(resp, 'Test User')
        self.assertContains(resp, 'Full Profile')

        user = User.objects.get(username=self.msisdn)
        resp = self.client.get(reverse('profile_view', args=[user.pk]))
        self.assertEquals(resp.status_code, 200)

        self.assertContains(resp, 'Test User')

    def test_add_connection(self):
        other_msisdn = '27121111111'
        self.login()
        self.fill_in_basic_info()

        user = User.objects.get(username=other_msisdn)
        user2 = User.objects.get(username='******')

        profile = user.get_profile()
        profile.first_name = 'Joe'
        profile.surname = 'Blog'
        profile.save()

        resp = self.client.get(reverse('profile_view', args=[user.pk]))
        self.assertContains(resp, 'Joe Blog')
        self.assertNotContains(resp, 'Contact Info')

        resp = self.client.get(reverse('add_connection', args=[user.pk]))
        self.assertContains(resp, 'Joe Blog')

        resp = self.client.post(reverse('add_connection', args=[user.pk]))
        self.assertVLiveRedirects(resp, reverse('profile'))

        resp = self.client.get(reverse('profile_view', args=[user.pk]))
        self.assertContains(resp, 'request pending')

        resp = self.client.post(reverse('add_connection', args=[user2.pk]))
        self.assertVLiveRedirects(resp, reverse('profile'))

        resp = self.client.get(reverse('profile_view', args=[user2.pk]))
        self.assertContains(resp, 'request pending')

        self.logout()

        user = User.objects.get(username=self.msisdn)

        #User 2
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=other_msisdn)
        self.msisdn = other_msisdn
        self.login()
        resp = self.client.get(reverse('my_connections'))
        self.assertContains(resp, 'Connection Requests (1)')

        user = User.objects.get(username='******')

        resp = self.client.get(reverse('confirm_request', args=[user.pk]))
        self.assertContains(resp, 'Test User')

        resp = self.client.post(reverse('confirm_request', args=[user.pk]))
        self.assertVLiveRedirects(resp, reverse('profile'))

        resp = self.client.get(reverse('my_connections'))
        self.assertContains(resp, 'My Connections (1)')

        self.logout()

        #User 1
        self.login()

        resp = self.client.get(reverse('my_connections'))
        self.assertContains(resp, 'My Connections (1)')

        resp = self.client.get(reverse('profile_view', args=[user.pk]))
        self.assertNotContains(resp, 'Full Profile')

        self.logout()

        #User 3
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID='27122222222')
        self.msisdn = '27122222222'
        self.login()

        resp = self.client.post(reverse('reject_request', args=[user.pk]))
        self.logout()

        #User 1

        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID='27123456789')
        self.msisdn = '27123456789'
        self.login()

        resp = self.client.get(reverse('my_connections'))
        self.assertContains(resp, 'My Connections (1)')

        resp = self.client.get(reverse('profile_view', args=[user2.pk]))
        self.assertNotContains(resp, 'request pending')

        self.logout()

        #User 3
        self.login()

        resp = self.client.get(reverse('connections', args=[4]))
        self.assertContains(resp, 'Test User')

    def test_add_connection_by_industry(self):
        self.login()
        self.fill_in_basic_info()

        user = User.objects.get(username='******')
        user2 = User.objects.get(username='******')

        profile = user.get_profile()
        profile.first_name = 'Joe'
        profile.surname = 'Blog'
        profile.province = 2
        profile.save()

        profile = user2.get_profile()
        profile.first_name = 'Jane'
        profile.surname = 'Doe'
        profile.province = 1
        profile.save()

        resp = self.client.get(reverse('add_connection_by_industry'))
        self.assertContains(resp, 'Accounts/Financial')
        self.assertContains(resp, 'Gauteng')

        resp = self.client.post(reverse('add_connection_by_industry_result',\
                                    args=[0, 1]))
        self.assertContains(resp, 'Jane Doe')
        self.assertNotContains(resp, 'Joe Blog')

    def test_add_connection_by_name(self):
        self.login()
        self.fill_in_basic_info()

        user = User.objects.get(username='******')
        user2 = User.objects.get(username='******')

        profile = user.get_profile()
        profile.first_name = 'Joe'
        profile.surname = 'Blog'
        profile.province = 2
        profile.save()

        profile = user2.get_profile()
        profile.first_name = 'Jane'
        profile.surname = 'Doe'
        profile.province = 1
        profile.save()

        resp = self.client.get(reverse('add_connection_by_first_name'))
        self.assertContains(resp, 'Gauteng')

        resp = self.client.post(reverse('add_connection_by_first_name'),\
                                    {'name': 'joe', 'province': 1})
        self.assertVLiveRedirects(resp,
                                    reverse('add_connection_by_first_name_result',\
                                        args=[1]))

        resp = self.client.post(reverse('add_connection_by_first_name_result',
                                    args=[1]),\
                                {'name': 'jane'})
        self.assertContains(resp, 'Jane Doe')
        self.assertNotContains(resp, 'Joe Blog')

        resp = self.client.post(reverse('add_connection_by_surname_result',
                                    args=[0]),\
                                {'name': 'blog'})
        self.assertNotContains(resp, 'Jane Doe')
        self.assertContains(resp, 'Joe Blog')

    def test_skills_views(self):
        self.login()
        self.fill_in_basic_info()

        resp = self.client.get(reverse('skills_new'))
        self.assertContains(resp, 'Accounts/Financial')

        #Add New
        resp = self.client.get(reverse('skills_new', args=[1]))
        self.assertContains(resp, 'Accounts/Financial')

        post_data = {
            'skill': 'Accounts/Financial',
            'level': 0,
        }

        resp = self.client.post(reverse('skills_new', args=[1]), post_data)
        resp = self.client.get(reverse('skills'))
        self.assertContains(resp,  'Accounts/Financial')
        self.assertContains(resp,  '(Laaitie)')

        #Mark as primary
        resp = self.client.get(reverse('skills_primary', args=[1]))
        resp = self.client.get(reverse('skills'))
        self.assertContains(resp, '*Accounts/Financial')

        #skills editing
        resp = self.client.get(reverse('skills', args=[1]))
        self.assertContains(resp, 'Accounts/Financial')

        post_data = {
            'level': 2,
            'skill': 'Accounts/Financial',
        }

        resp = self.client.post(reverse('skills', args=[1]), post_data)
        resp = self.client.get(reverse('skills'))
        self.assertContains(resp,  'Accounts/Financial')
        self.assertContains(resp,  '(Junior)')

        #Test Delete
        resp = self.client.get(reverse('skills_new', args=[2]))
        self.assertContains(resp,  'Admin/Clerical')

        post_data = {
            'level': 20,
            'skill': 'Admin/Clerical',
        }

        resp = self.client.post(reverse('skills_new', args=[2]), post_data)
        resp = self.client.get(reverse('skills'))
        self.assertContains(resp,  'Admin/Clerical')
        self.assertContains(resp,  '(Bozza)')

        resp = self.client.get(reverse('skills_delete', args=[1]))
        self.assertEquals(resp.status_code, 200)

        resp = self.client.post(reverse('skills_delete', args=[1]), post_data)
        resp = self.client.get(reverse('skills'))
        self.assertNotContains(resp,  'Accounts/Financial')

        #Test duplicate
        resp = self.client.post(reverse('skills_new', args=[2]), post_data)
        self.assertContains(resp,  'already added')
Ejemplo n.º 3
0
class VLiveCVTestCase(VLiveTestCase):
    fixtures = [
        'fixtures/opportunities.provinces.json',
    ]

    def setUp(self):
        self.msisdn = '27123456789'
        self.pin = '1234'
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)
        self.client.login(remote_user=self.msisdn)
        settings.CELERY_ALWAYS_EAGER = True

    def tearDown(self):
        settings.CELERY_ALWAYS_EAGER = settings.DEBUG

    def test_edit_personal_page(self):
        resp = self.client.get(reverse('profile'))
        self.assertEquals(resp.status_code, 200)

        resp = self.client.get(reverse('edit_personal'))
        self.assertEquals(resp.status_code, 200)

        post_data = {
            'first_name': 'Milton',
            'surname': 'Madanda',
            'gender': 'Male',
        }
        # not provided pin yet so it should redirect
        resp = self.client.post(reverse('edit_personal'), post_data)
        self.assertVLiveRedirects(resp, reverse('register'))
        # register pin
        resp = self.register()

        # try again, this time after having set the pin
        resp = self.client.post(reverse('edit_personal'), post_data)
        cv = self.get_user().get_profile()
        self.assertEquals(cv.first_name, 'Milton')
        self.assertEquals(cv.surname, 'Madanda')
        self.assertEquals(cv.gender, 'Male')
        # reload the page and check for new entries in form
        resp = self.client.get(reverse('edit_personal'))
        self.assertContains(resp, 'Milton')
        self.assertContains(resp, 'Madanda')
        self.assertContains(resp, 'Male')
        # logout & login
        resp = self.logout()

        # not provided pin yet so it should redirect to login page
        resp = self.client.post(reverse('edit_personal'), post_data)
        self.assertVLiveRedirects(resp, reverse('login'))

        # FIXME: we shouldn't need to provide the MSISDN here.
        resp = self.login()
        # load the personal details again, ensure they're present
        resp = self.client.get(reverse('edit_personal'))
        self.assertContains(resp, 'Male')
        self.assertContains(resp, 'Milton')
        self.assertContains(resp, 'Madanda')

    def test_edit_contact_details_page(self):
        self.register()
        self.login()

        resp = self.client.get(reverse('profile'))
        self.assertEquals(resp.status_code, 200)

        resp = self.client.get(reverse('edit_contact'))
        self.assertEquals(resp.status_code, 200)

        post_data = {
            'telephone_number': '0123456978',
            'address': 'Oak Rd',
            'city': 'Durban',
            'province': '1',
        }
        resp = self.client.post(reverse('edit_contact'), post_data)

        cv = self.get_user().get_profile()
        self.assertEquals(cv.telephone_number, '0123456978')
        self.assertEquals(cv.address, 'Oak Rd')
        self.assertEquals(cv.city, 'Durban')

    def test_edit_education_details_page(self):

        resp = self.client.get(reverse('profile'))
        self.assertEquals(resp.status_code, 200)
        self.assertVLiveRedirects(resp, reverse('register'))
        self.register()
        self.login()

        resp = self.client.get(reverse('edit_education'))
        self.assertNotVLiveRedirects(resp, reverse('login'))

        post_data = {
            'highest_grade': '12',
            'highest_grade_year': 2005,
            'school': 'Some school'
        }
        resp = self.client.post(reverse('edit_education'), post_data)

        cv = self.get_user().get_profile()
        self.assertEquals(cv.highest_grade, '12')
        self.assertEquals(cv.highest_grade_year, 2005)
        self.assertEquals(cv.school, 'Some school')

    def test_edit_certificates_details_page(self):
        resp = self.client.get(reverse('profile'))
        self.assertVLiveRedirects(resp, reverse('register'))

         # test certificates listing
        resp = self.client.get(reverse('certificate_list'))

         # test certificates add form
        resp = self.client.get(reverse('certificate_new'))
        self.assertVLiveRedirects(resp, reverse('register'))

        self.register()
        self.login()

         # test certificates add action
        post_data = {
            'name': 'BSc',
            'institution': 'UCT',
            'year': 2007,
        }
        resp = self.client.post(reverse('certificate_new'),  post_data)

         # test certificates listing of new certificate
        resp = self.client.get(reverse('certificate_list'))
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'BSc')

         # test editing of created certificate
        resp = self.client.get(reverse('certificate_edit',  args=[1]))
        self.assertEquals(resp.status_code, 200)

        post_data = {
            'name': 'BSc in IT',
            'institution': 'UCT',
            'year': 2007,
        }
        resp = self.client.post(reverse('certificate_edit', args=[1]),
                                post_data)

        resp = self.client.get(reverse('certificate_list'))
        self.assertContains(resp, 'BSc in IT')
        certs = self.get_user().get_profile().certificates.all()
        self.assertEquals(certs.count(), 1)

         # test delete action
        resp = self.client.get(reverse('certificate_delete',  args=[1]))
        self.assertContains(resp, 'Are you sure')

        resp = self.client.post(reverse('certificate_delete',  args=[1]))
        certs = self.get_user().get_profile().certificates.all()
        self.assertEquals(certs.count(), 0)

    def test_edit_work_experiences_details_page(self):

        self.register()
        self.login()

        resp = self.client.get(reverse('profile'))
        self.assertNotVLiveRedirects(resp, reverse('login'))

         # test certificates listing
        resp = self.client.get(reverse('work_experience_list'))
        self.assertNotVLiveRedirects(resp, reverse('login'))

         # test certificates add form
        resp = self.client.get(reverse('workExperience_new'))
        self.assertNotVLiveRedirects(resp, reverse('login'))

         # test certificates add action
        post_data = {
            'title': 'Engineer',
            'company': 'Praekelt',
            'start_year': 2007,
            'end_year': 2008,
        }
        # TODO: fix camel casing
        resp = self.client.post(reverse('workExperience_new'),  post_data)

         # test certificates listing of new certificate
        resp = self.client.get(reverse('work_experience_list'))
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'Praekelt')

         # test editing of created certificate
        resp = self.client.get(reverse('workExperience_edit',  args=[1]))
        self.assertEquals(resp.status_code, 200)

        post_data = {
            'title': 'Engineer',
            'company': 'Praekelt Consulting',
            'start_year': 2007,
            'end_year': 2008,
        }
        resp = self.client.post(reverse('workExperience_edit', args=[1]),
                                post_data)

        resp = self.client.get(reverse('work_experience_list'))
        self.assertContains(resp, 'Praekelt Consulting')

        work_experiences = self.get_user().get_profile().work_experiences.all()
        self.assertEquals(work_experiences.count(), 1)

         # test delete action
        resp = self.client.get(reverse('workExperience_delete',  args=[1]))
        self.assertContains(resp, 'Are you sure')

        resp = self.client.post(reverse('workExperience_delete',  args=[1]))
        work_experiences = self.get_user().get_profile().work_experiences.all()
        self.assertEquals(work_experiences.count(), 0)

    def test_edit_languages_details_page(self):
        self.register()
        self.login()

        resp = self.client.get(reverse('profile'))
        self.assertEquals(resp.status_code, 200)

         # test languages listing
        resp = self.client.get(reverse('language_list'))
        self.assertEquals(resp.status_code, 200)

         # test language add form
        resp = self.client.get(reverse('language_new'))
        self.assertEquals(resp.status_code, 200)

         # test languageadd action
        post_data = {'language': 'English', 'read_write': True}
        resp = self.client.post(reverse('language_new'),  post_data)

         # test listing of new language
        resp = self.client.get(reverse('language_list'))
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'English')

         # test editing of created language
        resp = self.client.get(reverse('language_edit',  args=[1]))
        self.assertEquals(resp.status_code, 200)

        post_data = {'language': 'Afrikaans', 'read_write': True}
        resp = self.client.post(reverse('language_edit', args=[1]),
                                post_data)

        resp = self.client.get(reverse('language_list'))
        self.assertContains(resp, 'Afrikaans')

        languages = self.get_user().get_profile().languages.all()
        self.assertEquals(languages.count(), 1)

         # test delete action
        resp = self.client.get(reverse('language_delete',  args=[1]))
        self.assertContains(resp, 'Are you sure')

        resp = self.client.post(reverse('language_delete',  args=[1]))
        languages = self.get_user().get_profile().languages.all()
        self.assertEquals(languages.count(), 0)

    def test_edit_references_details_page(self):
        self.register()
        self.login()

        resp = self.client.get(reverse('profile'))
        self.assertEquals(resp.status_code, 200)

         # test references listing
        resp = self.client.get(reverse('reference_list'))
        self.assertEquals(resp.status_code, 200)

         # test reference add form
        resp = self.client.get(reverse('reference_new'))
        self.assertEquals(resp.status_code, 200)

         # test reference add action
        post_data = {'fullname': 'Test', 'relationship': 'Manager',
                            'contact_no': '0123456789'}
        resp = self.client.post(reverse('reference_new'),  post_data)

         # test listing of new reference
        resp = self.client.get(reverse('reference_list'))
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'Test')

         # test editing of created reference
        resp = self.client.get(reverse('reference_edit',  args=[1]))
        self.assertEquals(resp.status_code, 200)

        post_data = {'fullname': 'User', 'relationship': 'Manager',
                            'contact_no': '0123456789'}
        resp = self.client.post(reverse('reference_edit', args=[1]),
                                post_data)

        resp = self.client.get(reverse('reference_list'))
        self.assertContains(resp, 'User')

        references = self.get_user().get_profile().references
        self.assertEquals(len(references.all()), 1)

         # test delete action
        resp = self.client.get(reverse('reference_delete',  args=[1]))
        self.assertContains(resp, 'Are you sure')

        resp = self.client.post(reverse('reference_delete',  args=[1]))
        references = self.get_user().get_profile().references
        self.assertEquals(len(references.all()), 0)

    def test_email(self):
        # setup user's first_name and surname
        self.register()
        self.login()
        self.fill_in_basic_info()

        resp = self.client.get(reverse('send'))
        self.assertEquals(resp.status_code, 200)

        post_data = {'send_to': '*****@*****.**', 'send_via': 'email'}
        resp = self.client.post(reverse('send'), post_data)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].attachments), 1)
        self.assertEquals(mail.outbox[0].subject, 'CV for Test User')
        self.assertEqual(mail.outbox[0].bcc[0], '*****@*****.**')
        self.assertEqual(mail.outbox[0].from_email, settings.SEND_FROM_EMAIL_ADDRESS)

    def test_fax(self):
        # setup user's first_name and surname
        self.register()
        self.login()
        self.fill_in_basic_info()

        post_data = {
            'send_to': '+27123456789',
            'send_via': 'fax'
        }
        resp = self.client.post(reverse('send'), post_data)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].to), 1)
        self.assertEqual(mail.outbox[0].to[0], '*****@*****.**')
        self.assertEqual(mail.outbox[0].bcc[0], '*****@*****.**')
        self.assertEqual(mail.outbox[0].from_email, settings.SEND_FROM_FAX_EMAIL_ADDRESS)
        self.assertEqual(len(mail.outbox[0].attachments), 1)
        self.assertEquals(mail.outbox[0].subject, 'CV for Test User')

        self.assertEqual(self.get_user().get_profile().nr_of_faxes_sent,  1)

    def test_missing_fields_when_sending(self):
        # setup user's first_name and surname
        self.register()
        self.login()

        post_data = {'send_to': '*****@*****.**', 'send_via': 'email'}
        resp = self.client.post(reverse('send'), post_data)

        self.assertContains(resp,  'Your CV is incomplete')
        self.assertContains(resp,  'first name')
        self.assertContains(resp,  'gender')

    def test_job_creation(self):
        self.register()
        self.login()

        post_data = {
            'province': '2',
            'category': '6',
            'title': 'Plumber needed',
            'description': 'This is some sample text.',
        }
        resp = self.client.post(reverse('jobs_create'), post_data)
        self.assertEqual(Job.objects.all().count(), 1)

        #test shows in my jobs
        resp = self.client.get(reverse('my_jobs'))
        self.assertContains(resp,  'Plumber needed')

        #test can edit job
        resp = self.client.get(reverse('my_jobs', args=[1]))
        self.assertEquals(resp.status_code, 200)

        post_data = {
            'province': '2',
            'category': '6',
            'title': 'Plumber needed 2',
            'description': 'This is some sample text.',
        }
        resp = self.client.post(reverse('jobs_create'), post_data)
        print resp
        self.assertEqual(Job.objects.all().count(), 2)

        resp = self.client.get(reverse('my_jobs'))
        self.assertContains(resp,  'Plumber needed 2')

        #test duplicate submissions
        resp = self.client.post(reverse('jobs_create'), post_data)
        self.assertEqual(Job.objects.all().count(), 2)

        post_data = {
            'province': '2',
            'category': '0',
            'title': 'Plumber needed',
            'description': 'This is some sample text.',
        }
        resp = self.client.post(reverse('jobs_create'), post_data)
        self.assertContains(resp,  'Please choose a category.')

    def test_cv_is_complete(self):
        # setup user's first_name and surname
        self.register()
        self.login()
        self.fill_in_basic_info()

        cv = self.get_user().get_profile()
        # remove a required field
        cv.telephone_number = None
        cv.save()
        # reload & check to ensure that is the case
        cv = CurriculumVitae.objects.get(pk=cv.pk)
        self.assertTrue(cv.missing_fields())
        self.assertEquals(cv.is_complete,  False)

        post_data = {
            'telephone_number': '0123456978',
            'address': 'Oak Rd',
            'city': 'Durban',
            'province': '1',
        }
        resp = self.client.post(reverse('edit_contact'), post_data)
        cv = self.get_user().get_profile()

        self.assertEquals(cv.is_complete,  True)
Ejemplo n.º 4
0
class JobsTestCase(VLiveTestCase):
    fixtures = [
        'fixtures/opportunities.provinces.json',
    ]

    def setUp(self):
        self.msisdn = '27123456789'
        self.pin = '1234'
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)
        self.client.login(remote_user=self.msisdn)
        settings.CELERY_ALWAYS_EAGER = True

    def tearDown(self):
        settings.CELERY_ALWAYS_EAGER = settings.DEBUG

    def test_job_data_creation(self):
        result = run_jobs_update.delay(MockCategoryParser,  MockJobsParser)
        result.ready()
        result.successful()

        jobs = Job.objects.filter(category=1, province__province=Province.GAUTENG).count()
        self.assertEquals(jobs, 4)
        jobs = Job.objects.filter(province__province=Province.GAUTENG).count()
        self.assertEquals(jobs, 4)
        jobs = Job.objects.all().count()
        self.assertEquals(jobs, 9)

        resp = self.client.get(reverse('jobs_list'))
        self.assertContains(resp, 'Admin/Clerical')

        resp = self.client.get(reverse('jobs', args=[1]))
        self.assertContains(resp, 'Isando Bcom')

        slug = 'accounts-administrator-west-rand-kzn-limpopo-eebcompt-accounts-qualif-mon'
        resp = self.client.get(reverse('job', kwargs={'slug':slug}))
        self.assertContains(resp, 'Accounts Administrator West')

    def test_category_parser(self):
        items = JobsParser(html_str = jobs_test_data.articles_html1).parse()
        self.assertEquals(len(items),  4)

        self.assertRaises(Exception,  CategoryParser(2,  html_str = 'blah',  url = 'blah'))

    def test_job_apply_via_email(self):
        self.register()
        self.login()
        self.fill_in_basic_info()

        # setup test data
        result = run_jobs_update.delay(MockCategoryParser,  MockJobsParser)
        result.ready()
        result.successful()

        # apply via email
        slug = 'accounts-administrator-west-rand-kzn-limpopo-eebcompt-accounts-qualif-mon'
        self.client.post(reverse('opportunity_apply', kwargs={'slug':slug}),
                                        {'send_via':'email',
                                         'send_to':'*****@*****.**'})

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].attachments), 1)
        self.assertEquals(mail.outbox[0].subject, 'CV for Test User')

    def test_job_apply_via_fax(self):
        self.register()
        self.login()
        self.fill_in_basic_info()

        # setup test data
        result = run_jobs_update.delay(MockCategoryParser,  MockJobsParser)
        result.ready()
        result.successful()

        # apply via fax

        resp = self.client.get(reverse('jobs', args=[1]))

        slug = 'accounts-administrator-west-rand-kzn-limpopo-eebcompt-accounts-qualif-mon'
        resp = self.client.post(reverse('opportunity_apply', kwargs={'slug':slug}),
                                        {'send_via':'fax',
                                         'send_to':'+27123456789'})

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].attachments), 1)
        self.assertEquals(mail.outbox[0].subject, 'CV for Test User')
        self.assertEqual(mail.outbox[0].to[0], '*****@*****.**')

        # test special launch special (max 2 faxes per user)
        self.assertEqual(self.get_user().get_profile().nr_of_faxes_sent,  1)

        # negative test case for require send_to
        resp = self.client.post(reverse('opportunity_apply', kwargs={'slug':slug}),
                                        {'send_via':'fax',
                                         'send_to':''})
        self.assertContains(resp,  'Please enter a valid email')
Ejemplo n.º 5
0
class VliveAuthenticationTestCase(VLiveTestCase):

    def setUp(self):
        self.msisdn = '27123456789'
        self.pin = '1234'
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)
        settings.CELERY_ALWAYS_EAGER = True

    def tearDown(self):
        settings.CELERY_ALWAYS_EAGER = settings.DEBUG

    def test_index_page(self):
        self.client.login(username=self.msisdn, password=self.pin)
        resp = self.client.get(reverse('index'))
         #  there shouldn't be a Location header as this would mean a redirect
         #  to a login URL
        self.assertFalse(resp.get('Location', None))
        self.assertEquals(resp.status_code, 200)

    def test_login_view(self):
        resp = self.client.post(reverse('register'), {
            'username': self.msisdn,
            'new_password1': self.pin,
            'new_password2': self.pin,
        })
        self.assertContains(resp, 'Submitted successfully')

        resp = self.client.get(reverse('logout'))
        self.assertContains(resp, 'Submitted successfully')

        resp = self.client.get(reverse('login'), )
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'Enter PIN to sign in.')

        resp = self.client.post(reverse('login'), {
            'username': self.msisdn,
            'password': self.pin,
        })

        self.assertEquals(resp.status_code, 200)  # redirect to index
        self.assertContains(resp, 'Submitted successfully')

        resp = self.client.post(reverse('login'),{
            'password': '******',
        })

        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'Sign in failed')

    def test_basic_registration_flow(self):

        resp = self.client.get(reverse('login'))
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'create a PIN')

        resp = self.client.get(reverse('register'))
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'Create PIN for %s' % (self.msisdn))

        resp = self.client.post(reverse('register'), {
            'username': self.msisdn,
            'new_password1': self.pin,
            'new_password2': self.pin,
        })

        # check that the PIN has been set and that we can now authenticate
        # with the ModelBackend using the msisdn and pin
        user = ModelBackend().authenticate(username=self.msisdn, password=self.pin)
        self.assertEqual(user.username, self.msisdn)
        self.assertEquals(resp.status_code, 200)
        self.assertContains(resp, 'Submitted successfully')
        # ensure the session's pin has been set
        self.assertTrue(self.client.session[settings.UMMELI_PIN_SESSION_KEY])

        #test automatic login
        resp = self.client.get(reverse('profile'))
        self.assertContains(resp, 'My Profile')

        resp = self.client.get(reverse('logout'))
        self.assertContains(resp,  'Submitted successfully')
        # ensure the session's pin has been cleared
        self.assertNotIn(settings.UMMELI_PIN_SESSION_KEY, self.client.session)

        resp = self.client.get(reverse('login'))
        self.assertContains(resp, 'Enter PIN to sign in.')
        self.assertContains(resp, 'Forgot your PIN?')

    def test_registration_invalid_pin(self):
        msisdn = '0123456789'
        password = '******'

        resp = self.client.post(reverse('register'), {
            'username': msisdn,
            'password1': password,
            'password2': 'wrong',
        })
        self.assertContains(resp, 'PIN codes don't match.')

    def test_forgot_pin(self):

        #register user
        resp = self.client.post(reverse('register'),{
            'username': self.msisdn,
            'password1': self.pin,
            'password2': self.pin,
        })

        resp = self.client.get(reverse('forgot'))
        self.assertContains(resp, 'PIN will be sent to %s.' % self.msisdn)

        resp = self.client.post(reverse('forgot'),  {'username':self.msisdn})
        self.assertContains(resp, 'Submitted successfully')

    def test_change_pin(self):
        # register user
        resp = self.client.post(reverse('register'), {
            'username': self.msisdn,
            'new_password1': self.pin,
            'new_password2': self.pin,
        })
        self.assertContains(resp, 'Submitted successfully')

        # authorize with pin
        resp = self.client.post(reverse('login'), {
            'username': self.msisdn,
            'password': self.pin,
        })

        resp = self.client.get(reverse('password_change'))
        self.assertContains(resp, 'Change PIN for %s' % self.msisdn)

        resp = self.client.post(reverse('password_change'),{
            'old_password': self.pin,
           'new_password1': '5678',
           'new_password2': '5678',
        })
        self.assertContains(resp, 'Submitted successfully')

        resp = self.client.post(reverse('login'), {
            'username': self.msisdn,
            'password': '******',
        })

        self.assertContains(resp, 'Submitted successfully')

    def test_phone_number_to_international(self):
        self.assertEquals(phone_number_to_international('0123456789'), '27123456789')
        self.assertEquals(phone_number_to_international('27123456789'), '27123456789')
        self.assertEquals(phone_number_to_international('271234567'), 'invalid no')
        self.assertEquals(phone_number_to_international('01234567'), 'invalid no')
        self.assertEquals(phone_number_to_international('username'), 'invalid no')

    def test_user_deactivated(self):
        self.register()
        user = User.objects.get(username=self.msisdn)
        user.is_active = False
        user.save()

        resp = self.client.post(reverse('login'), {
            'username': self.msisdn,
            'password': self.pin,
        })

        self.assertContains(resp, 'Your account has been deactivated')

        resp = self.client.get(reverse('contactsupport'))
        self.assertEquals(resp.status_code, 200)

        resp = self.client.post(reverse('contactsupport'), {
            'username': self.msisdn,
            'message': 'Im sorry I did this.',
        })

        self.assertEqual(len(mail.outbox), 1)
        self.assertEquals(mail.outbox[0].subject, 'Blocked User: %s' % self.msisdn)
        self.assertEqual(mail.outbox[0].from_email, settings.SEND_FROM_EMAIL_ADDRESS)
        self.assertEqual(mail.outbox[0].to[0], settings.UMMELI_SUPPORT)

        #restore user status
        user.is_active = True
        user.save()