Beispiel #1
0
    def test_build_should_return_response_successful_with_one_result_and_message(self):

        default_result = Result()
        default_result.message = 'provisionig failed'

        orders = {
            "orders" : [
                {
                    "partner"               : "interpartner",
                    "purchase"              : "1", 
                    "contractId"            : "", 
                    "password"              : "xxx", 
                    "action"                : "incluir", 
                    "customerIdentification" : "1", 
                    "planCode"              : "001", 
                    "startDate"             : "", 
                    "endDate"               : "", 
                    "callback"              : "",
                    "result"                : default_result
                }
            ]
        }

        builder = Response()
        result = builder.build(orders)

        expected = {
            "responses" : [
                { "success"   : False, "purchase"  : "1", "message" : "provisionig failed" }
            ]
        }

        self.assertEquals(expected, result)
Beispiel #2
0
        def test_build_should_return_response_successful_with_two_result(self):

            default_result = Result.create_with_success_default()

            failed_result = Result()
            orders = {
                "orders" : [
                    {
                        "partner"               : "interpartner",
                        "purchase"              : "1", 
                        "contractId"            : "", 
                        "password"              : "xxx", 
                        "action"                : "incluir", 
                        "customerIdentification" : "1", 
                        "planCode"              : "001", 
                        "startDate"             : "", 
                        "endDate"               : "", 
                        "callback"              : "",
                        "result"                : default_result
                    },
                    {
                        "partner"               : "interpartner",
                        "purchase"              : "2", 
                        "contractId"            : "", 
                        "password"              : "xxx", 
                        "action"                : "incluir", 
                        "customerIdentification" : "2", 
                        "planCode"              : "001", 
                        "startDate"             : "", 
                        "endDate"               : "", 
                        "callback"              : "",
                        "result"                : failed_result
                    }
                ]
            }

            builder = Response()
            result = builder.build(orders)

            expected = {
                "responses" : [
                    { "success"   : True,  "purchase"  : "1" },
                    { "success"   : False, "purchase"  : "2" }
                ]
            }

            self.assertEquals(expected, result)
Beispiel #3
0
    def activate(self, json):
        
        for order in json['orders'] :

            if 'partner' not in order :
                order['result'] = Result.create_with_partner_missing_error('partner')
                continue

            validator = self._factory_validator.create(order['partner'])
            if validator.validate("activate", order) :
                builder = self._factory_builder.create(order['partner'], 'activate')
                adapter = self._factory_adapter.create(order['partner'])
                order['result'] = adapter.call(builder.build(order))
            else :
                order['result'] = Result.create_with_partner_missing_error(validator.get_missing_field())

        builder_reponse = Response()
        return builder_reponse.build(json)