def test_import_library_with_resources(self): """ Try importing a basic library with resources """ bundle = build_bundle({ 'package.json': make_package( pebble_options={ 'projectType': 'package', 'resources': { 'media': [{ 'type': 'bitmap', 'name': 'MY_RES1', 'file': 'res1.png' }, { 'type': 'bitmap', 'name': 'MY_RES2', 'file': 'res2.png' }] } }), 'src/resources/res1.png': '', 'src/resources/res2.png': '', }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertSetEqual({f.file_name for f in project.resources.all()}, {'res1.png', 'res2.png'})
def test_throws_if_importing_array_appkeys_without_npm_manifest_support(self): """ Throw when trying to import a project with auto-assigned messageKeys before NPM manifest support is fully enabled """ bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(pebble_options={'messageKeys': []}) }) with self.assertRaises(InvalidProjectArchiveException): do_import_archive(self.project_id, bundle)
def test_import_basic_bundle_with_npm_manifest(self): """ Check that archives with package.json can be imported """ bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(package_options={'name': 'myproject'}) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(project.app_long_name, 'test') self.assertEqual(project.app_short_name, 'myproject')
def check_package_manifest(self, manifest, package_options=None, pebble_options=None): """ Check that a generated manifest file looks like a manually assembled manifest file :param manifest: Manifest to check :param package_options: root-level options to set in the 'correct' manifest file :param pebble_options: pebble-level options to set in the 'correct' manifest file """ pebble_options = {} if pebble_options is None else pebble_options pebble_options["uuid"] = str(self.project.app_uuid) compare_to = make_package(package_options=package_options, pebble_options=pebble_options) self.assertDictEqual(json.loads(manifest), json.loads(compare_to))
def test_import_package_with_resources(self): """ Check that a resource can be imported in an package.json project """ bundle = build_bundle({ 'src/main.c': '', 'resources/images/blah.png': 'contents!', 'package.json': make_package(pebble_options=RESOURCE_SPEC) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(project.resources.get().variants.get().get_contents(), 'contents!')
def test_invalid_resource_id(self): """ Check that invalid characters are banned from resource IDs """ bundle = build_bundle({ 'src/main.c': '', 'resources/images/blah.png': 'contents!', 'package.json': make_package(pebble_options=self.make_resource_spec("<>")) }) with self.assertRaises(ValidationError): do_import_archive(self.project_id, bundle)
def test_import_json_file(self): """ Check that json files are correctly imported """ bundle = build_bundle({ 'src/js/test.json': '{}', 'src/main.c': '', 'package.json': make_package() }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(project.source_files.filter(file_name='test.json').count(), 1)
def test_import_package_with_resources(self): """ Check that a resource can be imported in an package.json project """ bundle = build_bundle({ 'src/main.c': '', 'resources/images/blah.png': 'contents!', 'package.json': make_package(pebble_options=self.make_resource_spec()) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(project.resources.get().variants.get().get_contents(), 'contents!')
def test_import_json_file(self): """ Check that json files are correctly imported """ bundle = build_bundle({ 'src/js/test.json': '{}', 'src/main.c': '', 'package.json': make_package() }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual( project.source_files.filter(file_name='test.json').count(), 1)
def test_import_package_with_keywords(self): """ Check that keywords in a package.json file are imported into the database """ keywords = ['pebbles', 'watch', 'bunnies'] bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(package_options={'keywords': keywords}) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(set(keywords), set(project.keywords))
def test_import_package_with_keywords(self): """ Check that keywords in a package.json file are imported into the database """ keywords = ['pebbles', 'watch', 'bunnies'] bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(package_options={ 'keywords': keywords }) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(set(keywords), set(project.keywords))
def test_import_rocky(self): """ Check that json files are correctly imported """ bundle = build_bundle({ 'src/rocky/index.js': '', 'src/common/lib.js': '', 'src/pkjs/app.js': '', 'package.json': make_package(pebble_options={'projectType': 'rocky'}) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual(project.source_files.filter(file_name='index.js', target='app').count(), 1) self.assertEqual(project.source_files.filter(file_name='lib.js', target='common').count(), 1) self.assertEqual(project.source_files.filter(file_name='app.js', target='pkjs').count(), 1)
def check_package_manifest(self, manifest, package_options=None, pebble_options=None): """ Check that a generated manifest file looks like a manually assembled manifest file :param manifest: Manifest to check :param package_options: root-level options to set in the 'correct' manifest file :param pebble_options: pebble-level options to set in the 'correct' manifest file """ pebble_options = {} if pebble_options is None else pebble_options pebble_options['uuid'] = str(self.project.app_uuid) compare_to = make_package(package_options=package_options, pebble_options=pebble_options) self.assertDictEqual(json.loads(manifest), json.loads(compare_to))
def test_import_basic_library(self): """ Try importing a basic library """ bundle = build_bundle({ 'include/my-lib.h': '', 'package.json': make_package(pebble_options={'projectType': 'package'}), 'src/c/my-lib.c': '', 'src/c/my-priv.h': '', }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) files = {f.file_name: f for f in project.source_files.all()} self.assertSetEqual(set(files.keys()), {'my-lib.h', 'my-lib.c', 'my-priv.h'}) self.assertEqual(files['my-lib.h'].target, 'public') self.assertEqual(files['my-lib.c'].target, 'app') self.assertEqual(files['my-priv.h'].target, 'app')
def make_custom_manifests(messageKeys): # We want to specify as many optional options as possible, in the hope that they all get exported # identically after being imported. npm_options = { 'package_options': { 'dependencies': {'some_package': '11.11.0'}, 'keywords': ['earth', 'wind', 'fire', 'water'], }, 'pebble_options': { 'messageKeys': messageKeys } } appinfo_options = { 'appKeys': messageKeys } return make_package(**npm_options), make_appinfo(appinfo_options)
def test_import_package_with_dependencies(self): """ Check that dependencies in a package.json file are imported into the database """ deps = { 'some_package': '3.14.15', 'another': 'http://blah.com/package.git', } bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(package_options={'dependencies': deps}) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) actual_deps = {d.name: d.version for d in project.dependencies.all()} self.assertDictEqual(actual_deps, deps)
def make_custom_manifests(messageKeys): # We want to specify as many optional options as possible, in the hope that they all get exported # identically after being imported. npm_options = { 'package_options': { 'dependencies': { 'some_package': '11.11.0' }, 'keywords': ['earth', 'wind', 'fire', 'water'], }, 'pebble_options': { 'messageKeys': messageKeys } } appinfo_options = {'appKeys': messageKeys} return make_package(**npm_options), make_appinfo(appinfo_options)
def test_import_package_with_dependencies(self): """ Check that dependencies in a package.json file are imported into the database """ deps = { 'some_package': '3.14.15', 'another': 'http://blah.com/package.git', } bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(package_options={ 'dependencies': deps }) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) actual_deps = {d.name: d.version for d in project.dependencies.all()} self.assertDictEqual(actual_deps, deps)
def test_throws_with_local_file_dependencies(self): """ Throw if any dependencies reference local files """ bad_versions = [ 'file:security/breach', '/security/breach', './security/breach', '../security/breach', '~/security/breach' ] for version in bad_versions: bundle = build_bundle({ 'src/main.c': '', 'package.json': make_package(package_options={ 'dependencies': {'some_package': version} }) }) with self.assertRaises(ValidationError): do_import_archive(self.project_id, bundle)
def test_import_library_with_resources(self): """ Try importing a basic library with resources """ bundle = build_bundle({ 'package.json': make_package(pebble_options={ 'projectType': 'package', 'resources': {'media': [{ 'type': 'bitmap', 'name': 'MY_RES1', 'file': 'res1.png' }, { 'type': 'bitmap', 'name': 'MY_RES2', 'file': 'res2.png' }]} }), 'src/resources/res1.png': '', 'src/resources/res2.png': '', }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertSetEqual({f.file_name for f in project.resources.all()}, {'res1.png', 'res2.png'})
def test_import_rocky(self): """ Check that json files are correctly imported """ bundle = build_bundle({ 'src/rocky/index.js': '', 'src/common/lib.js': '', 'src/pkjs/app.js': '', 'package.json': make_package(pebble_options={'projectType': 'rocky'}) }) do_import_archive(self.project_id, bundle) project = Project.objects.get(pk=self.project_id) self.assertEqual( project.source_files.filter(file_name='index.js', target='app').count(), 1) self.assertEqual( project.source_files.filter(file_name='lib.js', target='common').count(), 1) self.assertEqual( project.source_files.filter(file_name='app.js', target='pkjs').count(), 1)