def setUp(self, mocked_now): self.initials = dict(self.initials) self.initials.update(action_template=False) mocked_now.return_value = now1 super().setUp() with self.app2_context: mocked_now.return_value = now2 soft = Software(id='aaaaaaaa-1234-5678-1234-56781234aaa1', name='test', version='1', filename='file') at = ActionTemplate(id='aaaaaaaa-1234-5678-1234-56781234aaa2', name='mkdir', version=1, action_type=ActionType.SHELL, code='mkdir {dir}') db.session.add_all([soft, at]) db.session.commit() mocked_now.return_value = now3 ssa = SoftwareServerAssociation(software=soft, server=Server.get_current(), path='/root') db.session.add(ssa) db.session.commit() self.soft_json = soft.to_json() self.at_json = at.to_json() self.catalog = fetch_catalog(now1) self.mock_queue = mock.Mock() self.mock_dm = mock.Mock() self.mock_dm.flask_app = self.app self.mock_dm.engine = db.engine self.mock_dm.manager.dict.return_value = dict() self.mock_dm.server_id = self.s1.id self.cm = CatalogManager("Catalog", startup_event=threading.Event(), shutdown_event=threading.Event(), publish_q=self.mock_queue, event_q=None, dimensigon=self.mock_dm) db.session.commit()
class TestSoftwareList(TestResourceBase): def fill_database(self): self.soft1 = Software(id='11111111-2222-3333-4444-555555550001', name='Dimensigon', version='0.0.1', filename='Dimensigon_0.0.1.tar.gz') self.soft2 = Software(id='11111111-2222-3333-4444-555555550002', name='Dimensigon', version='0.0.2', filename='Dimensigon_0.0.2.tar.gz') self.soft3 = Software(id='11111111-2222-3333-4444-555555550003', name='python', version='3.6.8', filename='python_3.6.8.x64.tar.gz') db.session.add_all([self.soft1, self.soft2, self.soft3]) def test_get(self): resp = self.client.get(url_for('api_1_0.softwarelist'), headers=self.auth.header) self.assertListEqual([ self.soft1.to_json(no_delete=False), self.soft2.to_json(no_delete=False), self.soft3.to_json(no_delete=False) ], resp.get_json()) def test_get_with_filter(self): resp = self.client.get(url_for('api_1_0.softwarelist', **{'filter[name]': 'Dimensigon'}), headers=self.auth.header) self.assertListEqual([ self.soft1.to_json(no_delete=False), self.soft2.to_json(no_delete=False) ], resp.get_json()) def test_get_with_filter2(self): resp = self.client.get(url_for('api_1_0.softwarelist', **{'filter[version]': '0.0.1,3.6.8'}), headers=self.auth.header) self.assertListEqual([ self.soft1.to_json(no_delete=False), self.soft3.to_json(no_delete=False) ], resp.get_json()) def test_post(self): size = os.path.getsize(__file__) checksum = md5(__file__) filename = os.path.basename(__file__) data = dict(name="Dimensigon", version="0.0.3", family='middleware', file=__file__) resp = self.client.post(url_for('api_1_0.softwarelist'), headers=self.auth.header, json=data) self.assertEqual(201, resp.status_code) soft = Software.query.filter_by(name="Dimensigon", version="0.0.3").one() self.assertEqual(size, soft.size) self.assertEqual(checksum, soft.checksum) self.assertEqual(filename, soft.filename) self.assertEqual(1, len(soft.ssas)) ssa = soft.ssas[0] self.assertEqual(os.path.dirname(__file__), ssa.path)