<commit_before># python
from auth.userpass import Userpass
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
from nose.tools import raises


class Test_Userpass(object):
    def test_userpass_001(self):
        """Check userpass vs. 2 user adds, default/first user"""
        userpass = Userpass()
        userpass.add_user_passwd("user1", "passwd1")
        userpass.add_user_passwd("user2", "passwd2")
        assert_equal( userpass.user, "user1" )
        assert_equal( userpass.passwd, "passwd1" )
        assert_equal( userpass.passwd_for("user2"), "passwd2")

    def test_userpass_002(self):
        """Check userpass vs. 2 user adds, switch users"""
        userpass = Userpass()
        userpass.add_user_passwd("user1", "<PASSWORD>1")
        userpass.add_user_passwd("user2", "passwd2")
        userpass.change_user( "user2" )
        assert_equal( userpass.user, "user2" )
        assert_equal( userpass.passwd, "passwd2" )

    def test_userpass_003(self):
        """Check userpass vs. 2 user adds, keys and has_key"""
        userpass = Userpass()
        userpass.add_user_passwd("user1", "<PASSWORD>1")
        userpass.add_user_passwd("user2", "<PASSWORD>2")
        assert_equal( userpass.has_key("user1"), True )
        assert_equal( userpass.has_key("user2"), True )
        assert_equal( userpass.has_key("user3"), False )
        assert_equal( sorted(userpass.keys()), ["user1", "user2"] )
        assert_equal( sorted(userpass.keys()), sorted(userpass.users()) )

    def test_userpass_004(self):
        """Check userpass file load works and sets file permissions to 600"""
        #write yaml file
        filepath = "/var/tmp/test.userpass.004.yml"
        f = open( filepath, "w")
        f.write("""
        users:
            user1: <PASSWORD>
            user2: <PASSWORD>
        defaultuser: user1
        """)
        f.close()
        #set group readable
        import os,stat
        os.chmod( filepath, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP)
        beforestat = os.stat(filepath)
        assert_equal( bool(beforestat.st_mode & stat.S_IRGRP), True )
        #read in yaml pwdb
        userpass = Userpass( filepath )
        #verify file is not group readable after load
        afterstat = os.stat(filepath)
        assert_equal( bool(afterstat.st_mode & stat.S_IRGRP), False )
        #perform checks per testcases above
        assert_equal( userpass.user, "user1" )
        assert_equal( userpass.passwd, "<PASSWORD>" )
        userpass.change_user( "user2" )
        assert_equal( userpass.user, "user2" )
        assert_equal( userpass.passwd, "<PASSWORD>" )
        assert_equal( userpass.has_key("user1"), True )
        assert_equal( userpass.has_key("user2"), True )
        assert_equal( userpass.has_key("user3"), False )


<commit_msg>coverage for line 44<commit_after># python
from auth.userpass import Userpass
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
from nose.tools import raises


class Test_Userpass(object):
    def test_userpass_001(self):
        """Check userpass vs. 2 user adds, default/first user"""
        userpass = Userpass()
        userpass.add_user_passwd("user1", "<PASSWORD>1")
        userpass.add_user_passwd("user2", "<PASSWORD>2")
        assert_equal( userpass.user, "user1" )
        assert_equal( userpass.passwd, "<PASSWORD>" )
        assert_equal( userpass.passwd_for(), "passwd1" )
        assert_equal( userpass.passwd_for("user2"), "<PASSWORD>2")

    def test_userpass_002(self):
        """Check userpass vs. 2 user adds, switch users"""
        userpass = Userpass()
        userpass.add_user_passwd("user1", "<PASSWORD>")
        userpass.add_user_passwd("user2", "<PASSWORD>")
        userpass.change_user( "user2" )
        assert_equal( userpass.user, "user2" )
        assert_equal( userpass.passwd, "<PASSWORD>" )

    def test_userpass_003(self):
        """Check userpass vs. 2 user adds, keys and has_key"""
        userpass = Userpass()
        userpass.add_user_passwd("user1", "<PASSWORD>1")
        userpass.add_user_passwd("user2", "<PASSWORD>")
        assert_equal( userpass.has_key("user1"), True )
        assert_equal( userpass.has_key("user2"), True )
        assert_equal( userpass.has_key("user3"), False )
        assert_equal( sorted(userpass.keys()), ["user1", "user2"] )
        assert_equal( sorted(userpass.keys()), sorted(userpass.users()) )

    def test_userpass_004(self):
        """Check userpass file load works and sets file permissions to 600"""
        #write yaml file
        filepath = "/var/tmp/test.userpass.004.yml"
        f = open( filepath, "w")
        f.write("""
        users:
            user1: <PASSWORD>
            user2: <PASSWORD>
        defaultuser: user1
        """)
        f.close()
        #set group readable
        import os,stat
        os.chmod( filepath, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP)
        beforestat = os.stat(filepath)
        assert_equal( bool(beforestat.st_mode & stat.S_IRGRP), True )
        #read in yaml pwdb
        userpass = Userpass( filepath )
        #verify file is not group readable after load
        afterstat = os.stat(filepath)
        assert_equal( bool(afterstat.st_mode & stat.S_IRGRP), False )
        #perform checks per testcases above
        assert_equal( userpass.user, "user1" )
        assert_equal( userpass.passwd, "<PASSWORD>" )
        userpass.change_user( "user2" )
        assert_equal( userpass.user, "user2" )
        assert_equal( userpass.passwd, "<PASSWORD>" )
        assert_equal( userpass.has_key("user1"), True )
        assert_equal( userpass.has_key("user2"), True )
        assert_equal( userpass.has_key("user3"), False )



{'fraction_non_alphanumeric': 0.12199758078451702, 'fraction_numerical': 0.018316917228270262, 'mean_word_length': 2.8663994655978624, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1511626', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1832, 'n_words': 406}