<s> import os . path <EOL> from django . test import TestCase <EOL> from django . utils import six <EOL> from storages . backends . overwrite import OverwriteStorage <EOL> from localshop . apps . packages import models <EOL> from localshop . apps . packages import utils <EOL> from localshop . utils import TemporaryMediaRootMixin <EOL> from tests import factories <EOL> class TestRepository ( TestCase ) : <EOL> def test_check_user_role_superuser ( self ) : <EOL> repository = factories . RepositoryFactory ( ) <EOL> team = factories . TeamFactory ( ) <EOL> repository . teams . add ( team ) <EOL> user = factories . UserFactory ( is_superuser = True ) <EOL> user . is_superuser = True <EOL> factories . TeamMemberFactory ( user = user , team = team , role = '<STR_LIT>' ) <EOL> assert repository . check_user_role ( user , [ '<STR_LIT>' ] ) <EOL> def test_check_user_role_owner ( self ) : <EOL> repository = factories . RepositoryFactory ( ) <EOL> team = factories . TeamFactory ( ) <EOL> repository . teams . add ( team ) <EOL> user = factories . UserFactory ( ) <EOL> factories . TeamMemberFactory ( user = user , team = team , role = '<STR_LIT>' ) <EOL> assert repository . check_user_role ( user , [ '<STR_LIT>' ] ) <EOL> def test_check_user_role_wrong_role ( self ) : <EOL> repository = factories . RepositoryFactory ( ) <EOL> team = factories . TeamFactory ( ) <EOL> repository . teams . add ( team ) <EOL> user = factories . UserFactory ( ) <EOL> factories . TeamMemberFactory ( user = user , team = team , role = '<STR_LIT>' ) <EOL> assert not repository . check_user_role ( user , [ '<STR_LIT>' ] ) <EOL> def test_check_user_role_multiple_roles ( self ) : <EOL> repository = factories . RepositoryFactory ( ) <EOL> team = factories . TeamFactory ( ) <EOL> repository . teams . add ( team ) <EOL> user = factories . UserFactory ( ) <EOL> factories . TeamMemberFactory ( user = user , team = team , role = '<STR_LIT>' ) <EOL> assert repository . check_user_role ( user , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class TestReleaseFile ( TemporaryMediaRootMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestReleaseFile , self ) . setUp ( ) <EOL> field = [ field for field in models . ReleaseFile . _meta . fields <EOL> if field . name == '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> field . storage = OverwriteStorage ( ) <EOL> def test_save_contents ( self ) : <EOL> release_file = factories . ReleaseFileFactory ( ) <EOL> dummy_fh = six . BytesIO ( six . b ( "<STR_LIT>" ) ) <EOL> release_file . save_filecontent ( '<STR_LIT>' , dummy_fh ) <EOL> self . assertEqual ( <EOL> release_file . distribution . name , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( release_file . distribution . path ) ) <EOL> def test_delete_file ( self ) : <EOL> release_file = factories . ReleaseFileFactory ( ) <EOL> dummy_fh = six . BytesIO ( six . b ( "<STR_LIT>" ) ) <EOL> release_file . save_filecontent ( '<STR_LIT>' , dummy_fh ) <EOL> self . assertTrue ( os . path . exists ( release_file . distribution . path ) ) <EOL> utils . delete_files ( models . ReleaseFile , instance = release_file ) <EOL> self . assertFalse ( os . path . exists ( release_file . distribution . path ) ) <EOL> def test_delete_file_twice_referenced ( self ) : <EOL> release_file = factories . ReleaseFileFactory ( ) <EOL> dummy_fh = six . BytesIO ( six . b ( "<STR_LIT>" ) ) <EOL> release_file . save_filecontent ( '<STR_LIT>' , dummy_fh ) <EOL> release_file = factories . ReleaseFileFactory ( <EOL> release = release_file . release , filetype = '<STR_LIT>' ) <EOL> release_file . save_filecontent ( '<STR_LIT>' , dummy_fh ) <EOL> self . assertTrue ( os . path . exists ( release_file . distribution . path ) ) <EOL> utils . delete_files ( models . ReleaseFile , instance = release_file ) <EOL> self . assertTrue ( os . path . exists ( release_file . distribution . path ) ) </s>
