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})
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 })
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})
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)
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)
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)
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)