def test_prepare_package_missing(): 'Tests that the prepare_package function fails when file is not found' err = ErrorBundle() submain.prepare_package(err, 'foo/bar/asdf/qwerty.xyz') assert err.failed()
def test_prepare_package(test_package): """Tests that the prepare_package does not raise any errors when given a valid add-on.""" err = ErrorBundle() submain.prepare_package(err, 'tests/resources/main/foo.xpi') assert not err.failed()
def test_prepare_package_bad_file(): 'Tests that the prepare_package function fails for unknown files' err = ErrorBundle() submain.prepare_package(err, 'tests/resources/main/foo.bar') assert err.failed()
def test_prepare_package_missing(): "Tests that the prepare_package function fails when file is not found" err = ErrorBundle(None, True) submain.prepare_package(err, "foo/bar/asdf/qwerty.xyz") assert err.failed() assert err.reject
def test_prepare_package_bad_file(): "Tests that the prepare_package function fails for unknown files" err = ErrorBundle(None, True) submain.prepare_package(err, "tests/resources/main/foo.bar") assert err.failed() assert err.reject
def test_prepare_package_extension(): "Tests that bad extensions get outright rejections" assert submain.prepare_package(None, "foo/bar/test.foo") == False ts = submain.test_search submain.test_search = lambda x, y, z: True assert submain.prepare_package(None, "foo/bar/test.xml") == True submain.test_search = ts
def test_validation_timeout(): tp = submain.test_inner_package def slow(*args, **kw): time.sleep(1) submain.test_inner_package = slow err = ErrorBundle() submain.prepare_package(err, "tests/resources/main/foo.xpi", timeout=0.1) submain.test_inner_package = tp assert len(err.errors) == 1
def test_prepare_package_webapp(): _orig = submain.test_webapp calls = {'x': 0} submain.test_webapp = lambda err, y, z: calls.update(x=1) try: err = ErrorBundle() submain.prepare_package(err, "tests/resources/main/mozball.webapp", expectation=PACKAGE_WEBAPP) assert not err.failed() assert calls['x'] == 1, "test_webapp() was not called" finally: submain.test_webapp = _orig
def test_prepare_package_xml(test_search): 'Tests that the prepare_package function passes with search providers' err = ErrorBundle() submain.prepare_package(err, 'tests/resources/main/foo.xml') assert not err.failed() assert test_search.called test_search.side_effect = lambda err, *args: err.error(('x'), 'Failed') submain.prepare_package(err, 'tests/resources/main/foo.xml') assert err.failed()
def test_validation_timeout(test_package): def slow(*args, **kw): time.sleep(1) test_package.side_effect = slow err = ErrorBundle() err.error(("an", "error"), "occurred") submain.prepare_package(err, "tests/resources/main/foo.xpi", timeout=0.1) # Make sure that our error got moved to the front of the list. eq_(len(err.errors), 2) eq_(err.errors[0]["id"], ("validator", "unexpected_exception", "validation_timeout"))
def test_validation_timeout(test_package): def slow(*args, **kw): time.sleep(1) test_package.side_effect = slow err = ErrorBundle() err.error(('an', 'error'), 'occurred') submain.prepare_package(err, 'tests/resources/main/foo.xpi', timeout=0.1) # Make sure that our error got moved to the front of the list. assert len(err.errors) == 2 assert err.errors[0]['id'] == ('validator', 'unexpected_exception', 'validation_timeout')
def test_validation_error(log, test_package): """Test that an unexpected exception during validation is turned into an error message and logged.""" test_package.side_effect = Exception err = ErrorBundle() err.error(('an', 'error'), 'occurred') submain.prepare_package(err, 'tests/resources/main/foo.xpi') assert log.error.called # Make sure that our error got moved to the front of the list. assert len(err.errors) == 2 assert err.errors[0]['id'] == ('validator', 'unexpected_exception')
def test_prepare_package_xml(): "Tests that the prepare_package function passes with search providers" smts = submain.test_search submain.test_search = lambda err, y, z: True err = ErrorBundle() submain.prepare_package(err, "tests/resources/main/foo.xml") assert not err.failed() submain.test_search = lambda err, y, z: err.error(("x"), "Failed") submain.prepare_package(err, "tests/resources/main/foo.xml") assert err.failed() submain.test_search = smts
def test_validation_error(log, test_package): """Test that an unexpected exception during validation is turned into an error message and logged.""" test_package.side_effect = Exception err = ErrorBundle() err.error(("an", "error"), "occurred") submain.prepare_package(err, "tests/resources/main/foo.xpi") assert log.error.called # Make sure that our error got moved to the front of the list. eq_(len(err.errors), 2) eq_(err.errors[0]["id"], ("validator", "unexpected_exception"))
def test_prepare_package_xml(): "Tests that the prepare_package function passes with search providers" submain.test_search = lambda err,y,z: True err = ErrorBundle(None, True) submain.prepare_package(err, "tests/resources/main/foo.xml") assert not err.failed() assert not err.reject submain.test_search = lambda err,y,z: err.error(("x"), "Failed") submain.prepare_package(err, "tests/resources/main/foo.xml") assert err.failed() assert not err.reject # prepare_package has no authority to reject XML.
def test_prepare_package(): "Tests that the prepare_package function passes for valid data" tp = submain.test_package submain.test_package = lambda w,x,y,z: True err = ErrorBundle(None, True) assert submain.prepare_package(err, "tests/resources/main/foo.xpi") == True submain.test_package = tp
def test_prepare_package(): "Tests that the prepare_package function passes for valid data" tp = submain.test_package submain.test_package = lambda w, x, y, z, for_appversions: True err = ErrorBundle() assert submain.prepare_package(err, "tests/resources/main/foo.xpi") == True submain.test_package = tp
def test_prepare_package_extension(test_search): 'Tests that bad extensions get outright rejections.' # Files with an invalid extension raise an error prior to # calling `test_search`. err = ErrorBundle() submain.prepare_package(err, 'foo/bar/test.foo') assert not test_search.called assert len(err.errors) == 1 assert err.errors[0]['id'] == ('main', 'prepare_package', 'not_found') # Files which do not exist raise an error prior to calling `test_search`. err = ErrorBundle() submain.prepare_package(err, 'foo/bar/test.xml') assert not test_search.called assert len(err.errors) == 1 assert err.errors[0]['id'] == ('main', 'prepare_package', 'not_found')
def test_prepare_package_extension(test_search): "Tests that bad extensions get outright rejections." # Files with an invalid extension raise an error prior to # calling `test_search`. err = ErrorBundle() submain.prepare_package(err, "foo/bar/test.foo") assert not test_search.called eq_(len(err.errors), 1) eq_(err.errors[0]["id"], ("main", "prepare_package", "not_found")) # Files which do not exist raise an error prior to calling `test_search`. err = ErrorBundle() submain.prepare_package(err, "foo/bar/test.xml") assert not test_search.called eq_(len(err.errors), 1) eq_(err.errors[0]["id"], ("main", "prepare_package", "not_found"))