<s> from __future__ import absolute_import <EOL> from datetime import datetime <EOL> from flask_sqlalchemy import SQLAlchemy , _SessionSignalEvents <EOL> try : <EOL> from unittest2 import TestCase <EOL> except ImportError : <EOL> from unittest import TestCase <EOL> _SessionSignalEvents . session_signal_before_commit = staticmethod ( lambda s : s ) <EOL> _SessionSignalEvents . session_signal_after_commit = staticmethod ( lambda s : s ) <EOL> db = SQLAlchemy ( ) <EOL> usermessages = db . Table ( <EOL> '<STR_LIT>' , <EOL> db . Column ( '<STR_LIT>' , db . Integer , db . ForeignKey ( '<STR_LIT>' ) ) , <EOL> db . Column ( '<STR_LIT>' , db . Integer , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> class Profile ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:20> ) , nullable = False ) <EOL> user = db . relationship ( "<STR_LIT>" , uselist = False , backref = "<STR_LIT>" ) <EOL> class User ( db . Model ) : <EOL> __tablename__ = '<STR_LIT:user>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> score = db . Column ( db . SmallInteger , default = <NUM_LIT:50> , nullable = False ) <EOL> created_at = db . Column ( <EOL> db . DateTime , default = datetime . utcnow , nullable = False ) <EOL> username = db . Column ( db . String ( <NUM_LIT:20> ) , nullable = False ) <EOL> profile_id = db . Column ( db . Integer , db . ForeignKey ( <EOL> '<STR_LIT>' ) , nullable = False ) <EOL> messages = db . relationship ( <EOL> "<STR_LIT>" , secondary = usermessages , backref = "<STR_LIT>" ) <EOL> class Role ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:20> ) , nullable = False ) <EOL> user_id = db . Column ( db . Integer , db . ForeignKey ( User . id ) , nullable = False ) <EOL> user = db . relation ( User ) <EOL> class Message ( db . Model ) : <EOL> __tablename__ = '<STR_LIT:message>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> content = db . Column ( db . String ( <NUM_LIT:20> ) ) <EOL> class Node ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> parent_id = db . Column ( db . Integer , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> children = db . relation ( <EOL> '<STR_LIT>' , <EOL> cascade = '<STR_LIT:all>' , <EOL> backref = db . backref ( '<STR_LIT>' , remote_side = '<STR_LIT>' ) ) <EOL> class MixerTestFlask ( TestCase ) : <EOL> def setUp ( self ) : <EOL> from flask import Flask <EOL> self . app = Flask ( __name__ ) <EOL> self . app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> db . init_app ( self . app ) <EOL> def test_base ( self ) : <EOL> from mixer . backend . flask import Mixer <EOL> mixer = Mixer ( commit = True ) <EOL> mixer . init_app ( self . app ) <EOL> with self . app . test_request_context ( ) : <EOL> db . create_all ( ) <EOL> node = mixer . blend ( '<STR_LIT>' ) <EOL> self . assertTrue ( node . id ) <EOL> self . assertFalse ( node . parent ) <EOL> role = mixer . blend ( '<STR_LIT>' ) <EOL> self . assertTrue ( role . user ) <EOL> self . assertEqual ( role . user_id , role . user . id ) <EOL> user = mixer . blend ( User ) <EOL> self . assertTrue ( user . id ) <EOL> self . assertTrue ( user . username ) <EOL> self . assertEqual ( user . score , <NUM_LIT:50> ) <EOL> self . assertTrue ( user . created_at ) <EOL> self . assertTrue ( user . profile ) <EOL> self . assertEqual ( user . profile . user , user ) <EOL> user = mixer . blend ( User , username = '<STR_LIT:test>' ) <EOL> self . assertEqual ( user . username , '<STR_LIT:test>' ) <EOL> role = mixer . blend ( <EOL> '<STR_LIT>' , user__username = '<STR_LIT>' ) <EOL> self . assertEqual ( role . user . username , '<STR_LIT>' ) <EOL> users = User . query . all ( ) <EOL> role = mixer . blend ( '<STR_LIT>' , user = mixer . SELECT ) <EOL> self . assertTrue ( role . user in users ) <EOL> role = mixer . blend ( '<STR_LIT>' , user = mixer . RANDOM ) <EOL> self . assertTrue ( role . user ) <EOL> profile = mixer . blend ( '<STR_LIT>' ) <EOL> user = mixer . blend ( User , profile = profile ) <EOL> self . assertEqual ( user . profile , profile ) <EOL> user = mixer . blend ( User , score = mixer . RANDOM ) <EOL> self . assertNotEqual ( user . score , <NUM_LIT:50> ) <EOL> user = mixer . blend ( User , username = lambda : '<STR_LIT>' ) <EOL> self . assertEqual ( user . username , '<STR_LIT>' ) <EOL> messages = mixer . cycle ( <NUM_LIT:3> ) . blend ( Message ) <EOL> user = mixer . blend ( User , messages = messages ) <EOL> self . assertEqual ( len ( user . messages ) , <NUM_LIT:3> ) <EOL> user = mixer . blend ( User , messages = mixer . RANDOM ) <EOL> self . assertEqual ( len ( user . messages ) , <NUM_LIT:1> ) <EOL> user = mixer . blend ( User , messages__content = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( user . messages ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( user . messages [ <NUM_LIT:0> ] . content , '<STR_LIT>' ) <EOL> def test_default_mixer ( self ) : <EOL> from mixer . backend . flask import mixer <EOL> test = mixer . blend ( User ) <EOL> self . assertTrue ( test . username ) </s>
