Comments (4)
Is there supposed to be an @DataClass annotation on FakeSession? Otherwise there is a class instance and object instance "committed" variable. If not, deleting the "committed = False" line will be OK.
that was me. intention is to have the default .committed
be False for all instances, but any instance that calls commit()
will get its attribute set to True.
this may be a bit of Python weirdness?
>>> class Classy:
... attribute = False
...
>>> instance = Classy()
>>> instance.attribute
False
>>> instance.attribute = True
>>> instance.attribute
True
>>> Classy.attribute
False
from book.
Re: the fake session, I see what you were going for (kind of a "Copy-on-Write"). It is a bit unusual, and looks maybe like it was a mistake The scenarios I am thinking are things like this:
class Thing(object):
stack = [1, 2, 3]
def pop(self):
return self.stack.pop()
def push(self, val):
return self.stack.append(val)
def test_first():
assert Thing().pop() == 3
def test_second():
assert Thing().pop() == 3
def test_third():
thing = Thing()
thing.push(100)
assert thing.stack == [1, 2, 3, 100]
If you run that with a test randomizer or a parallel-runner using threads, the tests looks will look like they fail randomly due to the shared state.
from book.
I suppose people are going to cargo-cult copy these sorts of code listings so maybe we should be careful not to leave footguns like that lying around? will add a note to change it when i get a moment... thanks Ed.
from book.
re: the first comment about making the random-reference-generators more readable, i found that quite appealing. here's what i've been playing around with so far:
def random_suffix():
return uuid.uuid4().hex[:6]
def random_sku(name=''):
return f'sku-{name}-{random_suffix()}'
def random_batchref(name=''):
return f'batch-{name}-{random_suffix()}'
def random_orderid(name=''):
return f'order-{name}-{random_suffix()}
@pytest.mark.usefixtures('postgres_db')
@pytest.mark.usefixtures('restart_api')
def test_happy_path_returns_201_and_allocated_batch():
sku, othersku = random_sku('desirable-chair'), random_sku('ugly-chair')
oldbatch, newbatch = random_batchref('old'), random_batchref('new')
otherbatch = random_batchref('other')
post_to_add_batch(oldbatch, sku, 100, '2011-01-02')
post_to_add_batch(newbatch, sku, 100, '2011-01-01')
post_to_add_batch(otherbatch, othersku, 100, None)
data = {'orderid': random_orderid(), 'sku': sku, 'qty': 3}
url = config.get_api_url()
r = requests.post(f'{url}/allocate', json=data)
assert r.status_code == 201
assert r.json()['batchref'] == newbatch
worth it? overengineered? what do y'all think?
from book.
Related Issues (20)
- A question about rich domain model which may not mentioned in book HOT 2
- Aggregate/Entity ids handling. HOT 2
- Issue with domain object not bounded to a Session HOT 12
- Question - Repository Pattern without UoW HOT 5
- [Question] Can we issue a command in a domain model?
- [Question] SqlAlchemy complete decoupling - is it possible? HOT 3
- [Request] Return types HOT 1
- Wrong url for event storming on Epilogue
- Ch7: mention a "compare-and-set" alternative to "repeatable read" HOT 1
- Making the message bus reliable HOT 3
- What comes after the allocation example? Or: how to modularize the event-driven architecture? HOT 2
- Adaptations for other programming languages? HOT 1
- [Question] A repository for every entity?
- the diagram is this book is very well HOT 1
- ch1: A confusion about unit test demo. HOT 1
- SQLAlchemy and Imperative Mapping (a.k.a. Classical Mapping) HOT 3
- Can we use async await HOT 3
- Book website is "broken" HOT 4
- 'Bug' in Chapter 9 with the `FakeUnitOfWorkWithFakeMessageBus` HOT 2
- You might want to make your favicon round and probably remove the underscore from the title HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from book.