Exemple #1
0
    def test_reporting_on_training(self):
        self.login()
        self.fill_in_basic_info()

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

        t = Training.objects.create(title='Test op 1',
                                    description='This is a test',
                                    owner=user)
        kwargs = {'slug': t.slug,
                  'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)

        #test duplicate votes
        self.client.get(reverse('report_object', kwargs=kwargs))
        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)

        #test vote by other user
        self.logout()
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID='27121111111',
                                  HTTP_REFERER='/')
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 2)
Exemple #2
0
    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
Exemple #3
0
class VLiveIndexTestCase(VLiveTestCase):
    fixtures = [
        'vlive/tests/yourwords/fixtures/sample.json',
        'vlive/tests/auth/fixtures/sample.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)

    def test_index_page(self):
        c = Command()
        c.publish()
        
        resp = self.client.get(reverse('index'))
        self.assertContains(resp, 'Another competition')
        self.assertContains(resp, 'Where are you')
Exemple #4
0
    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)
Exemple #5
0
class CommunityTestCase(VLiveTestCase):

    fixtures = [
        'vlive/tests/auth/fixtures/sample.json',
        'vlive/tests/article/fixtures/sample.json',
        '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)

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

        user = User.objects.get(username=self.msisdn)
        j = Job.objects.create(title='Test community job',
                               owner=user,
                               is_community=True,
                               state='published')
        j.save()
        i = StatusUpdate.objects.create(title='Test status update',
                                        owner=user,
                                        is_community=True,
                                        state='published')
        b = Bursary.objects.create(title='Test Bursary',
                                   owner=user,
                                   is_community=True,
                                   state='published')
        b.save()

        self.assertEqual(user.modelbase_set.filter(slug=i.slug).count(), 1)
        self.assertEqual(user.modelbase_set.get(slug=i.slug).ummeliopportunity.statusupdate.title, 'Test status update')
        self.assertEqual(user.modelbase_set.get(slug=b.slug).ummeliopportunity.bursary.title, 'Test Bursary')

        resp = self.client.get(reverse('community_jobs'))
        self.assertContains(resp, 'Test community job')
        self.assertContains(resp, 'Test status update')
        self.assertContains(resp, 'Test Bursary')
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')
Exemple #7
0
class ArticlesTestCase(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 test_commenting_open(self):
        """Test closing comments"""
        pk = self.article.pk
        resp = self.client.get(reverse('article_detail_redo', args=[pk]))
        self.assertNotContains(resp, 'Comments are closed')

        disable_commenting()

        resp = self.client.get(reverse('article_detail_redo', args=[pk]))
        self.assertContains(resp, 'Comments are closed')

        enable_commenting()

        resp = self.client.get(reverse('article_detail_redo', args=[pk]))
        self.assertNotContains(resp, 'Comments are closed')

        enable_commenting()

        resp = self.client.get(reverse('article_detail_redo', args=[pk]))
        self.assertNotContains(resp, 'Comments are closed')
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()
Exemple #9
0
 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)
Exemple #10
0
class OpportunitiesTest(VLiveTestCase):
    fixtures = [
        "vlive/tests/auth/fixtures/sample.json",
        "fixtures/opportunities.provinces.json",
        "opportunities/fixtures/test.opportunities.json",
    ]

    def setUp(self):
        self.msisdn = "27123456789"
        self.pin = "1234"
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)

    def test_province_from_str(self):
        p = Province.from_str("Gauteng")
        self.assertEqual(p.get_province_display(), "Gauteng")

        p = Province.from_str("KwaZulu Natal")
        self.assertEqual(p.get_province_display(), "KwaZulu Natal")
        p = Province.from_str("Kwa-Zulu Natal")
        self.assertEqual(p.get_province_display(), "KwaZulu Natal")

        p = Province.from_str("Western Cape")
        self.assertEqual(p.get_province_display(), "Western Cape")

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

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

        salary = Salary(amount=50, frequency=1)
        salary.save()

        i = Internship.objects.create(
            title="Test op", description="This is a test", owner=user, salary=salary, state="published"
        )
        i.province.add(2)
        i.province.add(3)
        i.save()

        self.assertEqual(user.modelbase_set.filter(slug=i.slug).count(), 1)
        self.assertEqual(user.modelbase_set.all()[0].ummeliopportunity.internship.salary.amount, 50)
        self.assertEqual(user.modelbase_set.all()[0].ummeliopportunity.internship.education, 0)
        self.assertEqual(user.modelbase_set.all()[0].ummeliopportunity.internship.province.count(), 2)

        resp = self.client.get(reverse("internships"))
        self.assertContains(resp, "Test op")

        resp = self.client.get(reverse("internship_detail", kwargs={"slug": "test-op"}))
        self.assertContains(resp, "Test op")
        self.assertContains(resp, "This is a test")

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

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

        i = Training.objects.create(title="Test op", description="This is a test", owner=user, cost=300)
        self.assertEqual(user.modelbase_set.filter(slug=i.slug).count(), 1)
        self.assertEqual(user.modelbase_set.all()[0].ummeliopportunity.training.cost, 300)

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

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

        i = Event.objects.create(title="Test op", description="This is a test", owner=user, place="Salt River")
        self.assertEqual(user.modelbase_set.filter(slug=i.slug).count(), 1)
        self.assertEqual(user.modelbase_set.all()[0].event.place, "Salt River")

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

        user = User.objects.get(username=self.msisdn)
        province = Province.objects.get(province=3)
        i = Event.objects.create(
            title="Test op", description="This is a test", owner=user, place="Salt River", state="published"
        )
        i.province.add(province)
        i.save()

        self.assertEqual(user.modelbase_set.filter(slug=i.slug).count(), 1)
        self.assertEqual(user.modelbase_set.all()[0].event.place, "Salt River")

        resp = self.client.get(reverse("events"))
        self.assertContains(resp, "All Provinces (change)")
        self.assertContains(resp, "Location: Salt River")

        resp = self.client.get(reverse("change_province"))
        self.assertEqual(resp.status_code, 200)

        url = "%s?next=/vlive/opportunities/events/" % reverse("change_province", kwargs={"province": 1})
        resp = self.client.get(url)
        self.assertVLiveRedirects(resp, reverse("events"))

        resp = self.client.get(reverse("events"))
        self.assertContains(resp, "Eastern Cape (change)")
        self.assertContains(resp, "0 events")

        url = "%s?next=/vlive/opportunities/events/" % reverse("change_province", kwargs={"province": 3})
        resp = self.client.get(url)
        self.assertVLiveRedirects(resp, reverse("events"))

        resp = self.client.get(reverse("events"))
        self.assertContains(resp, "Gauteng (change)")
        self.assertContains(resp, "Location: Salt River")

    def test_task_checkout(self):
        web_site = Site.objects.get_current()
        c = Campaign.objects.create(title="Campaign1")

        t1 = MicroTask(title="Test1", state="published", campaign=c)
        t1.save()
        t1.sites.add(web_site)

        t2 = MicroTask(title="Test2", users_per_task=0, state="published", campaign=c)
        t2.save()
        t2.sites.add(web_site)

        t3 = MicroTask(title="Test3", users_per_task=2, state="published", campaign=c)
        t3.save()
        t3.sites.add(web_site)

        t4 = MicroTask(title="Test4", users_per_task=2, state="published", campaign=c)
        t4.save()
        t4.sites.add(web_site)

        self.assertEqual(MicroTask.permitted.all().count(), 4)
        self.assertEqual(MicroTask.available.all().count(), 4)

        user = User.objects.get(username=self.msisdn)
        user2 = User.objects.get(username="******")

        # simple case - 1 user per task
        self.assertTrue(t1.is_available())
        result = t1.checkout(user)
        self.assertTrue(result)
        self.assertFalse(t1.is_available())
        self.assertEqual(MicroTask.available.all().count(), 3)

        tc = TaskCheckout.objects.get(user=user)
        self.assertEqual(tc.task, t1)

        # infinite checkouts available
        self.assertTrue(t2.is_available())
        result = t2.checkout(user)
        self.assertTrue(result)
        self.assertTrue(t2.is_available())
        self.assertEqual(MicroTask.available.all().count(), 3)

        # custom - 2 users per task
        self.assertTrue(t3.is_available())
        result = t3.checkout(user)
        self.assertTrue(result)
        self.assertTrue(t3.is_available())
        result = t3.checkout(user2)
        self.assertTrue(result)
        self.assertFalse(t3.is_available())
        self.assertEqual(MicroTask.available.all().count(), 2)

        # negative case - user attempt to checkout a task twice
        self.assertTrue(t4.is_available())
        result = t4.checkout(user)
        self.assertTrue(result)
        self.assertTrue(t4.is_available())
        result = t4.checkout(user)
        self.assertFalse(result)
        self.assertTrue(t4.is_available())

        # test microtask response object
        checkout = TaskCheckout.objects.get(task=t1)
        task_response = TomTomMicroTaskResponse.objects.create(
            task_checkout=checkout, user=user, state=SUBMITTED, task=t1
        )

        self.assertIsNotNone(checkout.microtaskresponse)
        self.assertIsNotNone(checkout.microtaskresponse.tomtommicrotaskresponse)

    def test_task_expiration(self):
        user = User.objects.get(username=self.msisdn)

        web_site = Site.objects.get_current()
        c = Campaign.objects.create(title="Campaign1")

        t1 = MicroTask(title="task1", state="published", campaign=c)
        t1.save()
        t1.sites.add(web_site)

        t2 = MicroTask(title="task2", state="published", campaign=c)
        t2.save()
        t2.sites.add(web_site)

        c.tasks.add(t1)
        c.tasks.add(t2)

        self.assertTrue(t1.is_available())

        d1 = datetime.now() - timedelta(hours=16)
        t1.checkout(user)
        t_checkout = t1.taskcheckout_set.all()[0]
        t_checkout.date = d1
        t_checkout.save()

        MicroTask.expire_tasks()
        self.assertFalse(t1.is_available())

        self.assertTrue(t2.is_available())

        d1 = datetime.now() - timedelta(hours=25)
        t2.checkout(user)
        t_checkout = t2.taskcheckout_set.all()[0]
        t_checkout.date = d1
        t_checkout.save()

        MicroTask.expire_tasks()
        self.assertTrue(t2.is_available())

        self.assertEqual(Campaign.available_tasks().count(), 1)
Exemple #11
0
 def setUp(self):
     self.msisdn = '27123456789'
     self.pin = '1234'
     self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn,
                               HTTP_REFERER='/')
Exemple #12
0
class ReportingTest(VLiveTestCase):
    fixtures = [
        'vlive/tests/auth/fixtures/sample.json',
    ]

    def setUp(self):
        self.msisdn = '27123456789'
        self.pin = '1234'
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn,
                                  HTTP_REFERER='/')

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

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

        t = Training.objects.create(title='Test op 1',
                                    description='This is a test',
                                    owner=user)
        kwargs = {'slug': t.slug,
                  'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)

        #test duplicate votes
        self.client.get(reverse('report_object', kwargs=kwargs))
        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)

        #test vote by other user
        self.logout()
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID='27121111111',
                                  HTTP_REFERER='/')
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 2)

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

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

        t = Training.objects.create(title='Test op 2',
                                    description='This is a test',
                                    owner=user)

        v = Volunteer.objects.create(title='Test Volunteer 2',
                                    description='This is a test Volunteer',
                                    owner=user)

        kwargs = {'slug': t.slug,
                  'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        kwargs = {'slug': v.slug,
                  'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)

        self.assertEquals(helpers.get_object_votes(v, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)

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

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

        t = Training.objects.create(title='Test op 3',
                                    description='This is a test',
                                    owner=user)

        kwargs = {'slug': t.slug,
                  'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        kwargs = {'slug': t.slug,
                  'report_key_field': UmmeliOpportunity.SCAM_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)
        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.SCAM_REPORT_KEY_FIELD), 1)


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

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

        t = Training.objects.create(title='Test op 4',
                                    description='This is a test',
                                    owner=user)

        kwargs = {'slug': t.slug,
                  'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD
        }
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.logout()
        self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID='27121111111',
                                  HTTP_REFERER='/')
        self.client.get(reverse('report_object', kwargs=kwargs))

        self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 2)
Exemple #13
0
    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')
Exemple #14
0
 def setUp(self):
     self.msisdn = "27123456789"
     self.pin = "1234"
     self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID=self.msisdn)
Exemple #15
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')
Exemple #16
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)
Exemple #17
0
 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
Exemple #18
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')