Пример #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