def process_item(self, item, spider): session = self.session() if not item['name'] or not item['phone']: return item # get company by phone number company = session.query(Company).filter( Company.phone == item['phone']).first() if not company: company = Company() company.name = item["name"] company.categories = item["categories"] company.phone = item["phone"] company.reviews = item["reviews"] company.website = item["website"] company.address = item["address"] company.schedule = item["schedule"] company.image = item['images'][0]['path'] try: session.add(company) session.commit() except: session.rollback() raise finally: session.close() return item
def test_company_has_portfolio(self): tech = Portfolio(name='tech') arbor = Company(name='Arbor Realty Trust', symbol='ABR', portfolio='low risk') assert seattle.portfolio.name == 'tech'
def company(session, portfolio): """Testable Company database table.""" company = Company(name='Google', symbol='goog', portfolio_id=portfolio.id) session.add(company) session.commit() return company
def test_port_has_co(self): blue = Portfolio(name='blue') cf = Company( name='Code Fellows', symbol='CF', exchange='Some Exchange', description='We learn more faster', portfolio=blue ) fc = Company( name='Mirror Universe Code Fellows', symbol='FC', exchange='Exchange Some', description='We forget less slower', portfolio=blue ) assert blue.companies[0].symbol == 'CF' assert blue.companies[1].symbol == 'FC'
def company(session, portfolio): company = Company(name='Code Fellows', symbol='CF', exchange='Some Exchange', description='We learn more faster', portfolio=portfolio) session.add(company) session.commit() return company
def company(session, portfolio): company = Company(name='Microsoft', portfolio_id=portfolio.id, company_sym='MSFT', website='www.microsoft.com', sector='TECH', industry='PROGRAMMING') session.add(company) session.commit() return company
def test_create_city_again(self, session): company = Company(name='Google', symbol='goog') session.add(company) session.commit() assert company.id > 0 company = Company.query.all() assert len(company) == 1
def test_co_has_port(self): red = Portfolio(name='red') cf = Company( name='Code Fellows', symbol='CF', exchange='Some Exchange', description='We learn more faster', portfolio=red ) assert cf.portfolio.name == 'red'
def company(session, portfolio): """ """ # company = Company(name='ADT Inc.', symbol='ADT', portfolio_id=portfolio_id) company = Company(name='ADT Inc.', symbol='ADT', portfolio=portfolio) session.add(company) session.commit() return company
def save_object(self, obj, context, session=None): user_data = context.user_data company = Company() company.name = user_data[self.menu_name]['name'] company.year = user_data[self.menu_name]['year'] company.phone = user_data[self.menu_name]['phone'] company.employees_quantity = user_data[ self.menu_name]['employees_quantity'] obj.companies.append(company) obj.date = user_data[self.menu_name]['date'] obj.amount = user_data[self.menu_name]['amount'] if not add_to_db([obj, company], session): return self.conv_fallback(context)
def save_object(self, obj, context, session=None): user_data = context.user_data payment = Payment() company = Company() company.name = user_data[self.menu_name]['name'] company.year = user_data[self.menu_name]['year'] company.phone = user_data[self.menu_name]['phone'] company.employees_quantity = user_data[ self.menu_name]['employees_quantity'] payment.companies.append(company) payment.date = user_data[self.menu_name]['date'] payment.amount = user_data[self.menu_name]['amount'] payment.taxation_service = self.parent.parent.selected_object(context) if not add_to_db([payment, company], session): return self.conv_fallback(context)
def test_portfolio_has_symbols(self): tech = Portfolio(name='tech') adt = Company(name='ADT Inc.', symbol='adt', category=tech) assert tech.companies[0].name == 'ADT Inc.'