コード例 #1
0
ファイル: test_ec_key.py プロジェクト: realityone/libtrust-py
 def setUp(self):
     with open(fixtures_path('ec-private.pem'), 'r') as f:
         self.private_key = ec_key.ECPrivateKey.from_pem(
             f.read().encode('utf-8'))
     with open(fixtures_path('ec-public.pem'), 'r') as f:
         self.public_key = ec_key.ECPublicKey.from_pem(
             f.read().encode('utf-8'))
コード例 #2
0
 def setUp(self):
     self.content = {'hello': '123'}
     with open(fixtures_path('private.pem'), 'r') as f:
         self.rsa_private_key = rsa_key.RSAPrivateKey.from_pem(
             f.read().encode())
     with open(fixtures_path('ec-private.pem'), 'r') as f:
         self.ec_private_key = ec_key.ECPrivateKey.from_pem(
             f.read().encode())
コード例 #3
0
 def connect(self):
     # FIXME need to find a better way to open a random port
     app_path = fixtures_path('factory_app.py')
     self.app = subprocess.Popen(['python', app_path, '-b',
         '127.0.0.1:14444', self.config_path],
         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     time.sleep(5)
コード例 #4
0
ファイル: test_utils.py プロジェクト: ravenac95/testkit
def test_in_directory():
    """Test change CWD to a specific directory"""
    original_working_dir = os.getcwd()
    sample_dir = fixtures_path('sample_dir')
    with in_directory(sample_dir):
        assert os.getcwd() != original_working_dir, "CWD is still the original"
        assert sample_dir == os.path.abspath('.')
    assert sample_dir != os.path.abspath('.')
    assert os.getcwd() == original_working_dir, "CWD did not revert to original"
コード例 #5
0
    def setup(self):
        self.config_path = fixtures_path('config.py')
        config_file = open(self.config_path, 'w')

        self.random_string = random.choice('abcdefghijklmnopqrstuvwxyz')

        config_file.write(textwrap.dedent("""
            TESTVAR = "%s"
        """ % self.random_string))
        config_file.close()
コード例 #6
0
ファイル: test_utils.py プロジェクト: ravenac95/testkit
def test_in_directory_raises_error():
    raised_error = False
    original_working_dir = os.getcwd()
    sample_dir = fixtures_path('sample_dir')
    try:
        with in_directory(sample_dir):
            raise TestException()
    except TestException:
        raised_error = True
    assert raised_error == True, "An error was not raised"
    assert os.getcwd() == original_working_dir, "CWD did not revert to original"
コード例 #7
0
ファイル: test_as_root.py プロジェクト: ravenac95/overlay4u
def test_mount():
    # Get lower directory from fixtures
    lower_dir = fixtures_path('lower_dir')
    # Read the hello.txt file in the lower_dir
    hello_orig_path = os.path.join(lower_dir, 'hello.txt')
    hello_orig_data = read_file_data(hello_orig_path)
    # Use a temp directory for the upper directory
    with temp_directory() as temp_upper_dir:
        # Use a temp directory for the mount point
        with temp_directory() as temp_mount_point:
            # Mount the overlay
            overlay = overlay4u.mount(temp_mount_point, lower_dir, temp_upper_dir)

            # Read the hello.txt file in the mount_point
            hello_overlay_path = os.path.join(temp_mount_point, 'hello.txt')
            hello_overlay_read_data = read_file_data(hello_overlay_path)

            # Assert that the text file's contents
            assert hello_orig_data == hello_overlay_read_data, ('Data '
                    'for hello.txt should be same in overlay and lower dir')

            # Write data to the overlay hello.txt
            hello_overlay_write = open(hello_overlay_path, 'w')

            # Generate a random string
            hello_overlay_write_data = random_string(50)

            # Write that string to the file
            hello_overlay_write.write(hello_overlay_write_data)

            # Save the file
            hello_overlay_write.close()

            # Unmount the overlay
            overlay.unmount()

            # Check that the file doesn't exist at the mount point now (means
            # successful unmount)
            assert os.path.exists(hello_overlay_path) == False, ('Mount '
                    'point should have nothing in it')

            # Check that the upper directory's hello.txt has the correct data
            # from the random generated string
            hello_upper_path = os.path.join(temp_upper_dir, 'hello.txt')
            hello_upper_data = read_file_data(hello_upper_path)
            assert hello_upper_data == hello_overlay_write_data

            # Check that the original file still has the same content
            current_orig_data = read_file_data(hello_orig_path)
            assert hello_orig_data == current_orig_data
コード例 #8
0
 def setUp(self):
     with open(fixtures_path('private.pem'), 'r') as f:
         self.private_key = rsa_key.RSAPrivateKey.from_pem(
             f.read().encode())
     with open(fixtures_path('public.pem'), 'r') as f:
         self.public_key = rsa_key.RSAPublicKey.from_pem(f.read().encode())