def test_city_model_1(self): """Test adding City objects to and deleting City objects from the db""" with app.test_request_context(): example1 = City("id1", "name1", "state1", "region1", "companies1", "finorgs1", "people1") example2 = City("id2", "name2", "state2", "region2", "companies2", "finorgs2", "people2") cities1 = db.session.query(City).all() db.session.add(example1) db.session.add(example2) db.session.commit() cities2 = db.session.query(City).all() self.assertTrue(example1 in cities2) self.assertTrue(example2 in cities2) self.assertEqual(len(cities2), len(cities1) + 2) db.session.delete(example1) db.session.delete(example2) db.session.commit() cities3 = db.session.query(City).all() self.assertTrue(example1 not in cities3) self.assertTrue(example2 not in cities3) self.assertEqual(len(cities1), len(cities2) - 2)
def test_company_model_1(self): """Test adding Company objects to and deleting Company objects from the db""" with app.test_request_context(): example1 = Company("id", "name", "summary", "people", "city", "finorgs", "twitter", "website", "logo") example2 = Company("id2", "name2", "summary2", "people2", "city2", "finorgs2", "twitter2", "website2", "logo2") companies1 = db.session.query(Company).all() db.session.add(example1) db.session.add(example2) db.session.commit() companies2 = db.session.query(Company).all() self.assertTrue(example1 in companies2) self.assertTrue(example2 in companies2) self.assertEqual(len(companies2), len(companies1) + 2) db.session.delete(example1) db.session.delete(example2) db.session.commit() companies3 = db.session.query(Company).all() self.assertTrue(example1 not in companies3) self.assertTrue(example2 not in companies3) self.assertEqual(len(companies1), len(companies2) - 2)
def test_person_model_1(self): """Test adding Person objects to and deleting Person objects from the db""" with app.test_request_context(): example1 = Person("id1", "name1", "summary1", "city1", "companies1", "role1", "twitter1", "logo_url1") example2 = Person("id2", "name2", "summary2", "city2", "companies2", "role2", "twitter2", "logo_url2") people1 = db.session.query(Person).all() db.session.add(example1) db.session.add(example2) db.session.commit() people2 = db.session.query(Person).all() self.assertTrue(example1 in people2) self.assertTrue(example2 in people2) self.assertEqual(len(people2), len(people1) + 2) db.session.delete(example1) db.session.delete(example2) db.session.commit() people3 = db.session.query(Person).all() self.assertTrue(example1 not in people3) self.assertTrue(example2 not in people3) self.assertEqual(len(people1), len(people2) - 2)
def test_financial_org_model_1(self): """Test adding FinancialOrg objects to and deleting FinancialOrg objects from the db""" with app.test_request_context(): example1 = FinancialOrg("id", "name", "summary", "city", "companies", "twitter", "website", "logo") example2 = FinancialOrg("id2", "name2", "summary2", "city2", "companies2", "twitter2", "website2", "logo2") finorgs1 = db.session.query(FinancialOrg).all() db.session.add(example1) db.session.add(example2) db.session.commit() finorgs2 = db.session.query(FinancialOrg).all() self.assertTrue(example1 in finorgs2) self.assertTrue(example2 in finorgs2) self.assertEqual(len(finorgs2), len(finorgs1) + 2) db.session.delete(example1) db.session.delete(example2) db.session.commit() finorgs3 = db.session.query(FinancialOrg).all() self.assertTrue(example1 not in finorgs3) self.assertTrue(example2 not in finorgs3) self.assertEqual(len(finorgs3), len(finorgs2) - 2)
def set_cluster_state(cluster_id, state): logger.debug('setting cluster state {} for id = {}'.format( cluster_id, state )) with app.test_request_context(): cluster = Cluster.by_uuid(cluster_id) cluster.cluster_state = state db.session.commit()
def store_master_ip_and_password(master_ip, cluster_id): # TODO verify that master_ip is valid ip master_password = get_master_password_from_sl(master_ip, cluster_id) with app.test_request_context(): cluster = Cluster.by_uuid(cluster_id) cluster.master_ip = master_ip cluster.master_password = master_password db.session.commit()
def test_city_model_2(self): """Test querying the database by attribute using simple keywords""" with app.test_request_context(): example1 = City("id1", "name1", "state1", "region1", "companies1", "finorgs1", "people1") db.session.add(example1) db.session.commit() city = db.session.query(City).filter_by(name="name1").first() self.assertEqual(city.state, "state1") self.assertEqual(city.region, "region1") db.session.delete(example1) db.session.commit()
def test_person_model_2(self): """Test querying the database by attribute using simple keywords""" with app.test_request_context(): example1 = Person("id1", "name1", "summary1", "city1", "companies1", "role1", "twitter1", "logo_url1") db.session.add(example1) db.session.commit() person = db.session.query(Person).filter_by(name="name1").first() self.assertEqual(person.city, "city1") self.assertEqual(person.twitter, "twitter1") db.session.delete(example1) db.session.commit()
def test_financial_org_model_2(self): """Test querying the database by attribute using simple keywords""" with app.test_request_context(): example1 = FinancialOrg("id", "name", "summary", "city", "companies", "twitter", "website", "logo") db.session.add(example1) db.session.commit() finorg = db.session.query(FinancialOrg).filter_by(name="name").first() self.assertEqual(finorg.city, "city") self.assertEqual(finorg.twitter, "twitter") db.session.delete(example1) db.session.commit()
def test_company_model_2(self): """Test querying the database by attribute using simple keywords""" with app.test_request_context(): example1 = Company("id", "name", "summary", "people", "city", "finorgs", "twitter", "website", "logo") db.session.add(example1) db.session.commit() company = db.session.query(Company).filter_by(name="name").first() self.assertEqual(company.city, "city") self.assertEqual(company.twitter, "twitter") db.session.delete(example1) db.session.commit()
def get_master_password_from_sl(master_ip, cluster_id): # This function executes one time from Thread and does not have db context if master_ip == '': return '' with app.test_request_context(): # retrieve sl username and api key by cluster_id cluster = Cluster.by_uuid(cluster_id) logger.debug( 'cluster_id={}, sl_username={}, master_ip={}'.format(cluster_id, cluster.sl_username, master_ip)) client = SoftLayer.Client(username=cluster.sl_username, api_key=cluster.sl_api_key) vs_manager = SoftLayer.managers.VSManager(client) try: master_details = vs_manager.list_instances(public_ip=master_ip) if len(master_details) > 1: logger.error( 'SoftLayer API returned non-unique instance for ip = {}'.format( master_ip)) master_id = master_details[0]['id'] master_instance = vs_manager.get_instance(instance_id=master_id) master_password = \ master_instance['operatingSystem']['passwords'][0]['password'] # store password in db for faster retrieval in the future cluster.master_password = master_password db.session.commit() except Exception: master_password = '' return master_password
def test_category_4(self): """Test that category renders properly""" with app.test_request_context(): self.assertEqual(category('financialorgs') is not None, True)
def test_category_5(self): """Test that category renders properly""" with app.test_request_context(): self.assertEqual(category('nonexistent_category') is not None, True)
def test_category_3(self): """Test that category renders properly""" with app.test_request_context(): self.assertEqual(category('companies') is not None, True)
def test_about_1(self): """Test that about renders properly""" with app.test_request_context(): self.assertEqual(about() is not None, True)
def test_index_1(self): """Test that index renders properly""" with app.test_request_context(): self.assertEqual(index() is not None, True)
def setUp(self): with app.test_request_context(): db.create_all()
def test_education_1(self): """Test that education renders properly""" with app.test_request_context(): self.assertEqual(education() is not None, True)
def test_page_not_found_1(self): """Test that page_not_found 404 renders properly""" with app.test_request_context(): self.assertEqual(page_not_found('error') is not None, True)
def tearDown(self): with app.test_request_context(): db.session.remove()