def test_good_attribute_is_working_properly(self): """testing if the good attribute value can be properly set """ g1 = Good(name='Good1') g2 = Good(name='Good2') g3 = Good(name='Good3') test_value = [g1, g2, g3] p = PriceList(**self.kwargs) assert p.goods != test_value p.goods = test_value assert p.goods == test_value
def test_good_argument_is_working_properly(self): """testing if the good argument value is properly passed to the good attribute """ g1 = Good(name='Good1') g2 = Good(name='Good2') g3 = Good(name='Good3') test_value = [g1, g2, g3] self.kwargs['goods'] = test_value p = PriceList(**self.kwargs) assert p.goods == test_value
def test_cost_attribute_value_will_be_copied_from_the_supplied_good_argument(self): """testing if the cost attribute value will be copied from the supplied good argument value """ good = Good(name='Some Good', cost=10, msrp=20, unit='$/hour') entry = BudgetEntry(budget=self.test_budget, good=good) self.assertEqual(entry.cost, good.cost)
def test_good_attribute_is_working_properly(self): """testing if the good attribute can be correctly set """ test_value = Good(name='Some Other Good') entry = BudgetEntry(budget=self.test_budget, good=self.test_good, amount=53) self.assertNotEqual(entry.good, test_value) entry.good = test_value self.assertEqual(entry.good, test_value)
def test_good_argument_is_working_properly(self): """testing if the good argument value is correctly passed to the good attribute """ test_value = Good(name='Some Good') entry = BudgetEntry( budget=self.test_budget, good=test_value, amount=53, ) self.assertEqual(entry.good, test_value)
def test_goods_attribute_is_not_a_list(self): """testing if a TypeError will be raised when the goods attribute is set to a value other than a list """ g1 = Good(name='Test Good') self.kwargs['goods'] = [g1] p = PriceList(**self.kwargs) with pytest.raises(TypeError) as cm: p.goods = 'this is not a list' assert str(cm.value) == \ 'Incompatible collection type: str is not list-like'
def create_good(request): """creates a new Good """ logger.debug('***create good method starts ***') logged_in_user = get_logged_in_user(request) utc_now = local_to_utc(datetime.datetime.now()) came_from = request.params.get('came_from', '/') name = request.params.get('name', None) msrp = request.params.get('msrp', None) unit = request.params.get('unit', None) cost = request.params.get('cost', None) price_list_name = request.params.get('price_list_name', None) logger.debug('came_from : %s' % came_from) logger.debug('name : %s' % name) logger.debug('msrp : %s' % msrp) logger.debug('unit : %s' % unit) logger.debug('cost : %s' % cost) logger.debug('price_list_name : %s' % price_list_name) # create and add a new good if name and msrp and unit and cost and price_list_name: price_list = query_price_list(price_list_name) try: # create the new group new_good = Good(name=name, msrp=int(msrp), unit=unit, cost=int(cost), price_lists=[price_list]) new_good.created_by = logged_in_user new_good.date_created = utc_now new_good.date_updated = utc_now new_good.price_lists = [price_list] DBSession.add(new_good) logger.debug('added new good successfully') request.session.flash('success:Good <strong>%s</strong> is ' 'created successfully' % name) logger.debug('***create good method ends ***') except BaseException as e: request.session.flash('error: %s' % e) HTTPFound(location=came_from) else: logger.debug('not all parameters are in request.params') transaction.abort() return Response('There are missing parameters: ' 'name: %s' % name, 500) return Response('successfully created %s!' % name)
def test_good_attribute_is_set_to_None(self): """testing if a TypeError will be raised if the good attribute is set to None """ entry = BudgetEntry(budget=self.test_budget, good=Good(name='Some Good'), amount=53) with pytest.raises(TypeError) as cm: entry.good = None assert str(cm.value) == \ 'BudgetEntry.good should be a stalker.models.budget.Good ' \ 'instance, not NoneType'
def test_goods_attribute_is_None(self): """testing if a TypeError will be raised when the goods attribute is set to None """ g1 = Good(name='Test Good') self.kwargs['goods'] = [g1] p = PriceList(**self.kwargs) assert p.goods == [g1] with pytest.raises(TypeError) as cm: p.goods = None assert str(cm.value) == \ 'Incompatible collection type: None is not list-like'
def test_good_attribute_is_set_to_None(self): """testing if a TypeError will be raised if the good attribute is set to None """ entry = BudgetEntry(budget=self.test_budget, good=Good(name='Some Good'), amount=53) with self.assertRaises(TypeError) as cm: entry.good = None self.assertEqual( str(cm.exception), 'BudgetEntry.good should be a stalker.models.budget.Good instance,' ' not NoneType')
def test_goods_attribute_is_None(self): """testing if a TypeError will be raised when the goods attribute is set to None """ g1 = Good(name='Test Good') self.kwargs['goods'] = [g1] p = PriceList(**self.kwargs) self.assertEqual(p.goods, [g1]) with self.assertRaises(TypeError) as cm: p.goods = None self.assertEqual( str(cm.exception), 'Incompatible collection type: None is not list-like')
def setUp(self): """run once """ defaults.timing_resolution = datetime.timedelta(hours=1) # create a new session db.setup({ 'sqlalchemy.url': 'sqlite://', 'sqlalchemy.echo': False }) db.init() self.status_wfd = Status.query.filter_by(code="WFD").first() self.status_rts = Status.query.filter_by(code="RTS").first() self.status_wip = Status.query.filter_by(code="WIP").first() self.status_prev = Status.query.filter_by(code="PREV").first() self.status_hrev = Status.query.filter_by(code="HREV").first() self.status_drev = Status.query.filter_by(code="DREV").first() self.status_oh = Status.query.filter_by(code="OH").first() self.status_stop = Status.query.filter_by(code="STOP").first() self.status_cmpl = Status.query.filter_by(code="CMPL").first() self.status_new = Status.query.filter_by(code='NEW').first() self.status_app = Status.query.filter_by(code='APP').first() self.budget_status_list = StatusList( name='Budget Statuses', target_entity_type='Budget', statuses=[self.status_new, self.status_prev, self.status_app] ) db.DBSession.add(self.budget_status_list) self.task_status_list = StatusList.query\ .filter_by(target_entity_type='Task').first() self.test_project_status_list = StatusList( name="Project Statuses", statuses=[self.status_wip, self.status_prev, self.status_cmpl], target_entity_type=Project, ) self.test_movie_project_type = Type( name="Movie Project", code='movie', target_entity_type=Project, ) self.test_repository_type = Type( name="Test Repository Type", code='test', target_entity_type=Repository, ) self.test_repository = Repository( name="Test Repository", type=self.test_repository_type, linux_path=tempfile.mkdtemp(), windows_path=tempfile.mkdtemp(), osx_path=tempfile.mkdtemp() ) self.test_user1 = User( name="User1", login="******", email="*****@*****.**", password="******" ) self.test_user2 = User( name="User2", login="******", email="*****@*****.**", password="******" ) self.test_user3 = User( name="User3", login="******", email="*****@*****.**", password="******" ) self.test_user4 = User( name="User4", login="******", email="*****@*****.**", password="******" ) self.test_user5 = User( name="User5", login="******", email="*****@*****.**", password="******" ) self.test_project = Project( name="Test Project1", code='tp1', type=self.test_movie_project_type, status_list=self.test_project_status_list, repository=self.test_repository ) self.kwargs = { 'project': self.test_project, 'name': 'Test Budget 1' } self.test_budget = Budget(**self.kwargs) self.test_good = Good( name='Some Good', cost=100, msrp=120, unit='$' )
def setUp(self): """run once """ super(BudgetTestBase, self).setUp() from stalker import db, Status self.status_wfd = Status.query.filter_by(code="WFD").first() self.status_rts = Status.query.filter_by(code="RTS").first() self.status_wip = Status.query.filter_by(code="WIP").first() self.status_prev = Status.query.filter_by(code="PREV").first() self.status_hrev = Status.query.filter_by(code="HREV").first() self.status_drev = Status.query.filter_by(code="DREV").first() self.status_oh = Status.query.filter_by(code="OH").first() self.status_stop = Status.query.filter_by(code="STOP").first() self.status_cmpl = Status.query.filter_by(code="CMPL").first() self.status_new = Status.query.filter_by(code='NEW').first() self.status_app = Status.query.filter_by(code='APP').first() from stalker import StatusList self.budget_status_list = StatusList( name='Budget Statuses', target_entity_type='Budget', statuses=[self.status_new, self.status_prev, self.status_app]) db.DBSession.add(self.budget_status_list) self.task_status_list = StatusList.query\ .filter_by(target_entity_type='Task').first() self.test_project_status_list = StatusList( name="Project Statuses", statuses=[self.status_wip, self.status_prev, self.status_cmpl], target_entity_type='Project', ) db.DBSession.add(self.test_project_status_list) from stalker import Type self.test_movie_project_type = Type( name="Movie Project", code='movie', target_entity_type='Project', ) db.DBSession.add(self.test_movie_project_type) self.test_repository_type = Type( name="Test Repository Type", code='test', target_entity_type='Repository', ) db.DBSession.add(self.test_repository_type) from stalker import Repository self.test_repository = Repository(name="Test Repository", type=self.test_repository_type, linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/') db.DBSession.add(self.test_repository) from stalker import User self.test_user1 = User(name="User1", login="******", email="*****@*****.**", password="******") db.DBSession.add(self.test_user1) self.test_user2 = User(name="User2", login="******", email="*****@*****.**", password="******") db.DBSession.add(self.test_user2) self.test_user3 = User(name="User3", login="******", email="*****@*****.**", password="******") db.DBSession.add(self.test_user3) self.test_user4 = User(name="User4", login="******", email="*****@*****.**", password="******") db.DBSession.add(self.test_user4) self.test_user5 = User(name="User5", login="******", email="*****@*****.**", password="******") db.DBSession.add(self.test_user5) from stalker import Project self.test_project = Project(name="Test Project1", code='tp1', type=self.test_movie_project_type, status_list=self.test_project_status_list, repository=self.test_repository) db.DBSession.add(self.test_project) self.kwargs = {'project': self.test_project, 'name': 'Test Budget 1'} self.test_budget = Budget(**self.kwargs) db.DBSession.add(self.test_budget) from stalker import Good self.test_good = Good(name='Some Good', cost=100, msrp=120, unit='$') db.DBSession.add(self.test_good) db.DBSession.commit()
def setUp(self): """run once """ super(BudgetTestBase, self).setUp() from stalker import Status self.status_wfd = Status(name='Waiting For Dependency', code="WFD") self.status_rts = Status(name='Ready To Start', code="RTS") self.status_wip = Status(name='Work In Progress', code="WIP") self.status_prev = Status(name='Pending Review', code="PREV") self.status_hrev = Status(name='Has Revision', code="HREV") self.status_drev = Status(name='Dependency Has Revision', code="DREV") self.status_oh = Status(name='On Hold', code="OH") self.status_stop = Status(name='Stopped', code="STOP") self.status_cmpl = Status(name='Completed', code="CMPL") self.status_new = Status(name='New', code='NEW') self.status_app = Status(name='Approved', code='APP') from stalker import StatusList self.budget_status_list = StatusList( name='Budget Statuses', target_entity_type='Budget', statuses=[self.status_new, self.status_prev, self.status_app]) self.task_status_list = StatusList(statuses=[ self.status_wfd, self.status_rts, self.status_wip, self.status_prev, self.status_hrev, self.status_drev, self.status_cmpl ], target_entity_type='Task') self.test_project_status_list = StatusList( name="Project Statuses", statuses=[self.status_wip, self.status_prev, self.status_cmpl], target_entity_type='Project', ) from stalker import Type self.test_movie_project_type = Type( name="Movie Project", code='movie', target_entity_type='Project', ) self.test_repository_type = Type( name="Test Repository Type", code='test', target_entity_type='Repository', ) from stalker import Repository self.test_repository = Repository(name="Test Repository", type=self.test_repository_type, linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/') from stalker import User self.test_user1 = User(name="User1", login="******", email="*****@*****.**", password="******") self.test_user2 = User(name="User2", login="******", email="*****@*****.**", password="******") self.test_user3 = User(name="User3", login="******", email="*****@*****.**", password="******") self.test_user4 = User(name="User4", login="******", email="*****@*****.**", password="******") self.test_user5 = User(name="User5", login="******", email="*****@*****.**", password="******") from stalker import Project self.test_project = Project( name="Test Project1", code='tp1', type=self.test_movie_project_type, status_list=self.test_project_status_list, repository=self.test_repository, ) self.kwargs = { 'project': self.test_project, 'name': 'Test Budget 1', 'status_list': self.budget_status_list } self.test_budget = Budget(**self.kwargs) from stalker import Good self.test_good = Good(name='Some Good', cost=100, msrp=120, unit='$')