<s> import pytest <EOL> import mock <EOL> from h import session <EOL> class FakeGroup ( object ) : <EOL> def __init__ ( self , pubid , name ) : <EOL> self . pubid = pubid <EOL> self . name = name <EOL> self . slug = pubid <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_model_sorts_groups ( User ) : <EOL> fake_user = mock . Mock ( ) <EOL> fake_user . groups = [ <EOL> FakeGroup ( '<STR_LIT:c>' , '<STR_LIT>' ) , <EOL> FakeGroup ( '<STR_LIT:b>' , '<STR_LIT>' ) , <EOL> FakeGroup ( '<STR_LIT:a>' , '<STR_LIT>' ) , <EOL> ] <EOL> request = mock . Mock ( authenticated_user = fake_user ) <EOL> session_model = session . model ( request ) <EOL> ids = [ group [ '<STR_LIT:id>' ] for group in session_model [ '<STR_LIT>' ] ] <EOL> assert ids == [ '<STR_LIT>' , '<STR_LIT:c>' , '<STR_LIT:a>' , '<STR_LIT:b>' ] <EOL> def test_model_includes_features ( fake_user ) : <EOL> feature_dict = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> request = mock . Mock ( authenticated_user = fake_user ) <EOL> request . feature . all . return_value = feature_dict <EOL> assert session . model ( request ) [ '<STR_LIT>' ] == feature_dict <EOL> @ pytest . mark . parametrize ( <EOL> "<STR_LIT>" , <EOL> [ ( False , False , False ) , <EOL> ( True , False , True ) , <EOL> ( True , True , False ) ] ) <EOL> def test_model_show_sidebar_tutorial ( <EOL> fake_user , user_authenticated , tutorial_dismissed , show_tutorial ) : <EOL> """<STR_LIT>""" <EOL> fake_user . sidebar_tutorial_dismissed = tutorial_dismissed <EOL> if user_authenticated : <EOL> authenticated_user = fake_user <EOL> else : <EOL> authenticated_user = None <EOL> request = mock . Mock ( <EOL> authenticated_user = authenticated_user , <EOL> ) <EOL> preferences = session . model ( request ) [ '<STR_LIT>' ] <EOL> if show_tutorial : <EOL> assert preferences [ '<STR_LIT>' ] is True <EOL> else : <EOL> assert '<STR_LIT>' not in preferences <EOL> @ pytest . fixture <EOL> def fake_user ( ) : <EOL> fake_user = mock . Mock ( ) <EOL> fake_user . groups = [ ] <EOL> return fake_user </s>
