Refactor and cleanup codes. No functional changes.
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
################################################################################
|
||||
# Copyright 2017 Google Inc.
|
||||
# Copyright 2017 Google LLC.
|
||||
#
|
||||
# This software is licensed under the terms defined in the Widevine Master
|
||||
# License Agreement. For a copy of this agreement, please contact
|
||||
# widevine-licensing@google.com.
|
||||
################################################################################
|
||||
|
||||
"""Class that provides test data for Provisioning SDK testing."""
|
||||
|
||||
import os
|
||||
|
||||
import pywrapcertificate_type
|
||||
from certificate_type import CertificateType
|
||||
|
||||
_TEST_CERT_DATA_FOLDER = os.path.join('example', 'example_data')
|
||||
_DEV_CERT_DATA_FOLDER = os.path.join('example', 'dev_cert_example_data')
|
||||
@@ -21,24 +19,27 @@ class TestDataProvider(object):
|
||||
|
||||
def __init__(self, cert_type):
|
||||
"""Initializes the TestData for Provisioning SDK tests."""
|
||||
assert (cert_type in (
|
||||
pywrapcertificate_type.kCertDevelopment,
|
||||
pywrapcertificate_type.kCertTesting))
|
||||
assert (cert_type in (CertificateType.kCertificateTypeDevelopment,
|
||||
CertificateType.kCertificateTypeTesting))
|
||||
self._cert_type = cert_type
|
||||
|
||||
def _GetTestData(self, filename):
|
||||
"""Helps read test data files such as certs and keys for SDK testing."""
|
||||
current_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
if self._cert_type == pywrapcertificate_type.kCertDevelopment:
|
||||
if self._cert_type == CertificateType.kCertificateTypeDevelopment:
|
||||
subfolder_path = _DEV_CERT_DATA_FOLDER
|
||||
elif self._cert_type == pywrapcertificate_type.kCertTesting:
|
||||
elif self._cert_type == CertificateType.kCertificateTypeTesting:
|
||||
subfolder_path = _TEST_CERT_DATA_FOLDER
|
||||
while not os.path.isdir(os.path.join(current_dir, subfolder_path)):
|
||||
current_dir = os.path.dirname(current_dir)
|
||||
filename = os.path.join(current_dir, subfolder_path, filename)
|
||||
with open(filename, 'rb') as data_file:
|
||||
data = data_file.read()
|
||||
return data
|
||||
try:
|
||||
with open(filename, 'r') as data_file:
|
||||
data = data_file.read()
|
||||
return data
|
||||
except IOError:
|
||||
print 'TestDataProvider: Failed to read \'%s\'' % filename
|
||||
return None
|
||||
|
||||
@property
|
||||
def service_drm_cert(self):
|
||||
@@ -86,11 +87,11 @@ class TestDataProvider(object):
|
||||
|
||||
@property
|
||||
def device_public_key(self):
|
||||
return self._GetTestData('user.public')
|
||||
return self._GetTestData('device.public')
|
||||
|
||||
@property
|
||||
def device_private_key(self):
|
||||
return self._GetTestData('user.private')
|
||||
return self._GetTestData('device.private')
|
||||
|
||||
@property
|
||||
def message(self):
|
||||
|
||||
Reference in New Issue
Block a user