예제 #1
0
 def get_for_or_create(cls, entity_type, entity_id, currency):
     return get_or_create(get_method=cls.get_for,
                          create_method=cls.create,
                          exception=IntegrityError,
                          kwargs={'entity_type': entity_type,
                                  'entity_id': entity_id,
                                  'currency': currency})
예제 #2
0
 def get_for_or_create(cls, entity_type, entity_id, currency):
     return get_or_create(get_method=cls.get_for,
                          create_method=cls.create,
                          exception=IntegrityError,
                          kwargs={
                              'entity_type': entity_type,
                              'entity_id': entity_id,
                              'currency': currency
                          })
예제 #3
0
 def get_for_or_create(cls, type, account_id, entity_id, source, state):
     return get_or_create(get_method=cls.get_for,
                          create_method=cls.create,
                          exception=IntegrityError,
                          kwargs={'type': type,
                                  'account_id': account_id,
                                  'entity_id': entity_id,
                                  'source': source,
                                  'state': state})
예제 #4
0
    def test_get_or_create__by_get(self):
        def get(x, y):
            return x + y

        self.assertEqual(
            get_or_create(get_method=get,
                          create_method=None,
                          exception=None,
                          kwargs={
                              'x': 222,
                              'y': 444
                          }), 666)
예제 #5
0
    def test_get_or_create__by_second_get(self):
        global _get_or_create_state
        _get_or_create_state = 'first'

        def get(x, y):
            global _get_or_create_state
            if _get_or_create_state == 'first':
                _get_or_create_state = 'second'
                return None
            return x + y

        def create(x, y): raise Exception

        self.assertEqual(get_or_create(get_method=get, create_method=create, exception=Exception, kwargs={'x': 222, 'y': 444}), 666)
예제 #6
0
    def test_get_or_create__by_second_get(self):
        global _get_or_create_state
        _get_or_create_state = 'first'

        def get(x, y):
            global _get_or_create_state
            if _get_or_create_state == 'first':
                _get_or_create_state = 'second'
                return None
            return x + y

        def create(x, y):
            raise Exception

        self.assertEqual(
            get_or_create(get_method=get,
                          create_method=create,
                          exception=Exception,
                          kwargs={
                              'x': 222,
                              'y': 444
                          }), 666)
예제 #7
0
    def test_get_or_create__by_create(self):
        def get(x, y): return None
        def create(x, y): return x + y

        self.assertEqual(get_or_create(get_method=get, create_method=create, exception=None, kwargs={'x': 222, 'y': 444}), 666)