def test_incorrect_firmware_build(self): architecture = Architecture.find('88f6281', syno=True) build = BuildFactory(active=True, version__report_url=None, architectures=[architecture], firmware=Firmware.find(1594)) db.session.commit() self.assertEqual(Download.query.count(), 0) response = self.client.get(url_for('nas.download', architecture_id=architecture.id, firmware_build=1593, build_id=build.id)) self.assert400(response) self.assertEqual(Download.query.count(), 0)
def test_not_stable_build_not_active_stable(self): BuildFactory(active=False, version__report_url=None, architectures=[Architecture.find('88f6281', syno=True)], firmware=Firmware.find(1594)) db.session.commit() data = dict(arch='88f6281', build='1594', language='enu', package_update_channel='beta') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 0)
def test_stable_build_active_stable_qinst(self): build = BuildFactory(active=True, version__report_url=None, version__license=None, version__install_wizard=False, architectures=[Architecture.find('88f6281', syno=True)], firmware=Firmware.find(1594)) db.session.commit() data = dict(arch='88f6281', build='1594', language='enu') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertCatalogEntry(catalog[0], build, data, dict(arch='88f628x', build='1594'))
def test_stable_build_active_stable(self): build = BuildFactory( active=True, version__report_url=None, architectures=[Architecture.find('88f6281', syno=True)], firmware=Firmware.find(1594)) db.session.commit() data = dict(arch='88f6281', build='1594', language='enu') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertCatalogEntry(catalog[0], build, data, dict(arch='88f628x', build='1594'))
def test_incorrect_firmware_build(self): architecture = Architecture.find('88f6281', syno=True) build = BuildFactory(active=True, version__report_url=None, architectures=[architecture], firmware=Firmware.find(1594)) db.session.commit() self.assertEqual(Download.query.count(), 0) response = self.client.get( url_for('nas.download', architecture_id=architecture.id, firmware_build=1593, build_id=build.id)) self.assert400(response) self.assertEqual(Download.query.count(), 0)
def test_stable_build_not_active_not_stable(self): BuildFactory( active=False, architectures=[Architecture.find("88f6281", syno=True)], firmware=Firmware.find(1594), ) db.session.commit() data = dict( arch="88f6281", build="1594", language="enu", package_update_channel="beta" ) response = self.client.post(url_for("nas.catalog"), data=data) self.assert200(response) self.assertHeader(response, "Content-Type", "application/json") catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 0)
def test_stable_build_active_stable(self): build = BuildFactory( active=True, version__report_url=None, architectures=[Architecture.find("88f6281", syno=True)], firmware=Firmware.find(1594), ) db.session.commit() data = dict(arch="88f6281", build="1594", language="enu") response = self.client.post(url_for("nas.catalog"), data=data) self.assert200(response) self.assertHeader(response, "Content-Type", "application/json") catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertCatalogEntry(catalog[0], build, data, dict(arch="88f628x", build="1594"))
def test_generic(self): architecture = Architecture.find('88f6281', syno=True) build = BuildFactory(active=True, version__report_url=None, architectures=[architecture], firmware=Firmware.find(1594)) db.session.commit() self.assertEqual(Download.query.count(), 0) response = self.client.get(url_for('nas.download', architecture_id=architecture.id, firmware_build=4458, build_id=build.id), environ_base={'REMOTE_ADDR': '127.0.0.1'}, headers={'User-Agent': 'My User Agent'}) self.assert302(response) self.assertEqual(Download.query.count(), 1) download = Download.query.first() self.assertEqual(download.ip_address, '127.0.0.1') self.assertEqual(download.user_agent, 'My User Agent') self.assertEqual(download.firmware_build, 4458) self.assertAlmostEqual(download.date, datetime.utcnow().replace(microsecond=0), delta=timedelta(seconds=10))
def test_incorrect_architecture(self): architecture = Architecture.find("88f6281", syno=True) build = BuildFactory( active=True, version__report_url=None, architectures=[architecture], firmware=Firmware.find(1594), ) db.session.commit() self.assertEqual(Download.query.count(), 0) response = self.client.get( url_for( "nas.download", architecture_id=Architecture.find("cedarview").id, firmware_build=4458, build_id=build.id, )) self.assert400(response) self.assertEqual(Download.query.count(), 0)
def test_generic(self): architecture = Architecture.find('88f6281', syno=True) build = BuildFactory(active=True, version__report_url=None, architectures=[architecture], firmware=Firmware.find(1594)) db.session.commit() self.assertEqual(Download.query.count(), 0) response = self.client.get(url_for('nas.download', architecture_id=architecture.id, firmware_build=4458, build_id=build.id), environ_base={'REMOTE_ADDR': '127.0.0.1'}, headers={'User-Agent': 'My User Agent'}) self.assert302(response) self.assertEqual(Download.query.count(), 1) download = Download.query.first() self.assertEqual(download.ip_address, '127.0.0.1') self.assertEqual(download.user_agent, 'My User Agent') self.assertEqual(download.firmware_build, 4458) self.assertAlmostEqual(download.date, datetime.utcnow().replace(microsecond=0), delta=timedelta(seconds=10))
def test_stable_build_active_stable_download_count(self): package = PackageFactory() build = BuildFactory(active=True, version__report_url=None, version__package=package, architectures=[Architecture.find('cedarview')], firmware=Firmware.find(1594)) DownloadFactory.create_batch(1, build=build, date=datetime.now()) DownloadFactory.create_batch(2, build=build, date=datetime.now() - timedelta(days=30)) DownloadFactory.create_batch(4, build=build, date=datetime.now() - timedelta(days=100)) db.session.commit() data = dict(arch='cedarview', build='1594', language='enu') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertEqual(catalog[0]['download_count'], 7) self.assertEqual(catalog[0]['recent_download_count'], 3)
def test_stable_build_active_stable_null_data(self): build = BuildFactory( active=True, version__report_url=None, version__changelog=None, version__distributor=None, version__distributor_url=None, version__maintainer=None, version__maintainer_url=None, version__service_dependencies=[], version__dependencies=None, version__conflicts=None, version__package__add_screenshot=False, architectures=[Architecture.find('88f6281', syno=True)], firmware=Firmware.find(1594)) db.session.commit() data = dict(arch='88f6281', build='1594', language='enu') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertCatalogEntry(catalog[0], build, data, dict(arch='88f628x', build='1594'))
def test_stable_build_active_stable_null_data(self): build = BuildFactory(active=True, version__report_url=None, version__changelog=None, version__distributor=None, version__distributor_url=None, version__maintainer=None, version__maintainer_url=None, version__service_dependencies=[], version__dependencies=None, version__conflicts=None, version__package__add_screenshot=False, architectures=[Architecture.find('88f6281', syno=True)], firmware=Firmware.find(1594)) db.session.commit() data = dict(arch='88f6281', build='1594', language='enu') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertCatalogEntry(catalog[0], build, data, dict(arch='88f628x', build='1594'))
def test_stable_build_active_stable_download_count(self): package = PackageFactory() build = BuildFactory(active=True, version__report_url=None, version__package=package, architectures=[Architecture.find('cedarview')], firmware=Firmware.find(1594)) DownloadFactory.create_batch(1, build=build, date=datetime.now()) DownloadFactory.create_batch(2, build=build, date=datetime.now() - timedelta(days=30)) DownloadFactory.create_batch(4, build=build, date=datetime.now() - timedelta(days=100)) db.session.commit() data = dict(arch='cedarview', build='1594', language='enu') response = self.client.post(url_for('nas.catalog'), data=data) self.assert200(response) self.assertHeader(response, 'Content-Type', 'application/json') catalog = json.loads(response.data.decode(response.charset)) self.assertEqual(len(catalog), 1) self.assertEqual(catalog[0]['download_count'], 7) self.assertEqual(catalog[0]['recent_download_count'], 3)