simple create and update implementation

This commit is contained in:
Colin Goutte 2023-08-23 15:04:33 +02:00
parent 9dc2465d5a
commit 158169b50e
2 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,27 @@
movies = []
class Movie(object):
def __init__(self, name, sample_attr):
self.name = name
self.sample_attr = sample_attr
movies.append(self)
def create(name, sample_attr):
return Movie(name, sample_attr)
def update(name, set_sample_attr):
matches = [m for m in movies if m.name == name]
if len(matches) != 1:
raise LookupError(f"{matches}/{name} should be of length 1")
matches[0].sample_attr = set_sample_attr
return matches[0]
def _clear_movies():
while movies:
movies.pop()

View File

@ -9,15 +9,16 @@ import movie_service
def test_create():
movie = movie_service.create(name="Base movie", sample_attr=0)
assert movie_service.movies
assert movie
def test_update():
movie_service._clear_movies()
initial_value = None
value_to_set = 1
movie = movie_service.create(name="Base movie", sample_attr=initial_value)
base_value = move.sample_attr
base_value = movie.sample_attr
movie_service.update(name="Base movie", set_sample_attr=value_to_set)