<s> import pytest <EOL> import pprint <EOL> from . . helpers . movie_data import Movie , Actor , Director <EOL> from . fixtures import backend <EOL> from blitzdb . backends . sql . relations import ManyToManyProxy <EOL> def test_basics ( backend ) : <EOL> backend . init_schema ( ) <EOL> backend . create_schema ( ) <EOL> francis_coppola = Director ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> stanley_kubrick = Director ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> robert_de_niro = Actor ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } ) <EOL> harrison_ford = Actor ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> brian_de_palma = Director ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> al_pacino = Actor ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } ) <EOL> scarface = Movie ( { '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : brian_de_palma } ) <EOL> the_godfather = Movie ( { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : francis_coppola } ) <EOL> space_odyssey = Movie ( { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : stanley_kubrick } ) <EOL> clockwork_orange = Movie ( { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : stanley_kubrick } ) <EOL> robert_de_niro . movies . append ( the_godfather ) <EOL> al_pacino . movies . append ( the_godfather ) <EOL> al_pacino . movies . append ( scarface ) <EOL> apocalypse_now = Movie ( { '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> star_wars_v = Movie ( { '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> harrison_ford . movies = [ star_wars_v ] <EOL> backend . save ( robert_de_niro ) <EOL> backend . save ( al_pacino ) <EOL> backend . save ( francis_coppola ) <EOL> backend . save ( stanley_kubrick ) <EOL> backend . save ( brian_de_palma ) <EOL> backend . save ( harrison_ford ) <EOL> backend . update ( stanley_kubrick , { '<STR_LIT>' : al_pacino } ) <EOL> backend . update ( francis_coppola , { '<STR_LIT>' : robert_de_niro } ) <EOL> backend . save ( the_godfather ) <EOL> backend . save ( clockwork_orange ) <EOL> backend . save ( space_odyssey ) <EOL> backend . save ( scarface ) <EOL> backend . commit ( ) <EOL> actor = backend . get ( Actor , { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> assert isinstance ( actor . movies , ManyToManyProxy ) <EOL> assert the_godfather in actor . movies <EOL> assert scarface in actor . movies <EOL> assert len ( actor . movies ) == <NUM_LIT:2> <EOL> with backend . transaction ( ) : <EOL> actor . movies . remove ( scarface ) <EOL> assert scarface not in actor . movies <EOL> assert len ( actor . movies ) == <NUM_LIT:1> <EOL> actor . movies . append ( scarface ) <EOL> assert len ( actor . movies ) == <NUM_LIT:2> <EOL> assert scarface in actor . movies <EOL> actor . movies . append ( scarface ) <EOL> assert len ( actor . movies ) == <NUM_LIT:2> <EOL> assert scarface in actor . movies <EOL> actor . movies . extend ( [ scarface , the_godfather ] ) <EOL> assert len ( actor . movies ) == <NUM_LIT:2> <EOL> assert scarface in actor . movies <EOL> actor . movies . extend ( [ scarface , the_godfather , star_wars_v ] ) <EOL> assert len ( actor . movies ) == <NUM_LIT:3> <EOL> assert star_wars_v in actor . movies <EOL> assert len ( actor . movies [ <NUM_LIT:1> : ] ) == <NUM_LIT:2> <EOL> assert len ( actor . movies [ <NUM_LIT:1> : <NUM_LIT:2> ] ) == <NUM_LIT:1> <EOL> assert len ( actor . movies [ : - <NUM_LIT:1> ] ) == <NUM_LIT:2> <EOL> assert len ( actor . movies [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) == <NUM_LIT:1> </s>
