当前位置: 首页>>代码示例>>Python>>正文


Python tools.ok_函数代码示例

本文整理汇总了Python中nose.tools.ok_函数的典型用法代码示例。如果您正苦于以下问题:Python ok_函数的具体用法?Python ok_怎么用?Python ok_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ok_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_http_method_not_allowed_allowed_methods

    def test_http_method_not_allowed_allowed_methods(self):
        class GetPostView(views.JSONView):
            def get(self, request, *args, **kwargs):
                return 'asdf'

            def post(self, request, *args, **kwargs):
                return 'qwer'
        response = GetPostView().http_method_not_allowed()
        ok_(set(['GET', 'POST']).issubset(set(response['Allow'].split(', '))))

        class GetPostPutDeleteHeadView(views.JSONView):
            def get(self, request, *args, **kwargs):
                return 'asdf'

            def post(self, request, *args, **kwargs):
                return 'qwer'

            def put(self, request, *args, **kwargs):
                return 'qwer'

            def delete(self, request, *args, **kwargs):
                return 'qwer'

            def head(self, request, *args, **kwargs):
                return 'qwer'
        response = GetPostPutDeleteHeadView().http_method_not_allowed()
        expected_methods = set(['GET', 'POST', 'PUT', 'DELETE', 'HEAD'])
        actual_methods = set(response['Allow'].split(', '))
        ok_(expected_methods.issubset(actual_methods))
开发者ID:Azeez09,项目名称:remo,代码行数:29,代码来源:test_views.py

示例2: mocked_get

 def mocked_get(url, **options):
     assert '/crash_data/' in url
     ok_('/datatype/processed/' in url)
     return Response("""
     {
       "product": "Firefox",
       "uuid": "7c44ade2-fdeb-4d6c-830a-07d302120525",
       "version": "13.0",
       "build": "20120501201020",
       "ReleaseChannel": "beta",
       "os_name": "Windows NT",
       "date_processed": "2012-05-25 11:35:57",
       "success": true,
       "signature": "CLocalEndpointEnumerator::OnMediaNotific",
       "addons": [
         [
           "[email protected]",
           "1.2.1"
         ],
         [
           "{972ce4c6-7e08-4474-a285-3208198ce6fd}",
           "13.0"
         ]
       ]
     }
     """)
开发者ID:GabiThume,项目名称:socorro-crashstats,代码行数:26,代码来源:test_models.py

示例3: test_current_versions

    def test_current_versions(self, rget):
        model = models.CurrentVersions
        api = model()

        def mocked_get(**options):
            assert '/products/' in options['url']
            return Response("""
                {"hits": {
                   "SeaMonkey": [{
                     "product": "SeaMonkey",
                     "throttle": "100.00",
                     "end_date": "2012-05-10 00:00:00",
                     "start_date": "2012-03-08 00:00:00",
                     "featured": true,
                     "version": "2.1.3pre",
                     "release": "Beta",
                     "id": 922}]
                  },
                  "products": ["SeaMonkey"]
                }
              """)

        rget.side_effect = mocked_get
        info = api.get()
        ok_(isinstance(info, list))
        ok_(isinstance(info[0], dict))
        eq_(info[0]['product'], 'SeaMonkey')
开发者ID:GabiThume,项目名称:socorro-crashstats,代码行数:27,代码来源:test_models.py

示例4: test_rename_file

 def test_rename_file(self):
   paths = ['foo', '%s/bar' % (self.client.root.rstrip('/'), )]
   self.client._create(paths[0], data='hello')
   ok_(self.client._rename(paths[0], destination=paths[1]).json()['boolean'])
   ok_(not self._exists(paths[0]))
   eq_(self.client._open(paths[1].rsplit('/', 1)[1]).content, b'hello')
   self.client._delete(paths[1])
开发者ID:e-heller,项目名称:hdfs,代码行数:7,代码来源:test_client.py

示例5: test_xss_file_attachment_title

    def test_xss_file_attachment_title(self):
        title = '"><img src=x onerror=prompt(navigator.userAgent);>'
        # use view to create new attachment
        file_for_upload = make_test_file()
        post_data = {
            'title': title,
            'description': 'xss',
            'comment': 'xss',
            'file': file_for_upload,
        }
        self.client.login(username='admin', password='testpass')
        resp = self.client.post(reverse('attachments.new_attachment'),
                                data=post_data)
        eq_(302, resp.status_code)

        # now stick it in/on a document
        attachment = Attachment.objects.get(title=title)
        rev = revision(content='<img src="%s" />' % attachment.get_file_url(),
                       save=True)

        # view it and verify markup is escaped
        response = self.client.get(rev.document.get_edit_url())
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_('%s xss' % title,
            doc('#page-attachments-table .attachment-name-cell').text())
        ok_('&gt;&lt;img src=x onerror=prompt(navigator.userAgent);&gt;' in
            doc('#page-attachments-table .attachment-name-cell').html())
开发者ID:anaran,项目名称:kuma,代码行数:28,代码来源:test_templates.py

示例6: test_on_model_change_delete

def test_on_model_change_delete():
    app, db, admin = setup()
    Model1, _ = create_models(db)
    db.create_all()

    class ModelView(CustomModelView):
        def on_model_change(self, form, model, is_created):
            model.test1 = model.test1.upper()

        def on_model_delete(self, model):
            self.deleted = True

    view = ModelView(Model1, db.session)
    admin.add_view(view)

    client = app.test_client()

    client.post('/admin/model1/new/',
                data=dict(test1='test1large', test2='test2'))

    model = db.session.query(Model1).first()
    eq_(model.test1, 'TEST1LARGE')

    url = '/admin/model1/edit/?id=%s' % model.id
    client.post(url, data=dict(test1='test1small', test2='test2large'))

    model = db.session.query(Model1).first()
    eq_(model.test1, 'TEST1SMALL')

    url = '/admin/model1/delete/?id=%s' % model.id
    client.post(url)
    ok_(view.deleted)
开发者ID:Jingcui01,项目名称:campusTours,代码行数:32,代码来源:test_basic.py

示例7: test_message_with_url_is_link

 def test_message_with_url_is_link(self):
     m = Message(message="Go to http://bit.ly/sample-demo", is_global=True,
                 is_active=True, url="/")
     m.save()
     ok_('Go to <a href="http://bit.ly/sample-demo">'
         'http://bit.ly/sample-demo</a>' in
         soapbox_messages(get_soapbox_messages("/")))
开发者ID:VoodooLab,项目名称:kuma,代码行数:7,代码来源:test_helpers.py

示例8: test_get_jwt

 def test_get_jwt(self, client=None, extra_headers=None):
     res = self._post(client=client, extra_headers=extra_headers)
     eq_(res.status_code, 201, res.content)
     contribution = Contribution.objects.get()
     eq_(res.json['contribStatusURL'],
         reverse('webpay-status', kwargs={'uuid': contribution.uuid}))
     ok_(res.json['webpayJWT'])
开发者ID:amitdash,项目名称:zamboni,代码行数:7,代码来源:test_resources.py

示例9: test_saves_promo_img

    def test_saves_promo_img(self, requests_mock, crush_mock):
        img_path = os.path.join(settings.ROOT, 'mkt', 'site', 'tests',
                                'images', 'game_1050.jpg')

        # Mock the image fetch request.
        with open(img_path, 'r') as content:
            requests_mock.return_value = mock.Mock(
                content=content.read(),
                headers={'ok': 'ok'},
                status_code=200)

        result = fetch_promo_imgs(self.website.pk, 'http://mocked_url.ly')
        ok_(result)

        website = Website.objects.all()[0]
        eq_(website.promo_img_hash, '215dd2a2')

        # Check the actual saved image on disk.
        img_dir = website.get_promo_img_dir()
        for size in mkt.PROMO_IMG_SIZES:
            img_path = os.path.join(img_dir, '%s-%s.png' % (str(website.id),
                                                            size))
            with public_storage.open(img_path, 'r') as img:
                checker = ImageCheck(img)
                assert checker.is_image()
                eq_(checker.img.size[0], size)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:26,代码来源:test_tasks.py

示例10: test_title

    def test_title(self):
        event = SuggestedEvent.objects.create(
            user=self.user,
            title='Cool Title',
            slug='cool-title',
        )
        url = reverse('suggest:title', args=(event.pk,))
        response = self.client.get(url)
        eq_(response.status_code, 200)

        data = {
            'title': '',
            'slug': 'contains spaces',
        }
        response = self.client.post(url, data)
        eq_(response.status_code, 200)
        ok_('Form errors' in response.content)

        data = {
            'title': 'New Title',
            'slug': 'new-slug',
        }
        response = self.client.post(url, data)
        eq_(response.status_code, 302)
        next_url = reverse('suggest:description', args=(event.pk,))
        self.assertRedirects(response, next_url)
开发者ID:smarshy,项目名称:airmozilla,代码行数:26,代码来源:test_views.py

示例11: test_details_timezone_formatting

 def test_details_timezone_formatting(self):
     location = Location.objects.create(
         name='Paris',
         timezone='Europe/Paris'
     )
     start_time = datetime.datetime(
         2013, 5, 6, 11, 0, 0
     ).replace(tzinfo=utc)
     event = SuggestedEvent.objects.create(
         user=self.user,
         title='Cool Title',
         slug='cool-title',
         description='Some long description',
         short_description='',
         location=location,
         privacy=Event.PRIVACY_PUBLIC,
         start_time=start_time,
     )
     url = reverse('suggest:details', args=(event.pk,))
     response = self.client.get(url)
     eq_(response.status_code, 200)
     # the location is `US/Pacific` which means at 13:00 UTC,
     # the time is expected to be 05:00 in US/Pacific
     as_string = '2013-05-06 13:00:00'
     ok_('value="%s"' % as_string in response.content)
开发者ID:smarshy,项目名称:airmozilla,代码行数:25,代码来源:test_views.py

示例12: test_link_to_suggest

 def test_link_to_suggest(self):
     event = Event.objects.get(title='Test event')
     self._attach_file(event, self.placeholder)
     response = self.client.get('/')
     eq_(response.status_code, 200)
     start_url = reverse('suggest:start')
     ok_(start_url in response.content)
开发者ID:smarshy,项目名称:airmozilla,代码行数:7,代码来源:test_views.py

示例13: test_send_mail

    def test_send_mail(self, fake_messages):
        """Test EmailRepsForm email sending functionality."""

        data = {"subject": "Test email subject", "body": "Test email body", "functional_area": self.functional_area.id}

        form = EmailRepsForm(data=data)
        ok_(form.is_valid())

        area = self.functional_area
        UserFactory.create_batch(20, userprofile__functional_areas=[area])

        factory = RequestFactory()
        request = factory.request()
        request.user = UserFactory.create()

        reps = User.objects.filter(userprofile__functional_areas__name=area)

        form.send_email(request, reps)

        eq_(len(mail.outbox), 20)

        address = lambda u: "%s %s <%s>" % (u.first_name, u.last_name, u.email)
        recipients = map(address, reps)

        receivers = []
        for i in range(0, len(mail.outbox)):
            eq_(mail.outbox[i].subject, data["subject"])
            eq_(mail.outbox[i].body, data["body"])
            receivers.append(mail.outbox[i].to[0])

        eq_(set(receivers), set(recipients))
        fake_messages.assert_called_with(ANY, "Email sent successfully.")
开发者ID:ppapadeas,项目名称:remo,代码行数:32,代码来源:test_forms.py

示例14: test_register_without_code_vouched

 def test_register_without_code_vouched(self):
     user = UserFactory.create()
     with self.login(user) as client:
         response = client.get(reverse('phonebook:register'), follow=True)
     ok_(not self.client.session.get('invite-code'))
     self.assertJinja2TemplateUsed(response, 'phonebook/home.html')
     eq_(response.status_code, 200)
开发者ID:Acidburn0zzz,项目名称:mozillians,代码行数:7,代码来源:test_views_register.py

示例15: test_non_int_pk

def test_non_int_pk():
    app, db, admin = setup()

    class Model(db.Model):
        id = db.Column(db.String, primary_key=True)
        test = db.Column(db.String)

    db.create_all()

    view = CustomModelView(Model, db.session, form_columns=['id', 'test'])
    admin.add_view(view)

    client = app.test_client()

    rv = client.get('/admin/model/')
    eq_(rv.status_code, 200)

    rv = client.post('/admin/model/new/',
                     data=dict(id='test1', test='test2'))
    eq_(rv.status_code, 302)

    rv = client.get('/admin/model/')
    eq_(rv.status_code, 200)
    data = rv.data.decode('utf-8')
    ok_('test1' in data)

    rv = client.get('/admin/model/edit/?id=test1')
    eq_(rv.status_code, 200)
    data = rv.data.decode('utf-8')
    ok_('test2' in data)
开发者ID:Jingcui01,项目名称:campusTours,代码行数:30,代码来源:test_basic.py


注:本文中的nose.tools.ok_函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。