예제 #1
0
class GetCall(BaseCall):
    method = _('get')
    required_fields = [('order_id', 'hash')]
    cleaner = clean(dict,
                    values={
                        'order_id':
                        'int',
                        'order_status':
                        'int',
                        'client_id':
                        'int',
                        'order_form_id':
                        'int',
                        'order_queue_id':
                        'int',
                        'opportunity_id':
                        'int',
                        'total':
                        'decimal',
                        'activity':
                        'timestamp',
                        'ts':
                        'timestamp',
                        'progress':
                        clean(dict,
                              keys='int',
                              values=clean(dict, values={
                                  'ts': 'timestamp',
                              })),
                    })
예제 #2
0
 def it_raises_key_errors_if_asked(self):
     with pytest.raises(KeyError):
         clean(dict, keys={
             'not_there': int
         }, values={
             'not_there': int
         }, raises=True)({})
예제 #3
0
 def it_cleans_keys_and_nested_values(self):
     assert clean(dict, keys=int, values=clean(dict, values={
         'amount': Decimal,
         'object_id': int,
         'info': clean(dict, values={
             'pack_id': int,
             'amount': Decimal,
         })
     }))({
         '1234': {
             'amount': '123.45',
             'object_id': '123',
             'info': {
                 'pack_id': '1234',
                 'amount': '123.45',
             },
         },
     }) == {
         1234: {
             'amount': Decimal('123.45'),
             'object_id': 123,
             'info': {
                 'pack_id': 1234,
                 'amount': Decimal('123.45'),
             },
         },
     }
예제 #4
0
 def it_cleans_keys_and_nested_values(self):
     assert clean(dict,
                  keys=int,
                  values=clean(dict,
                               values={
                                   'amount':
                                   Decimal,
                                   'object_id':
                                   int,
                                   'info':
                                   clean(dict,
                                         values={
                                             'pack_id': int,
                                             'amount': Decimal,
                                         })
                               }))({
                                   '1234': {
                                       'amount': '123.45',
                                       'object_id': '123',
                                       'info': {
                                           'pack_id': '1234',
                                           'amount': '123.45',
                                       },
                                   },
                               }) == {
                                   1234: {
                                       'amount': Decimal('123.45'),
                                       'object_id': 123,
                                       'info': {
                                           'pack_id': 1234,
                                           'amount': Decimal('123.45'),
                                       },
                                   },
                               }
예제 #5
0
 def it_cleans_recursive_lists(self):
     cleaner = clean(list, values={
         1: str,
         3: int,
         5: clean(list, values=int),
     })
     result = cleaner([0, 1, 2, 3, 4, ['10', '20', '30']])
     assert result == [0, '1', 2, 3, 4, [10, 20, 30]]
예제 #6
0
class InvoicePaymentsCall(BaseCall):
    method = _('invoice_payments')
    required_fields = ['invoice_id']
    cleaner = clean(dict,
                    keys='int',
                    values=clean(dict, values={
                        'time': 'timestamp',
                    }))
예제 #7
0
 def it_cleans_recursive_lists(self):
     cleaner = clean(list,
                     values={
                         1: str,
                         3: int,
                         5: clean(list, values=int),
                     })
     result = cleaner([0, 1, 2, 3, 4, ['10', '20', '30']])
     assert result == [0, '1', 2, 3, 4, [10, 20, 30]]
예제 #8
0
class InvoiceList(BaseCall):
    method = _('invoice_list')
    cleaner = clean(dict,
                    keys='int',
                    values=clean(dict,
                                 values={
                                     'clientid': 'int',
                                     'invid': 'int',
                                     'date': 'timestamp',
                                     'datepaid': 'timestamp',
                                     'due': 'timestamp',
                                 }))
예제 #9
0
class CreditListCall(BaseCall):
    method = _('credit_list')
    required_fields = ['client_id']
    cleaner = clean(dict,
                    keys='int',
                    values=clean(dict,
                                 values={
                                     'clientid': 'int',
                                     'active': 'int',
                                     'credit_id': 'int',
                                     'order_id': 'int',
                                     'date': 'timestamp',
                                 }))
예제 #10
0
class QueueListCall(BaseCall):
    method = _('queue_list')
    required_fields = ['brand_id']
    cleaner = clean(dict,
                    keys='int',
                    values=clean(dict,
                                 values={
                                     'steps':
                                     clean(dict,
                                           keys='int',
                                           values=clean(dict,
                                                        values={
                                                            'count': 'int',
                                                        })),
                                 }))
예제 #11
0
class ListCall(BaseCall):
    method = _('list')
    cleaner = clean(dict,
                    keys='int',
                    values=clean(dict,
                                 values={
                                     'order_id': 'int',
                                     'priority': 'int',
                                     'order_status': 'int',
                                     'client_id': 'int',
                                     'order_form_id': 'int',
                                     'order_queue_id': 'int',
                                     'opportunity_id': 'int',
                                     'total': 'decimal',
                                     'activity': 'timestamp',
                                     'ts': 'timestamp',
                                 }))
예제 #12
0
class CheckLoginCall(BaseCall):
    method = _('check_login')
    cleaner = clean(dict,
                    values={
                        'password_expired': 'int',
                        'last_login': '******',
                        'password_changed': 'timestamp',
                    })
예제 #13
0
 def it_raises_index_errors_if_asked(self):
     cleaner = clean(list, values={
         1: str,
         3: int,
         5: Decimal,
     }, raises=True)
     with pytest.raises(IndexError):
         cleaner(range(2))
예제 #14
0
 def it_silences_index_errors(self):
     cleaner = clean(list, values={
         1: str,
         3: int,
         5: Decimal,
     })
     result = cleaner(range(2))
     assert result == [0, '1']
     assert type(result[1]) is str
예제 #15
0
 def it_silences_index_errors(self):
     cleaner = clean(list, values={
         1: str,
         3: int,
         5: Decimal,
     })
     result = cleaner(range(2))
     assert result == [0, '1']
     assert type(result[1]) is str
예제 #16
0
 def it_cleans_dict_keys(self):
     assert clean(dict, keys=int)({
         '10': 'a',
         '20': 'b',
         '30': 'c',
     }) == {
         10: 'a',
         20: 'b',
         30: 'c',
     }
예제 #17
0
 def it_raises_index_errors_if_asked(self):
     cleaner = clean(list,
                     values={
                         1: str,
                         3: int,
                         5: Decimal,
                     },
                     raises=True)
     with pytest.raises(IndexError):
         cleaner(range(2))
예제 #18
0
 def it_cleans_dict_keys(self):
     assert clean(dict, keys=int)({
         '10': 'a',
         '20': 'b',
         '30': 'c',
     }) == {
         10: 'a',
         20: 'b',
         30: 'c',
     }
예제 #19
0
 def it_cleans_specific_values_in_list(self):
     cleaner = clean(list, values={
         1: str,
         3: int,
         5: Decimal,
     })
     result = cleaner(range(6))
     assert result == [0, '1', 2, 3, 4, Decimal(5)]
     assert type(result[1]) is str
     assert type(result[3]) is int
     assert type(result[5]) is Decimal
예제 #20
0
 def it_cleans_specific_values_in_list(self):
     cleaner = clean(list, values={
         1: str,
         3: int,
         5: Decimal,
     })
     result = cleaner(range(6))
     assert result == [0, '1', 2, 3, 4, Decimal(5)]
     assert type(result[1]) is str
     assert type(result[3]) is int
     assert type(result[5]) is Decimal
예제 #21
0
class InvoiceGet(BaseCall):
    method = _('invoice_get')
    required_fields = ['invoice_id']
    cleaner = clean(dict,
                    values={
                        'clientid': 'int',
                        'invid': 'int',
                        'date': 'timestamp',
                        'datepaid': 'timestamp',
                        'due': 'timestamp',
                        'overdue': 'timestamp',
                    })
예제 #22
0
 def it_cleans_dict_with_specific_keys(self):
     assert clean(dict, keys={
         '200': int,
         300: str,
     })({
         100: 'foo',
         '200': 'bar',
         300: 'baz',
     }) == {
         100: 'foo',
         200: 'bar',
         '300': 'baz',
     }
예제 #23
0
 def it_cleans_dict_with_specific_keys(self):
     assert clean(dict, keys={
         '200': int,
         300: str,
     })({
         100: 'foo',
         '200': 'bar',
         300: 'baz',
     }) == {
         100: 'foo',
         200: 'bar',
         '300': 'baz',
     }
예제 #24
0
class ClientWelcomeStatsCall(BaseCall):
    method = _('client_welcome_stats')
    required_fields = ['client_id']
    cleaner = clean(dict,
                    values={
                        'client_activity_type': 'int',
                        'closed_count': 'int',
                        'inv_count': 'int',
                        'pack_count': 'int',
                        'ticket': 'int',
                        'type': 'int',
                        'client_activity': 'timestamp',
                        'next_inv': 'date',
                    })
예제 #25
0
 def it_cleans_ints(self):
     assert clean(int)('123') == 123
예제 #26
0
 def it_cleans_numerical_values_with_empty_string_as_none(self):
     assert clean('int')('') is None
     assert clean('decimal')('') is None
예제 #27
0
 def it_cleans_numerical_values_with_none_as_none(self):
     assert clean('int')(None) is None
     assert clean('decimal')(None) is None
예제 #28
0
 def it_cleans_decimals_with_commas(self):
     assert clean('decimal')(u'1,200.21') == Decimal('1200.21')
예제 #29
0
 def it_cleans_list_values(self):
     cleaner = clean(list, values=str)
     assert cleaner([1, 2, 3, 4]) == ['1', '2', '3', '4']
예제 #30
0
 def it_cleans_decimals_with_commas(self):
     assert clean('decimal')(u'1,200.21') == Decimal('1200.21')
예제 #31
0
 def it_cleans_timestamps(self):
     assert clean('timestamp')(u'1234567') == \
         datetime.datetime.fromtimestamp(float(1234567))
예제 #32
0
class ListCall(BaseCall):
    method = _('list')
    cleaner = clean(dict, keys='int', values=_CLIENT_CLEANER)
예제 #33
0
class CCAddCall(BaseCall):
    method = _('cc_add')
    required_fields = ['client_id', 'cc_num']
    cleaner = clean(int)
예제 #34
0
class ServiceAddCall(BaseCall):
    method = _('service_add')
    required_fields = ['client_id']
    cleaner = clean(int)
예제 #35
0
 def it_cleans_decimal_as_decimal_type(self):
     assert clean('decimal')(Decimal('1')) == Decimal('1')
예제 #36
0
 def it_cleans_numerical_values_with_none_as_none(self):
     assert clean('int')(None) is None
     assert clean('decimal')(None) is None
예제 #37
0
 def it_cleans_dicts(self):
     assert clean(dict)({'key': 'value'}) == {'key': 'value'}
예제 #38
0
 def it_cleans_list_values(self):
     cleaner = clean(list, values=str)
     assert cleaner([1, 2, 3, 4]) == ['1', '2', '3', '4']
예제 #39
0
 def it_cleans_php(self):
     assert clean('php')(u'a:1:{s:3:"foo";s:3:"bar";}') == {b"foo": b"bar"}
예제 #40
0
class PaymentMethodListCall(BaseCall):
    method = _('payment_method_list')
    cleaner = clean(dict, keys='int')
예제 #41
0
 def it_cleans_dates(self):
     assert clean('date')(u'Apr/01/2014') == datetime.date(2014, 4, 1)
예제 #42
0
 def it_cleans_numerical_values_with_empty_string_as_none(self):
     assert clean('int')('') is None
     assert clean('decimal')('') is None
예제 #43
0
 def it_cleans_ints_with_commas(self):
     assert clean('int')(u'1,221') == 1221
예제 #44
0
 def it_cleans_decimal_as_decimal_type(self):
     assert clean('decimal')(Decimal('1')) == Decimal('1')
예제 #45
0
 def it_cleans_ints_with_commas(self):
     assert clean('int')(u'1,221') == 1221
예제 #46
0
 def it_cleans_ints_as_int_type(self):
     assert clean('int')(1) == 1
예제 #47
0
]

_ = prepend_base(__name__.split('.')[-1])


_DEVICE_CLEANER = clean(dict, values={
    'active': 'int',
    'cage_id': 'int',
    'clientid': 'int',
    'dev': 'int',
    'devtype_group_id': 'int',
    'disabled': 'int',
    'down': 'int',
    'fac_id': 'int',
    'owner': 'int',
    'parent': 'int',
    'rack_id': 'int',
    'row_id': 'int',
    'total': 'int',
    'type_id': 'int',
    'up': 'int',
    'warn': 'int',
    'zone_id': 'int',
    'depth': float,
    'height': float,
    'width': float,
})


class GetCall(BaseCall):
    method = _('get')
    required_fields = ['device_id']
예제 #48
0
 def it_silences_key_errors(self):
     assert clean(dict, keys={
         'not_there': int
     }, values={
         'not_there': int
     })({}) == {}
예제 #49
0
 def it_cleans_dicts(self):
     assert clean(dict)({'key': 'value'}) == {'key': 'value'}
예제 #50
0
 def it_cleans_list(self):
     assert clean(list)([1, 2, 3, 4]) == [1, 2, 3, 4]
예제 #51
0
    'InvoiceList',
    'CreditListCall',
    'ServiceAddCall',
]

_ = prepend_base(__name__.split('.')[-1])

_CLIENT_CLEANER = clean(dict,
                        values={
                            'active': bool,
                            'clientid': 'int',
                            'class_id': 'int',
                            'priority': 'int',
                            'balance': 'decimal',
                            'commission': 'decimal',
                            'commission_rate': 'decimal',
                            'discount': 'decimal',
                            'tier_commission': 'decimal',
                            'tier_commission_rate': 'decimal',
                            'created': 'timestamp',
                            'latest_inv': 'timestamp',
                            'password_changed': 'timestamp',
                            'access': 'php',
                        })


class GetCall(BaseCall):
    method = _('get')
    required_fields = [('client_id', 'user_login', 'email')]
    cleaner = _CLIENT_CLEANER
예제 #52
0
    'InvoiceList',
    'CreditListCall',
    'ServiceAddCall',
]

_ = prepend_base(__name__.split('.')[-1])


_CLIENT_CLEANER = clean(dict, values={
    'active': bool,
    'clientid': 'int',
    'class_id': 'int',
    'priority': 'int',
    'balance': 'decimal',
    'commission': 'decimal',
    'commission_rate': 'decimal',
    'discount': 'decimal',
    'tier_commission': 'decimal',
    'tier_commission_rate': 'decimal',
    'created': 'timestamp',
    'latest_inv': 'timestamp',
    'password_changed': 'timestamp',
    'access': 'php',
})


class GetCall(BaseCall):
    method = _('get')
    required_fields = [('client_id', 'user_login', 'email')]
    cleaner = _CLIENT_CLEANER

예제 #53
0
 def it_cleans_ints(self):
     assert clean(int)('123') == 123
예제 #54
0
 def it_cleans_ints_as_int_type(self):
     assert clean('int')(1) == 1