コード例 #1
0
 def get(self, request, format=None):
     return Response(
         OrderedDict(
             (
                 (
                     "peering",
                     rest_reverse(
                         "peering-api:api-root", request=request, format=format
                     ),
                 ),
                 (
                     "peeringdb",
                     rest_reverse(
                         "peeringdb-api:api-root", request=request, format=format
                     ),
                 ),
                 (
                     "utils",
                     rest_reverse(
                         "utils-api:api-root", request=request, format=format
                     ),
                 ),
             )
         )
     )
コード例 #2
0
ファイル: api_views.py プロジェクト: hellojoshuatonga/notepik
 def get(self, request, format=None):
     return Response(dict(
         notes=rest_reverse('main:note-list', request=request, format=format),
         notecategories=rest_reverse('main:category-list', request=request,
             format=format),
         notepikusers=rest_reverse('main:notepikuser-list', request=request,
             format=format),
         ))
コード例 #3
0
def api_root(request, format=None):
    return Response({
        "Cinemas":
        rest_reverse("cinemas", request=request, format=format),
        "Movies":
        rest_reverse("movies", request=request, format=format),
        "Screenings":
        rest_reverse("screenings", request=request, format=format),
    })
コード例 #4
0
ファイル: views.py プロジェクト: NormanLe/RedditClone
def api_root(request, format=None):
    return Response({
        'users':
        rest_reverse('RedditApp:user-list', request=request, format=format),
        'subs':
        rest_reverse('RedditApp:subblueit-list',
                     request=request,
                     format=format),
        'posts':
        rest_reverse('RedditApp:post-list', request=request, format=format),
        'comments':
        rest_reverse('RedditApp:comment-list', request=request, format=format)
    })
コード例 #5
0
def api_root_view(request, format=None):
    return Response({
        'User Register':
        rest_reverse('user-registration', request=request, format=format),
        'User Log In':
        rest_reverse('user-login', request=request, format=format),
        'Task List':
        rest_reverse('task-list', request=request, format=format),
        'Task Create':
        rest_reverse('task-create', request=request, format=format),
        'Get Task':
        rest_reverse('task-get', request=request, format=format)
    })
コード例 #6
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_destroy_load_missing(self):
     # non-existent loading data cannot be deleted
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, "abcdef"])
     self.client.force_login(self.user)
     response = self.client.delete(url)
     assert response.status_code == status.HTTP_404_NOT_FOUND
コード例 #7
0
def confirm_solicitud(request, token, template=None, source=None):
    encoded_string = urlsafe_base64_decode(token)
    folio = encoded_string.split('=')[1]
    context = {}
    try:
        clients = ['verifica', 'drivemee']
        solicitud = models.Solicitud.objects.get(
            folio=folio, status='pendiente', client__deviceToken__in=clients)


#         solicitud = models.Solicitud.objects.get(folio=folio, client__deviceToken__in=clients)
    except:
        return HttpResponseRedirect(reverse('drivemee:index'))
    if solicitud.client.deviceToken == 'verifica':
        template = 'drivemee/verifica_confirm_solicitud.html'
    elif solicitud.client.deviceToken == 'drivemee':
        template = 'drivemee/drivemee-confirm-solicitud.html'
    solicitud.status = 'abierto'
    solicitud.timestamp_confirmacion = timezone.now()
    solicitud.save()
    context['folio'] = solicitud.internal_folio()
    url = rest_reverse('drivemee:solicitud-detail',
                       args=('agencia', 'activo', solicitud.folio),
                       request=request)
    utilities.send_lead_email(solicitud, request)
    slackbot.send_message('Nuevo lead: ' + url, channel='#leadsvalet')
    return render(request, template, context)
コード例 #8
0
ファイル: test_api.py プロジェクト: chusiang/zamboni
    def test_get(self, version=None, **kwargs):

        if not version:
            version = self.version

        url = rest_reverse('version-detail', kwargs={'pk': version.pk})
        res = self.client.get(url, kwargs)
        data = res.data
        features = data['features']

        eq_(res.status_code, 200)

        # Test values on Version object.
        eq_(data['version'], version.version)
        eq_(data['developer_name'], version.developer_name)
        eq_(data['is_current_version'],
            version == self.app.current_version)
        eq_(data['app'], reverse('api_dispatch_detail', kwargs={
            'resource_name': 'app',
            'api_name': 'apps',
            'pk': self.app.pk}
        ))

        for key in features:
            ok_(getattr(version.features, 'has_' + key))
コード例 #9
0
 def report(self, request, pk=None):
     force = request.query_params.get("force", False)
     delayed_report, created = self.__return_delayed_report(request)
     if created or force:
         prepare_report.delay(delayed_report.pk)
     data = {"message": "OK", "url": rest_reverse('delayedreport-detail', args=[delayed_report.pk], request=request)}
     return Response(data, status=status.HTTP_202_ACCEPTED)
コード例 #10
0
    def test_get_units(self):
        self.assertEqual(Unit.mock_objects.count(), 2)

        response = self.client.get(rest_reverse('mock:unit-list'), follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content,
                             """
                             {
                                 "count": 2,
                                 "next": null,
                                 "previous": null,
                                 "results": [
                                     {
                                        "id": 1,
                                        "name": "Mon premier labo",
                                        "acronym": "MPL",
                                        "authors": []
                                     },
                                     {
                                        "id": 2,
                                        "name": "Mon institut",
                                        "acronym": "MI",
                                        "authors": []
                                     }
                                 ]
                             }
                             """)

        self.assertEqual(Unit.mock_objects.count(), 2)
コード例 #11
0
    def test_fake_argument_is_respected(self):
        test_status_code = 300

        # first test the standard

        response = self.client.get(rest_reverse('mock:unit-detail',
                                                args=[1]), follow=True)

        self.assertNotEqual(response.status_code, test_status_code)

        response = self.client.get(rest_reverse('mock:unit-detail',
                                                args=[1]) +
                                   '?fake=%s' % test_status_code,
                                   follow=True)

        self.assertEqual(response.status_code, test_status_code)
コード例 #12
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_destroy_load_no_permission(self):
     # users without permissions cannot delete in-process loading data
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, "abcdef"])
     self.client.force_login(UserFactory())
     response = self.client.delete(url)
     assert response.status_code == status.HTTP_403_FORBIDDEN
コード例 #13
0
    def test_get(self, version=None, **kwargs):

        if not version:
            version = self.version

        url = rest_reverse('version-detail', kwargs={'pk': version.pk})
        res = self.client.get(url, kwargs)
        data = res.data
        features = data['features']

        eq_(res.status_code, 200)

        # Test values on Version object.
        eq_(data['version'], version.version)
        eq_(data['developer_name'], version.developer_name)
        eq_(data['is_current_version'],
            version == self.app.current_version)
        eq_(data['app'], reverse('api_dispatch_detail', kwargs={
            'resource_name': 'app',
            'api_name': 'apps',
            'pk': self.app.pk}
        ))

        for key in features:
            ok_(getattr(version.features, 'has_' + key))
コード例 #14
0
    def pdf_file(self, obj):
        pdf_ref = rest_reverse(
            'invoice-pdf',
            kwargs={'uuid': obj.uuid.hex},
        )

        return format_html('<a href="%s">download</a>' % pdf_ref)
コード例 #15
0
    def test_get_units(self):
        self.assertEqual(Unit.mock_objects.count(), 2)

        response = self.client.get(rest_reverse('mock:unit-list'),
                                   follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content,
                             """
                             {
                                 "count": 2,
                                 "next": null,
                                 "previous": null,
                                 "results": [
                                     {
                                        "id": 1,
                                        "name": "Name1"
                                     },
                                     {
                                        "id": 2,
                                        "name": "Name2"
                                     }
                                 ]
                             }
                             """)

        self.assertEqual(Unit.mock_objects.count(), 2)
コード例 #16
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_update_load_no_permission(self):
     # users without permissions cannot update in-process loading data
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, "abcdef"])
     self.client.force_login(UserFactory())
     response = self.client.patch(url, format="multipart")
     assert response.status_code == status.HTTP_403_FORBIDDEN
コード例 #17
0
    def test_get_greetings(self):
        self.assertEqual(Greeting.mock_objects.count(), 2)

        response = self.client.get(rest_reverse('mock:greeting-list'),
                                   follow=True)

        self.assertEqual(response.status_code, 200)

        # as order matter, do the order before the check
        id_values = list(Greeting.mock_objects.all())
        id_values = sorted(id_values, key=lambda tup: tup.pk, reverse=True)

        self.assertJSONEqual(
            response.content, """
                             {
                                 "count": 2,
                                 "next": null,
                                 "previous": null,
                                 "results": [
                                     {
                                        "id": %s,
                                        "name": "%s"
                                     },
                                     {
                                        "id": %s,
                                        "name": "%s"
                                     }
                                 ]
                             }
                             """ % (id_values[0].pk, id_values[0].name,
                                    id_values[1].pk, id_values[1].name))

        self.assertEqual(Greeting.mock_objects.count(), 2)
コード例 #18
0
    def test_put_greeting(self):
        before_count = Greeting.mock_objects.count()

        response = self.client.put(rest_reverse('mock:greeting-detail',
                                                args=[1]),
                                   """
                                   {
                                       "name": "newName"
                                   }
                                   """,
                                   content_type='application/json',
                                   follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(
            response.content, """
                             {
                                 "id": 1,
                                 "name": "newName"
                             }
                             """)

        # no new object in the 'mock' db
        self.assertEqual(Greeting.mock_objects.count(), before_count)

        self.assertNotEqual(Greeting.mock_objects.get(pk=1).name, 'newName')
コード例 #19
0
    def test_post_greeting(self):
        before_count = Greeting.mock_objects.count()

        response = self.client.post(rest_reverse('mock:greeting-list'),
                                    """
                                    {
                                        "name": "Toto"
                                    }
                                    """,
                                    content_type='application/json',
                                    follow=True)

        self.assertEqual(response.status_code, 201)
        self.assertJSONEqual(
            response.content, """
                             {
                                 "id": 3,
                                 "name": "Toto"
                             }
                             """)

        # yes, since it's the mock service, the response is as if something was
        # created, but the DB is as before
        self.assertEqual(Greeting.mock_objects.count(), before_count)
        with self.assertRaises(Greeting.DoesNotExist):
            Greeting.mock_objects.get(name='Toto')
コード例 #20
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_update_load_does_not_exist(self):
     # non-existent loading data cannot be updated
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, "abcdef"])
     self.client.force_login(self.user)
     response = self.client.patch(url, format="multipart")
     assert response.status_code == status.HTTP_404_NOT_FOUND
コード例 #21
0
    def test_post_unit(self):
        before_count = Unit.mock_objects.count()

        response = self.client.post(rest_reverse('mock:unit-list'),
                                    """
                                    {
                                        "name": "Toto",
                                        "acronym": "TOTO"
                                    }
                                    """,
                                    content_type='application/json',
                                    follow=True)

        self.assertEqual(response.status_code, 201)
        self.assertJSONEqual(response.content,
                             """
                             {
                                 "id": 3,
                                 "name": "Toto",
                                 "acronym": "TOTO",
                                 "authors": []
                             }
                             """)

        # yes, since it's the mock service, the response is as if something was
        # created, but the DB is as before
        self.assertEqual(Unit.mock_objects.count(), before_count)
        with self.assertRaises(Unit.DoesNotExist):
            Unit.mock_objects.get(name='Toto')
コード例 #22
0
    def test_put_unit(self):
        before_count = Unit.mock_objects.count()

        response = self.client.put(rest_reverse('mock:unit-detail',
                                                args=[1]),
                                   """
                                   {
                                       "name": "newName",
                                       "acronym": "newAcro"
                                   }
                                   """,
                                   content_type='application/json',
                                   follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content,
                             """
                             {
                                 "id": 1,
                                 "name": "newName",
                                 "acronym": "newAcro",
                                 "authors": []
                             }
                             """)

        # no new object in the 'mock' db
        self.assertEqual(Unit.mock_objects.count(), before_count)

        self.assertNotEqual(Unit.mock_objects.get(pk=1).name, 'newName')
        self.assertNotEqual(Unit.mock_objects.get(pk=1).acronym, 'newAcro')
コード例 #23
0
 def get_namespace(name, request, format):
     return (
         name,
         rest_reverse(f"{name}-api:api-root",
                      request=request,
                      format=format),
     )
コード例 #24
0
ファイル: test_views.py プロジェクト: gurumukhi/zamboni
 def do_patch(self, data=None, client=None):
     if data is None:
         data = {}
     if client is None:
         client = self.client
     url = rest_reverse("version-status", kwargs={"pk": self.version.pk})
     res = self.client.patch(url, data=json.dumps(data), content_type="application/json")
     return data, res
コード例 #25
0
    def test_fake_argument_is_respected(self):
        test_status_code = 300

        # first test the standard

        response = self.client.get(rest_reverse('mock:greeting-detail',
                                                args=[1]),
                                   follow=True)

        self.assertNotEqual(response.status_code, test_status_code)

        response = self.client.get(
            rest_reverse('mock:greeting-detail', args=[1]) +
            '?fake=%s' % test_status_code,
            follow=True)

        self.assertEqual(response.status_code, test_status_code)
コード例 #26
0
    def test_get_non_public(self):
        self.app.update(status=amo.STATUS_PENDING)
        url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
        res = self.client.get(url)
        eq_(res.status_code, 403)

        res = self.anon.get(url)
        eq_(res.status_code, 403)
コード例 #27
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
    def test_get_non_public(self):
        self.app.update(status=mkt.STATUS_PENDING)
        url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
        res = self.client.get(url)
        eq_(res.status_code, 403)

        res = self.anon.get(url)
        eq_(res.status_code, 403)
コード例 #28
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_update_load_no_parameters(self):
     # updating loading data with no changed parameters is fine
     load = LoadRequest(study_uuid=self.study.uuid)
     load.store()
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, load.request])
     self.client.force_login(self.user)
     response = self.client.patch(url, format="multipart")
     assert response.status_code == status.HTTP_202_ACCEPTED
コード例 #29
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_create_load_without_upload(self):
     # trying to post with all required options but no upload is OK
     url = rest_reverse("rest:study_load-list", args=[self.study.pk])
     payload = self._build_common_payload()
     self.client.force_login(self.user)
     with patch("edd.load.tasks.wizard_parse_and_resolve") as task:
         response = self.client.post(url, payload, format="multipart")
     assert response.status_code == status.HTTP_200_OK
     task.delay.assert_not_called()
コード例 #30
0
 def patch(self, features=None):
     data = {
         'features': features or ['fm', 'mp3'],
         'developer_name': "Cee's Vans"
     }
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     res = self.client.patch(url, data=json.dumps(data),
                             content_type='application/json')
     return data, res
コード例 #31
0
 def do_patch(self, data=None, client=None):
     if data is None:
         data = {}
     if client is None:
         client = self.client
     url = rest_reverse('version-status', kwargs={'pk': self.version.pk})
     res = self.client.patch(url, data=json.dumps(data),
                             content_type='application/json')
     return data, res
コード例 #32
0
ファイル: test_api.py プロジェクト: smillaedler/zamboni
    def patch(self, mock_has_permission, features=None, auth=True):
        mock_has_permission.return_value = auth
        data = {"features": features or ["fm", "mp3"], "developer_name": "Cee's Vans"}
        url = rest_reverse("version-detail", kwargs={"pk": self.version.pk})

        # Uses PUT because Django's test client didn't support PATCH until
        # bug #17797 was resolved.
        res = self.client.put(url, data=json.dumps(data), content_type="application/json")
        return data, res
コード例 #33
0
ファイル: serializers.py プロジェクト: doytsujin/lava
 def get_url(self, obj, view_name, request, format):
     url_kwargs = {
         "parent_lookup_suite__job_id": obj.suite.job_id,
         "parent_lookup_suite_id": obj.suite_id,
         "pk": obj.pk,
     }
     return rest_reverse(
         view_name, kwargs=url_kwargs, request=request, format=format
     )
コード例 #34
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
 def patch(self, features=None):
     data = {
         'features': features or ['fm', 'mp3'],
         'developer_name': "Cee's Vans"
     }
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     res = self.client.patch(url, data=json.dumps(data),
                             content_type='application/json')
     return data, res
コード例 #35
0
 def get_url(self, obj, view_name, request, format):
     try:
         project_status = ProjectStatus.objects.get(pk=obj.pk)
         return rest_reverse(view_name,
                             kwargs={'pk': project_status.build.pk},
                             request=request,
                             format=format)
     except ProjectStatus.DoesNotExist:
         return None
コード例 #36
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_destroy_load(self):
     # users with permissions can delete in-process loading data
     load = LoadRequest(study_uuid=self.study.uuid)
     load.store()
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, load.request])
     self.client.force_login(self.user)
     response = self.client.delete(url)
     assert response.status_code == status.HTTP_200_OK
コード例 #37
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_create_load_simulated_unknown_error(self):
     # simulate an unexpected error (AttributeError) and verify proper response
     url = rest_reverse("rest:study_load-list", args=[self.study.pk])
     payload = self._build_common_payload()
     payload.update(file=BytesIO(b"some file content"))
     self.client.force_login(self.user)
     with patch("edd.load.rest.views.LoadRequest.store") as store:
         store.side_effect = AttributeError
         response = self.client.post(url, payload, format="multipart")
     assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
コード例 #38
0
    def save_model(self, request, obj, form, change):
        is_update = obj.created_at is not None

        obj.save(using=self.using)

        # Save the object to the warehouse as well.
        headers = {'Content-Type': 'application/json'}
        data = model_to_dict(
            obj,
            fields=(
                'id',
                'company',
                'address',
                'status',
                'deliver_by',
            ),
        )

        if is_update:
            url = request.build_absolute_uri(
                rest_reverse(
                    'warehouse:order-detail',
                    args=[obj.id],
                ))
            resp = requests.patch(
                url,
                data=json.dumps(data, cls=CustomJsonEncoder),
                headers=headers,
            )
        else:
            url = request.build_absolute_uri(
                rest_reverse('warehouse:order-list', ))
            resp = requests.post(
                url,
                data=json.dumps(data, cls=CustomJsonEncoder),
                headers=headers,
            )

        self.logger.debug(
            'Store order saved to warehouse status: {}; reason: {}'.format(
                resp.status_code,
                resp.reason,
            ), )
コード例 #39
0
ファイル: test_api.py プロジェクト: chusiang/zamboni
    def test_app_delete(self):
        """Deleted apps should result in a 404 for the version API."""
        url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
        res = self.client.get(url)
        eq_(res.status_code, 200)

        self.app.delete()

        res = self.client.get(url)
        eq_(res.status_code, 404)
コード例 #40
0
ファイル: views.py プロジェクト: gaoxiaob-fall2020/webapp
 def put(self, request, question_id, answer_id):
     statsd.incr('view_question_n_answer_views_AnswerDetail_PUT')
     q, a = self.get_q_n_a(question_id, answer_id)
     if a.user_id != request.user.id:
         return Response(
             {
                 'Unauthorized':
                 'You\'re not allowed to update an answer that was posted by others.'
             },
             status=status.HTTP_400_BAD_REQUEST)
     serializer = AnswerSerializer(a, data=request.data)
     if serializer.is_valid():
         serializer.save()
         # TODO
         if not settings.TESTING:
             sns_msg = {
                 'on':
                 'answer_updated',
                 'question_id':
                 question_id,
                 'question_creator_email':
                 q.user.username,
                 'question_text':
                 q.question_text,
                 'question_url':
                 rest_reverse('get_put_del_a_question',
                              args=[question_id],
                              request=request),
                 'answer_id':
                 serializer.data.get('answer_id'),
                 'answer_text':
                 serializer.data.get('answer_text'),
                 'answer_url':
                 rest_reverse('get_put_del_an_answer',
                              args=[question_id, answer_id],
                              request=request)
             }
             sns.publish(TopicArn=settings.AWS_SNS_TOPIC_ARN,
                         Message=json.dumps(sns_msg))
         else:
             print('Testing - Update an answer')
         return Response(status=status.HTTP_204_NO_CONTENT)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #41
0
    def test_app_delete(self):
        """Deleted apps should result in a 404 for the version API."""
        url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
        res = self.client.get(url)
        eq_(res.status_code, 200)

        self.app.delete()

        res = self.client.get(url)
        eq_(res.status_code, 404)
コード例 #42
0
ファイル: test_views.py プロジェクト: JBEI/edd
 def test_create_load_multiple_permission(self):
     # users with multiple group permissions are OK
     url = rest_reverse("rest:study_load-list", args=[self.study.pk])
     payload = self._build_common_payload()
     user = self._add_groups_permission()
     self.client.force_login(user)
     with patch("edd.load.tasks.wizard_parse_and_resolve") as task:
         response = self.client.post(url, payload, format="multipart")
     assert response.status_code == status.HTTP_200_OK
     task.delay.assert_not_called()
コード例 #43
0
ファイル: test_api.py プロジェクト: rhelmer/zamboni
    def test_app_delete(self):
        """Deleted apps should result in a 404 for the version API."""
        url = rest_reverse("version-detail", kwargs={"pk": self.version.pk})
        res = self.client.get(url)
        eq_(res.status_code, 200)

        self.create_switch("soft_delete")
        self.app.delete()

        res = self.client.get(url)
        eq_(res.status_code, 404)
コード例 #44
0
    def test_delete_unit(self):
        self.assertTrue(Unit.mock_objects.get(id=1))

        response = self.client.delete(rest_reverse('mock:unit-detail',
                                                   args=[1]),
                                      follow=True)

        self.assertEqual(response.status_code, 204)

        # and the object still exists in the 'mock' db (rollbacked)
        self.assertTrue(Unit.mock_objects.get(id=1))
コード例 #45
0
ファイル: test_api.py プロジェクト: AALEKH/zamboni
    def patch(self, features=None):
        data = {
            'features': features or ['fm', 'mp3'],
            'developer_name': "Cee's Vans"
        }
        url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})

        # Uses PUT because Django's test client didn't support PATCH until
        # bug #17797 was resolved.
        res = self.client.put(url, data=json.dumps(data),
                              content_type='application/json')
        return data, res
コード例 #46
0
def js_config(request):
    """
    Javascript config context processor. Provides urls and
     backend-defined settings to be loaded in javascript.
    :param request:
    :return:
    """
    config = {
        'latest_tweets_endpoint': rest_reverse(
            'twitter_streamer:api:tweets-latest'),
        'tweets_list_endpoint': rest_reverse(
            'twitter_streamer:api:tweets-list'),
        'admin_vote_endpoint': url_reverse(
            'twitter_streamer:admin_vote'),
        'search_endpoint': url_reverse(
            'search:tweet_search'),
        'tweet_page_size': settings.TWEET_PAGE_SIZE,
        'is_staff': request.user.is_staff
    }

    return {'js_config': json.dumps(config)}
コード例 #47
0
    def test_get_unit_1(self):
        response = self.client.get(rest_reverse('mock:unit-detail',
                                                args=[1]),
                                   follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content,
                             """
                             {
                                 "id": 1,
                                 "name": "Name1"
                             }
                             """)
コード例 #48
0
def _get_url(object_type, rdn_value=None): # API URL
    """
    <RegexURLPattern servers-detail ^servers/(?P<name>[^/]+)/$>,
    <RegexURLPattern servers-aliases ^servers/(?P<name>[^/]+)/aliases/$>,
    <RegexURLPattern servers-resources ^servers/(?P<name>[^/]+)/resources/$>,
    <RegexURLPattern servers-sudoers ^servers/(?P<name>[^/]+)/sudoers/$>,
    <RegexURLPattern servers-users ^servers/(?P<name>[^/]+)/users/$>,
    """
    try:
        return rest_reverse('%s-detail' % object_type.__class__.__name__.lower(), args=[getattr(object_type, 'name', object_type)])
    except NoReverseMatch, e:
        # TODO: Resource-model needs API entry
        print e
        return '/'
コード例 #49
0
    def test_get_unit_1(self):
        response = self.client.get(rest_reverse('mock:unit-detail',
                                                args=[1]),
                                   follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content,
                             """
                             {
                                 "id": 1,
                                 "name": "Mon premier labo",
                                 "acronym": "MPL",
                                 "authors": []
                             }
                             """)
コード例 #50
0
    def test_fake_argument_dont_do_the_action(self):
        test_status_code = 300

        before_count = Unit.mock_objects.count()

        response = self.client.post(rest_reverse('mock:unit-list') +
                                    '?fake=%s' % test_status_code,
                                    """
                                    {
                                        "name": "Toto"
                                    }
                                    """,
                                    content_type='application/json')

        self.assertEqual(response.status_code, test_status_code)
        self.assertEqual(Unit.mock_objects.count(), before_count)
コード例 #51
0
ファイル: test_views.py プロジェクト: gurumukhi/zamboni
    def test_get(self, version=None, **kwargs):
        if not version:
            version = self.version

        url = rest_reverse("version-detail", kwargs={"pk": version.pk})
        res = self.client.get(url, kwargs)
        data = res.data
        features = data["features"]

        eq_(res.status_code, 200)

        # Test values on Version object.
        eq_(data["version"], version.version)
        eq_(data["developer_name"], version.developer_name)
        eq_(data["is_current_version"], version == self.app.current_version)
        eq_(data["app"], reverse("app-detail", kwargs={"pk": self.app.pk}))

        for key in features:
            ok_(getattr(version.features, "has_" + key))
コード例 #52
0
ファイル: views.py プロジェクト: acrooo/Adlibre-DMS
 def get(self, request, format=None):
     code='testcode'
     urls = {
         'main': rest_reverse('api_main', request=request, format=format),
         'viersion': rest_reverse('api_version', request=request, format=format),
         'api_file': rest_reverse('api_file', kwargs={'code': 'code'}, request=request, format=format),
         'api_file_info': reverse('api_file_info', kwargs={'code': 'code'}),
         'api_file_list': reverse('api_file_list', kwargs={'id_rule': 1}),
         'api_revision_count': reverse('api_revision_count', kwargs={'document': 'code'}),
         'api_rules': rest_reverse('api_rules', request=request, format=format),
         'api_rules_detail': reverse('api_rules_detail', kwargs={'id_rule': '1'}),
         'api_tags': reverse('api_tags', kwargs={'id_rule': '1'}),
         'api_plugins': rest_reverse('api_plugins', request=request, format=format),
         'api_mdt': rest_reverse('api_mdt', request=request, format=format),
         'api_parallel': rest_reverse('api_parallel', request=request, format=format),
         'api_thumbnail': reverse('api_thumbnail', kwargs={'code': 'code'}),
         'api_file_deprecated': reverse('api_file_deprecated', kwargs={'code': 'code'}),
     }
     return Response(urls)
コード例 #53
0
ファイル: test_api.py プロジェクト: AALEKH/zamboni
 def test_get_non_app(self):
     self.app.update(type=amo.ADDON_PERSONA)
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     res = self.client.get(url)
     eq_(res.status_code, 404)
コード例 #54
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
 def test_get_owner_non_public(self):
     self.app.update(status=mkt.STATUS_PENDING)
     self.app.webappuser_set.create(user=self.user)
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     res = self.client.get(url)
     eq_(res.status_code, 200)
コード例 #55
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
 def test_get_reviewer_non_public(self):
     self.app.update(status=mkt.STATUS_PENDING)
     self.grant_permission(self.profile, 'Apps:Review')
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     res = self.client.get(url)
     eq_(res.status_code, 200)
コード例 #56
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
 def test_has_cors(self):
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     self.assertCORS(self.client.get(url), 'get', 'put', 'patch')
コード例 #57
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
 def test_delete(self):
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     res = self.client.delete(url)
     eq_(res.status_code, 405)
コード例 #58
0
ファイル: test_views.py プロジェクト: shahbaz17/zamboni
 def test_get_deleted_app(self):
     url = rest_reverse('version-detail', kwargs={'pk': self.version.pk})
     self.app.delete()
     res = self.client.get(url)
     eq_(res.status_code, 404)
コード例 #59
0
ファイル: test_views.py プロジェクト: gurumukhi/zamboni
 def patch(self, features=None):
     data = {"features": features or ["fm", "mp3"], "developer_name": "Cee's Vans"}
     url = rest_reverse("version-detail", kwargs={"pk": self.version.pk})
     res = self.client.patch(url, data=json.dumps(data), content_type="application/json")
     return data, res
コード例 #60
0
ファイル: views.py プロジェクト: hemebond/djeden
	def get(self, request):
		return Response({
			'projects': rest_reverse('project_list', request=request),
			'organisations': rest_reverse('organisation_list', request=request),
		})