コード例 #1
0
ファイル: tests.py プロジェクト: Gartlar/mozio
    def setUp(self):

       u = get_user_model()()
       u.id = 1
       u.username = '******'
       u.first_name = 'test'
       u.last_name = 'test'
       u.email = 'test'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 1
       p.user = u
       p.name = "test"  
       p.email = "*****@*****.**" 
       p.phone = 12312312
       p.currency = "USD"
       p.language = "DE"
       p.save()

       u = get_user_model()()
       u.id = 2
       u.username = '******'
       u.first_name = 'test2'
       u.last_name = 'test2'
       u.email = '*****@*****.**'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 2
       p.user = u
       p.name = "test2"  
       p.email = "*****@*****.**" 
       p.phone = 123123212
       p.currency = "USD"
       p.language = "EN"
       p.save()

       self.url = reverse("provider:provider-detail",kwargs={"pk":1})
コード例 #2
0
ファイル: views.py プロジェクト: deathping1994/mozio
def service_provider(request, id= ''):
    """
        endpoint: /provider/<id>/
        method: GET
        response: Service provider object stored in Database
        method: Post
        body: Json (name,email,phone,currency)
        response: 201, Newly created Service provider object
        method: Put
        body: Json (name,email,phone,currency)
        response: 200, Updated Service Provider Object
        method: Delete
        response: 204, No content
        ________________________________________________________________________________________
        endpoint: /provider/all
        method: GET
        response: Array of all service provider objects
    """
    try:
        if request.method == "POST":
            data = json.loads(request.body)
            provider = Provider(name=data['name'], email=data['email'], phone=data['phone'],
                                currency=data['currency'],service_area=[])
            provider.save()
            return json_response(provider.to_json(), 201)
        if request.method == "GET":
            if id is None or id == '':
                providers= Provider.objects.all()
                return json_response(providers.to_json(), 200)
            else:
                provider = Provider.objects.get(pk=id)
                return json_response(provider.to_json(), 200)
        provider = Provider.objects.get(pk=id)
        if request.method == "PUT":
            data = json.loads(request.body)
            provider.name = data['name']
            provider.email = data['email']
            provider.phone = data['phone']
            provider.currency = data['currency']
            provider.save()
            return json_response(provider.to_json(), 200)
        if request.method == "DELETE":
            provider.delete()
            return json_response('',204)
    except Exception as e:
        response = error_handler(e)
        return response