Ejemplo n.º 1
0
    def test_get_external_id_returns_username(self):
        u = create_user(username="******", password="******")
        request = test.RequestFactory().get("/")
        request.user = u

        view = views.ZendeskAuthorize(request=request)
        self.assertEqual(u.get_username(), view.get_external_id())
Ejemplo n.º 2
0
    def test_mezzanine_form(self):
        page = Form.objects.create(slug='my-form')
        page.save()

        field = Field.objects.create(form=page, field_type=3, required=False)
        field.save()

        page_middleware = PageMiddleware()

        request = test.RequestFactory().post(
            '/my-form', data={'field_1': '*****@*****.**'})
        request.user = User.objects.get_or_create(pk=1)[0]

        SessionMiddleware().process_request(request)
        request.session.save()

        self.assertEqual(
            len(mail.outbox),
            0,
        )

        page_middleware.process_view(request, mezzanine_page_view, {}, {})
        self.assertEqual(len(mail.outbox), 1)
        self.assertNotIn('access your downloads', mail.outbox[0].body)

        download = Download.objects.create()
        download.forms.add(page)
        download.save()

        page_middleware.process_view(request, mezzanine_page_view, {}, {})
        self.assertEqual(len(mail.outbox), 2)
        self.assertIn('access your downloads', mail.outbox[1].body)
Ejemplo n.º 3
0
 def cookie_request(self, value, **headers):
     fac = test.RequestFactory()
     request = fac.get("/")
     cookies = {}
     request.COOKIES = cookies
     self.sign_cookie(request, value, **headers)
     return request
Ejemplo n.º 4
0
    def test_get_user_name_returns_username_when_no_first_or_last_name(self):
        u = User(username="******")
        request = test.RequestFactory().get("/")
        request.user = u

        view = views.ZendeskAuthorize(request=request)
        self.assertEqual(u.get_username(), view.get_user_name())
Ejemplo n.º 5
0
    def test_get_email_returns_user_email(self):
        u = create_user(username="******", email="*****@*****.**")
        request = test.RequestFactory().get("/")
        request.user = u

        view = views.ZendeskAuthorize(request=request)
        self.assertEqual(u.email, view.get_email())
Ejemplo n.º 6
0
    def test_get_user_name_returns_full_name_when_present(self):
        u = User(first_name=" Joe", last_name="Tester ")
        request = test.RequestFactory().get("/")
        request.user = u

        view = views.ZendeskAuthorize(request=request)
        self.assertEqual("Joe Tester", view.get_user_name())
Ejemplo n.º 7
0
    def test_get_timestamp_returns_empty_string_when_not_in_get_parameter(
            self):
        request = test.RequestFactory().get("/", {})
        view = views.ZendeskAuthorize(request=request)

        timestamp = view.get_timestamp()
        self.assertEqual(u'', timestamp)
Ejemplo n.º 8
0
    def test_vary_xmobile(self):
        request = test.RequestFactory().get('/')
        request.NO_MOBILE = True
        response = http.HttpResponse()

        r = middleware.XMobileMiddleware().process_response(request, response)
        self.assertEqual(response.get('Vary', None), None)
Ejemplo n.º 9
0
 def test_vary(self):
     request = test.RequestFactory().get('/')
     response = http.HttpResponse()
     r = middleware.DetectMobileMiddleware().process_response(
         request, response)
     assert r is response
     self.assertEqual(response['Vary'], 'User-Agent')
Ejemplo n.º 10
0
    def setUp(self):
        self.factory = test.RequestFactory()
        from django.contrib.sessions.backends.file import SessionStore

        store = SessionStore()
        store.save()
        self.session = store
Ejemplo n.º 11
0
    def test_send_mail_sets_request_on_instance(self, get_message_dict,
                                                *mocks):
        mock_request = test.RequestFactory().get('/')
        get_message_dict.return_value = {"to": ["*****@*****.**"]}

        form = forms.BaseEmailFormMixin()
        form.send_email(mock_request)
        self.assertEqual(mock_request, form.request)
Ejemplo n.º 12
0
    def test_unknown_attribute_not_rendered(self):
        request = test.RequestFactory().get("/")
        self.assertEqual(
            str(meta_tags([], request=request, unknown="Stuff")),
            """\
<meta property="og:type" content="website">
  <meta property="og:url" content="http://testserver/">""",
        )
Ejemplo n.º 13
0
 def test_get(self):
     fac = test.RequestFactory()
     request = fac.get("/")
     response = views.stage(request)
     self.assertEqual(response.status_code, 401)
     form = response.context_data['form']
     self.assertIsInstance(form, StagingForm)
     self.assertFalse(form.is_bound)
Ejemplo n.º 14
0
 def test_post_invalid_host(self):
     fac = test.RequestFactory()
     request = fac.post("/",
                        data={'secret': 'password'},
                        HTTP_HOST="potato.com")
     request.COOKIES = {}
     response = views.stage(request)
     self.assertEqual(response.status_code, 401)
     self.assertNotIn(conf.get("SESSION_KEY"), response.cookies)
Ejemplo n.º 15
0
 def test_get_request(self):
     payload = {'name': 'Zail Singh'}
     factory = test.RequestFactory()
     req = factory.get("/", data={}, content_type='application/json')
     req.user = AnonymousUser()
     view = self.create_view(get=lambda _: payload)
     resp = view(req)
     resp.json = json.loads(resp.content)
     self.assertEqual(resp.json, payload)
Ejemplo n.º 16
0
 def setUp(self):
     self.request = test.RequestFactory().get('/fake-path')
     self.view = setup_view(CustomerCreate(), self.request)
     comp = Company.objects.create(name='test')
     user = User.objects.create(email='*****@*****.**', company=comp)
     object_ = Customer.objects.create(first_name="test",
                                       last_name="test",
                                       user=user)
     setattr(self.view, 'object', object_)
Ejemplo n.º 17
0
    def setUp(self):
        # Must post some data or the form will not be bound.
        self.request = test.RequestFactory().post('/', data={'not': 'None'})

        SessionMiddleware().process_request(self.request)
        self.request.session.save()

        self.page = Form.objects.create()
        self.page.save()
Ejemplo n.º 18
0
    def setUp(self):
        super(IntegrationTestMixin, self).setUp()

        self.request_factory = test.RequestFactory()
        self.login_page_url = reverse('signin_user')
        self.register_page_url = reverse('register_user')
        patcher = testutil.patch_mako_templates()
        patcher.start()
        self.addCleanup(patcher.stop)
 def test_if_exception_is_raised_for_redirect_loop(self):
     factories.UrlMappingFactory(
         source_url='/a/',
         target_url='/a/',
     )
     request = test.RequestFactory().get('/a/')
     resolver = views.UrlResolver(request)
     with self.assertRaises(views.InvalidRedirect):
         list(resolver.map())
Ejemplo n.º 20
0
 def test_broken_index_view_django_2_x(self):
     '''
     Test the index view functionality with a broken view.
     In Django 2.0, NoReverseMatch exception is no longer silenced.
     '''
     self.create_urlconf([], index_view='does-not-exist')
     view = resolve('/', urlconf=self).func
     with self.assertRaises(urlresolvers.NoReverseMatch):
         view(test.RequestFactory().get(path='/'))
Ejemplo n.º 21
0
 def create_request(self, method, payload):
     factory = test.RequestFactory()
     kwargs = {}
     if payload is not None:
         content = json.dumps(payload)
         kwargs['content_type'] = 'application/json'
         kwargs['data'] = content
     request = getattr(factory, method)("/", **kwargs)
     request.user = AnonymousUser()
     return request
Ejemplo n.º 22
0
    def setUpClass(cls):
        cls.request = test.RequestFactory().get('/')
        SessionMiddleware().process_request(cls.request)
        cls.request.session.save()
        setattr(cls.request, '_messages', FallbackStorage(cls.request))

        cls.product = Product.objects.create()
        cls.product.save()

        super(DownloadViewTests, cls).setUpClass()
    def setUp(self):
        self.owner = User.objects.create(username='******')
        self.non_owner = User.objects.create(username='******')
        self.item = Item.objects.create(name='secure item', owner=self.owner)
        self.request = test.RequestFactory().get('/')
        self.autocomplete = SecureAutocomplete(request=self.request)
        self.form = SecureForm({'item': self.item.pk})

        # Enable security switch
        self.form.fields['item'].request = self.request
Ejemplo n.º 24
0
    def test_sends_mail_with_message_dict(self, get_message_dict, email_class):
        mock_request = test.RequestFactory().get('/')
        get_message_dict.return_value = {"to": ["*****@*****.**"]}

        form = forms.BaseEmailFormMixin()
        result = form.send_email(mock_request)

        email_class.assert_called_once_with(**get_message_dict.return_value)
        email_class.return_value.send.assert_called_once_with(
            fail_silently=False)
        self.assertEqual(email_class.return_value.send.return_value, result)
Ejemplo n.º 25
0
    def test_get_context_returns_cleaned_data_with_request_when_form_is_valid(
            self):
        request = test.RequestFactory().post("/")

        class TestForm(forms.BaseEmailFormMixin, forms.forms.Form):
            name = forms.forms.CharField()

        form = TestForm(data={'name': 'test'})
        form.request = request
        self.assertEqual(dict(name='test', request=request),
                         form.get_context())
Ejemplo n.º 26
0
    def test_generate_hash_creates_pipe_delimited_hash_from_values(self):
        # functional test... testing default behavior.
        u = User(first_name=" Joe", last_name="Tester ", email="*****@*****.**", username="******")
        request = test.RequestFactory().get("/", {'timestamp': 500})
        request.user = u

        hash_string = "{user_name}|{email}|{external_id}||||{token}|{timestamp}".format(
            user_name="Joe Tester", email=u.email, external_id=u.get_username(), token=settings.ZENDESK_TOKEN, timestamp=u'500')
        expected_hash = md5(hash_string).hexdigest()

        view = views.ZendeskAuthorize(request=request)
        self.assertEqual(expected_hash, view.generate_hash())
Ejemplo n.º 27
0
    def setUp(self):
        self.request = test.RequestFactory().get('/')
        self.request.cart = Cart.objects.create()
        SessionMiddleware().process_request(self.request)
        self.request.session.save()

        digital_product_variation = ProductVariation.objects.create(
            sku=self.sku, product=self.product)
        digital_product_variation.option1 = 'Download Only'
        digital_product_variation.save()

        self.request.cart.add_item(digital_product_variation, 5)
Ejemplo n.º 28
0
 def test_bad_request(self):
     """
     Content of the body should be valid json
     """
     factory = test.RequestFactory()
     req = factory.post("/", content_type="application/json", data="asdasdasdasdasdasdasd")
     req.user = None
     view = self.create_view(post=lambda _, **kwargs: {'kwargs': kwargs})
     resp = view(req)
     result = json.loads(resp.content)
     self.assertEqual(resp.status_code, 400)
     self.assertEqual(result['type'], 'BadRequest')
Ejemplo n.º 29
0
 def setUp(self):
     self.request = test.RequestFactory().get('/fake-path')
     comp = Company.objects.create(name='test')
     self.user = User.objects.create(email='*****@*****.**', company=comp)
     today = datetime.date.today()
     self.object = FollowUp.objects.create(user=self.user,
                                           subject="Call John",
                                           date=today)
     self.view = setup_view(FollowUpUpdate(),
                            self.request,
                            pk=self.object.pk)
     setattr(self.view, 'object', self.object)
Ejemplo n.º 30
0
    def test_send_mail_sets_request_on_instance(self, get_message_dict,
                                                *mocks):
        mock_request = test.RequestFactory().get('/')
        get_message_dict.return_value = {
            "recipient_list": ["*****@*****.**"],
            "from_email": '*****@*****.**',
            "context": {}
        }

        form = forms.BaseEmailFormMixin()
        form.send_email(mock_request)
        self.assertEqual(mock_request, form.request)