def test_get_entities_is_working_properly(self): """testing if get_entities() method is working properly """ # create a time log import datetime from stalker import db, TimeLog db.DBSession.flush() db.DBSession.commit() t1 = TimeLog(task=self.test_task1, resource=self.test_user1, start=datetime.datetime(2016, 7, 26, 16), end=datetime.datetime(2016, 7, 26, 17), created_by=self.test_user2) db.DBSession.add(t1) t2 = TimeLog(task=self.test_task1, resource=self.test_user1, start=datetime.datetime(2016, 7, 26, 17), end=datetime.datetime(2016, 7, 26, 18), created_by=self.test_user2) db.DBSession.add(t2) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() time_log_view = time_log.TimeLogViews(request) response = time_log_view.get_entities() self.maxDiff = None self.assertEqual( sorted(response.json_body), sorted([{ 'entity_type': 'TimeLog', 'id': t.id, 'name': t.name, '$ref': '/api/time_logs/%s' % t.id } for t in [t1, t2]]))
def test_get_entities_view_is_working_properly(self): """testing if get_entities() method is working properly """ from stalker import db, Tag test_tag1 = Tag(name='Test Tag 1') test_tag2 = Tag(name='Test Tag 2') test_tag3 = Tag(name='Test Tag 3') db.DBSession.add_all([test_tag1, test_tag2, test_tag3]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() tag_view = tag.TagViews(request) response = tag_view.get_entities() self.assertEqual(response.json_body, [{ 'id': t.id, '$ref': '/api/tags/%s' % t.id, 'name': t.name, 'entity_type': t.entity_type } for t in [test_tag1, test_tag2, test_tag3]])
def test_update_entity_is_working_properly(self): """testing if update_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_role1.id request.params = DummyMultiDict() request.params['name'] = 'New Role Name' request.params['description'] = 'New description' role_view = role.RoleViews(request) self.patch_logged_in_user(request) response = role_view.update_entity() from stalker import Role role_db = Role.query.get(self.test_role1.id) self.assertEqual(role_db.name, 'New Role Name') self.assertEqual(role_db.description, 'New description')
def test_get_statuses_is_working_properly(self): """testing if get_statuses() method is working properly """ from stalker import db, Status, StatusList test_status1 = Status(name='Test Status 1', code='TST1') test_status2 = Status(name='Test Status 2', code='TST2') test_status3 = Status(name='Test Status 3', code='TST3') test_status4 = Status(name='Test Status 4', code='TST4') test_status5 = Status(name='Test Status 5', code='TST5') test_status_list = StatusList( name='Test Status List', target_entity_type='Project', statuses=[test_status1, test_status2, test_status3, test_status4]) db.DBSession.add_all([ test_status1, test_status2, test_status3, test_status4, test_status5, test_status_list ]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_status_list.id status_list_view = status.StatusListViews(request) response = status_list_view.get_statuses() self.maxDiff = None self.assertEqual( sorted(response.json_body), sorted([{ 'id': s.id, '$ref': '/api/statuses/%s' % s.id, 'name': s.name, 'entity_type': s.entity_type } for s in [test_status1, test_status2, test_status3, test_status4]]))
def test_update_entity_is_working_properly(self): """testing if update_entity() method is working properly """ # create a time log import datetime start = datetime.datetime(2016, 7, 26, 16) end = datetime.datetime(2016, 7, 26, 17) new_end = datetime.datetime(2016, 7, 26, 18) from stalker import db, TimeLog db.DBSession.flush() db.DBSession.commit() t1 = TimeLog(task=self.test_task1, resource=self.test_user1, start=start, end=end, created_by=self.test_user2) db.DBSession.add(t1) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = t1.id request.params = DummyMultiDict() from stalker_pyramid.views import EntityViewBase request.params['end'] = \ EntityViewBase.milliseconds_since_epoch(new_end) self.patch_logged_in_user(request) time_log_view = time_log.TimeLogViews(request) response = time_log_view.update_entity() t1_db = TimeLog.query.filter(TimeLog.name == t1.name).first() self.assertEqual(t1_db.end, new_end)
def test_delete_entity_method_is_working_properly(self): """testing if the delete_entity() method is working properly """ from stalker import db, Entity test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) db.DBSession.commit() test_entity_db = Entity.query\ .filter(Entity.name == test_entity.name).first() self.assertIsNotNone(test_entity_db) from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_entity_db.id entity_view = entity.EntityViews(request) entity_view.delete_entity() test_entity_db = Entity.query\ .filter(Entity.name == test_entity.name).first() self.assertIsNone(test_entity_db)
def test_create_entity_with_invalid_user_id(self): """testing if create_entity() method is working properly with invalid user_id parameter """ import datetime start = datetime.datetime(2016, 4, 22, 10) end = datetime.datetime(2016, 4, 22, 16) from stalker_pyramid.testing import DummyRequest, DummyMultiDict from stalker_pyramid.views import EntityViewBase request = DummyRequest() request.params = DummyMultiDict() request.params['user_id'] = -1 request.params['start'] = \ EntityViewBase.milliseconds_since_epoch(start) request.params['end'] = EntityViewBase.milliseconds_since_epoch(end) vacation_views = vacation.VacationViews(request) from pyramid.httpexceptions import HTTPServerError with self.assertRaises(HTTPServerError) as cm: vacation_views.create_entity() self.assertEqual(str(cm.exception), 'Missing "user_id" parameter')
def test_delete_entity_method_is_working_properly(self): """testing if the delete_entity() method is working properly """ from stalker import db, ImageFormat test_image_format = ImageFormat(name='HD 1080', description='A test image format', created_by=self.admin, width=1920, height=1080) db.DBSession.add(test_image_format) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_image_format.id image_format_view = format.ImageFormatViews(request) image_format_view.delete_entity() self.assertIsNotNone(test_image_format.id) self.assertIsNone( ImageFormat.query.filter( ImageFormat.id == test_image_format.id).first())
def test_update_statuses_is_working_properly_with_post(self): """testing if update_statuses() method is working properly when the request method is POST """ from stalker import db, Status, StatusList test_status1 = Status(name='Test Status 1', code='TST1') test_status2 = Status(name='Test Status 2', code='TST2') test_status3 = Status(name='Test Status 3', code='TST3') test_status4 = Status(name='Test Status 4', code='TST4') test_status5 = Status(name='Test Status 5', code='TST5') test_status_list = StatusList( name='Test Status List', target_entity_type='Project', statuses=[test_status1, test_status2, test_status3, test_status4]) db.DBSession.add_all([ test_status1, test_status2, test_status3, test_status4, test_status5, test_status_list ]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_status_list.id self.patch_logged_in_user(request) request.params = DummyMultiDict() request.params['status_id'] = [test_status1.id, test_status5.id] request.method = 'POST' status_list_view = status.StatusListViews(request) status_list_view.update_statuses() self.maxDiff = None self.assertEqual(sorted(test_status_list.statuses), sorted([test_status1, test_status5]))
def test_get_tags_is_working_properly(self): """testing if get tags is working properly """ # create some tags from stalker import db, Tag t1 = Tag(name='tag1') t2 = Tag(name='tag2') t3 = Tag(name='tag3') # create a test entity from stalker import Entity test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) test_entity.tags = [t1, t2] db.DBSession.add_all([t1, t2, t3, test_entity]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_entity.id # get the tags of the entity entity_view = entity.EntityViews(request) response = entity_view.get_tags() expected = [{ 'id': t1.id, '$ref': '/api/tags/%s' % t1.id, 'name': 'tag1', 'entity_type': 'Tag' }, { 'id': t2.id, '$ref': '/api/tags/%s' % t2.id, 'name': 'tag2', 'entity_type': 'Tag' }] self.assertEqual(sorted(response.json_body), sorted(expected))
def test_update_entity_is_working_properly_with_post(self): """testing if update_entity() method is working properly with POST """ from stalker import db, Tag new_tag = Tag(name='Test Tag 1') db.DBSession.add(new_tag) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = new_tag.id self.patch_logged_in_user(request) request.params = DummyMultiDict() request.params['name'] = 'New Tag Name' request.params['description'] = 'This also should be updated' request.method = 'POST' tag_view = tag.TagViews(request) tag_view.update_entity() new_tag_db = Tag.query.get(new_tag.id) self.assertEqual(new_tag_db.name, 'New Tag Name') self.assertEqual(new_tag_db.description, 'This also should be updated')
def test_delete_statuses_is_working_properly_with_non_related_statuses( self): """testing if delete_statuses() method is working properly with statuses that is not in the statuses list """ from stalker import db, Status, StatusList test_status1 = Status(name='Test Status 1', code='TST1') test_status2 = Status(name='Test Status 2', code='TST2') test_status3 = Status(name='Test Status 3', code='TST3') test_status4 = Status(name='Test Status 4', code='TST4') test_status5 = Status(name='Test Status 5', code='TST5') test_status_list = StatusList( name='Test Status List', target_entity_type='Project', statuses=[test_status1, test_status2, test_status3, test_status4]) db.DBSession.add_all([ test_status1, test_status2, test_status3, test_status4, test_status5, test_status_list ]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_status_list.id request.params = DummyMultiDict() request.params['status_id'] = [test_status4.id, test_status5.id] status_list_view = status.StatusListViews(request) status_list_view.delete_statuses() self.maxDiff = None self.assertEqual(sorted(test_status_list.statuses), sorted([test_status1, test_status2, test_status3]))
def test_delete_entity_is_working_properly(self): """testing if the delete_entity() method is working properly """ from stalker import db, Status, StatusList test_status1 = Status(name='Test Status 1', code='TST1') test_status2 = Status(name='Test Status 2', code='TST2') test_status3 = Status(name='Test Status 3', code='TST3') test_status4 = Status(name='Test Status 4', code='TST4') test_status5 = Status(name='Test Status 5', code='TST5') test_status_list = StatusList( name='Status List', statuses=[test_status1, test_status2, test_status3, test_status4], target_entity_type='Project', created_by=self.admin) db.DBSession.add_all([ test_status1, test_status2, test_status3, test_status4, test_status5, test_status_list ]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_status_list.id status_list_view = status.StatusListViews(request) status_list_view.delete_entity() # normally we shouldn't need a commit # but this is a unit test and the data is not committed to the db # and that's why it is not deleted (I guess) db.DBSession.commit() test_status_list_db = StatusList.query.get(test_status_list.id) self.assertIsNone(test_status_list_db)
def test_get_entities_is_working_properly(self): """testing if get_entities() method is working properly """ from stalker import db, Status, StatusList test_status1 = Status(name='Test Status 1', code='TST1') test_status2 = Status(name='Test Status 2', code='TST2') test_status3 = Status(name='Test Status 3', code='TST3') test_status4 = Status(name='Test Status 4', code='TST4') test_status5 = Status(name='Test Status 5', code='TST5') test_status_list_1 = StatusList( name='Status List 1', statuses=[test_status1, test_status2, test_status3, test_status4], target_entity_type='Project', created_by=self.admin) db.DBSession.add_all([ test_status1, test_status2, test_status3, test_status4, test_status5, test_status_list_1 ]) db.DBSession.commit() # get the default status lists s_lists = StatusList.query.all() from stalker_pyramid.testing import DummyRequest request = DummyRequest() status_list_view = status.StatusListViews(request) response = status_list_view.get_entities() self.assertEqual(response.json_body, [{ 'id': sl.id, '$ref': '/api/status_lists/%s' % sl.id, 'name': sl.name, 'entity_type': sl.entity_type } for sl in s_lists])
def test_update_templates_is_working_properly_with_patch(self): """testing if update_templates() method is working properly with patch """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_structure1.id request.params = DummyMultiDict() request.params['template_id'] = \ [self.test_filename_template3.id] request.method = 'PATCH' structure_view = structure.StructureViews(request) response = structure_view.update_templates() from stalker import Structure structure_db = Structure.query.get(self.test_structure1.id) self.assertEqual( sorted(structure_db.templates), sorted([ self.test_filename_template1, self.test_filename_template2, self.test_filename_template3 ]))
def test_get_department_user_roles_is_working_properly(self): """testing if the get_department_user_roles() method is working properly """ self.test_department1.users = [self.test_user1, self.test_user2] from stalker import db db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = self.test_department1.id department_view = department.DepartmentViews(request) response = department_view.get_user_roles() from stalker import DepartmentUser all_dep_users = DepartmentUser.query\ .filter(DepartmentUser.department == self.test_department1)\ .all() self.maxDiff = None self.assertEqual( sorted(response.json_body), sorted([{ 'user': { 'id': du.user.id, 'name': du.user.name, 'entity_type': du.user.entity_type, '$ref': '/api/users/%s' % du.user.id }, 'role': { 'id': du.role.id, 'name': du.role.name, 'entity_type': du.role.entity_type, '$ref': '/api/roles/%s' % du.role.id } if du.role else None } for du in all_dep_users]))
def test_get_entity_is_working_properly(self): """testing if the get_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = self.test_department1.id department_view = department.DepartmentViews(request) response = department_view.get_entity() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': self.admin.id, 'name': 'admin', '$ref': '/api/users/%s' % self.admin.id, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch( self.test_department1.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( self.test_department1.date_updated), 'description': '', 'entity_type': 'Department', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % self.test_department1.id, 'length': 0 }, 'id': self.test_department1.id, 'name': 'Test Department 1', 'notes': { '$ref': '/api/entities/%s/notes' % self.test_department1.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % self.test_department1.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, 'name': 'admin', '$ref': '/api/users/%s' % self.admin.id, 'entity_type': 'User' }, 'user_roles': { '$ref': '/api/departments/%s/user_roles' % self.test_department1.id, 'length': 0 }, 'users': { '$ref': '/api/departments/%s/users' % self.test_department1.id, 'length': 0 }, })
def test_get_entity(self): """testing get_entity() is working properly """ # create a test entity from stalker import db, Entity, Type test_type = Type(name='Test User', code='testuser', target_entity_type='User') db.DBSession.add(test_type) from stalker import Link test_thumbnail = Link(full_path='/some/full/path') db.DBSession.add(test_thumbnail) import datetime date_created = datetime.datetime(2016, 6, 20, 13, 55) test_entity = Entity(name='Test Entity', description='This is a test description', created_by=self.admin, type=test_type, date_created=date_created, thumbnail=test_thumbnail) db.DBSession.add(test_entity) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_entity.id entity_view = entity.EntityViews(request) response = entity_view.get_entity() from stalker_pyramid.views import EntityViewBase import stalker expected = { 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch(date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(date_created), 'description': 'This is a test description', 'entity_type': 'Entity', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % test_entity.id, 'length': 0 }, 'id': test_entity.id, 'name': 'Test Entity', 'notes': { '$ref': '/api/entities/%s/notes' % test_entity.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % test_entity.id, 'length': 0 }, 'thumbnail': { 'id': test_thumbnail.id, '$ref': '/api/links/%s' % test_thumbnail.id, 'name': test_thumbnail.name, 'entity_type': 'Link' }, 'type': { 'id': test_entity.type_id, '$ref': '/api/types/%s' % test_entity.type_id, 'name': test_entity.type.name, 'entity_type': 'Type' }, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, } import pprint pprint.pprint(response.json_body) self.maxDiff = None self.assertEqual(response.json_body, expected)
def test_create_entity_is_working_properly(self): """testing if the create_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.params['name'] = 'New Department' request.params['description'] = 'New department description' request.params['user_id'] = [self.test_user1.id, self.test_user2.id] department_view = department.DepartmentViews(request) print('code is here 1') self.patch_logged_in_user(request) print('code is here 2') response = department_view.create_entity() print('code is here 3') from stalker import Department new_dep = Department.query\ .filter(Department.name == 'New Department')\ .first() from stalker_pyramid.views import EntityViewBase import stalker self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': self.admin.id, 'name': 'admin', '$ref': '/api/users/%s' % self.admin.id, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch(new_dep.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(new_dep.date_updated), 'description': 'New department description', 'entity_type': 'Department', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % new_dep.id, 'length': 0 }, 'id': new_dep.id, 'name': 'New Department', 'notes': { '$ref': '/api/entities/%s/notes' % new_dep.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % new_dep.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, 'name': 'admin', '$ref': '/api/users/%s' % self.admin.id, 'entity_type': 'User' }, 'user_roles': { '$ref': '/api/departments/%s/user_roles' % new_dep.id, 'length': 2 }, 'users': { '$ref': '/api/departments/%s/users' % new_dep.id, 'length': 2 }, })
def test_create_entity_is_working_properly(self): """testing if create_entity() method is working properly """ from stalker import db, User, Vacation user1 = User(name='Test User 1', login='******', email='*****@*****.**', password='******') db.DBSession.add(user1) db.DBSession.flush() import transaction transaction.commit() import datetime start = datetime.datetime(2016, 4, 22, 10) end = datetime.datetime(2016, 4, 22, 16) user1 = User.query.filter(User.login == user1.login).first() from stalker_pyramid.testing import DummyRequest, DummyMultiDict from stalker_pyramid.views import EntityViewBase request = DummyRequest() request.params = DummyMultiDict() request.params['user_id'] = user1.id request.params['start'] = \ EntityViewBase.milliseconds_since_epoch(start) request.params['end'] = EntityViewBase.milliseconds_since_epoch(end) self.patch_logged_in_user(request) vacation_views = vacation.VacationViews(request) response = vacation_views.create_entity() vac = Vacation.query.filter(Vacation.user == user1).first() self.assertEqual(vac.start, start) self.assertEqual(vac.end, end) self.assertEqual(vac.user, user1) import stalker self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch(vac.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(vac.date_created), 'description': '', 'end': EntityViewBase.milliseconds_since_epoch(vac.end), 'entity_type': 'Vacation', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % vac.id, 'length': 0 }, 'generic_text': '', 'id': vac.id, 'name': vac.name, 'stalker_version': stalker.__version__, 'start': EntityViewBase.milliseconds_since_epoch(vac.start), 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'user': { 'id': vac.user_id, '$ref': '/api/users/%s' % vac.user_id, 'name': vac.user.name, 'entity_type': 'User' } })
def test_get_entity_is_working_properly(self): """testing if get_entity() method is working properly """ from stalker import db, User, Vacation user1 = User(name='Test User 1', login='******', email='*****@*****.**', password='******') db.DBSession.add(user1) import datetime start = datetime.datetime(2016, 4, 22) end = datetime.datetime(2016, 4, 23) # get admin admin = User.query.filter(User.login == 'admin').first() vac1 = Vacation( user=user1, start=start, end=end, created_by=admin, ) db.DBSession.add(vac1) db.DBSession.commit() # get the id vac1 = Vacation.query.filter(Vacation.name == vac1.name).first() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = vac1.id vacation_views = vacation.VacationViews(request) response = vacation_views.get_entity() from stalker_pyramid.views import EntityViewBase import stalker self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': vac1.created_by.id, '$ref': '/api/users/%s' % vac1.created_by.id, 'name': vac1.created_by.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch(vac1.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(vac1.date_updated), 'description': '', 'end': EntityViewBase.milliseconds_since_epoch(vac1.end), 'entity_type': 'Vacation', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % vac1.id, 'length': 0 }, 'id': vac1.id, 'name': vac1.name, 'stalker_version': stalker.__version__, 'start': EntityViewBase.milliseconds_since_epoch(vac1.start), 'thumbnail': None, 'type': None, 'user': { 'id': vac1.user.id, '$ref': '/api/users/%s' % vac1.user.id, 'name': vac1.user.name, 'entity_type': 'User' }, 'updated_by': { 'id': vac1.updated_by.id, '$ref': '/api/users/%s' % vac1.updated_by.id, 'name': vac1.updated_by.name, 'entity_type': 'User' }, })
def test_create_entity_is_working_properly(self): """testing if create_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.params['name'] = 'New Group' request.params['description'] = 'This is a new test group' request.params['user_id'] = [self.test_user1.id, self.test_user3.id] request.params['permission'] = \ ['%s_%s_%s' % (p.access, p.action, p.class_name) for p in self.all_permissions[4:10]] request.params['created_by_id'] = self.test_user2.id group_view = group.GroupViews(request) response = group_view.create_entity() # get the new group from db import stalker from stalker import Group from stalker_pyramid.views import EntityViewBase new_group = Group.query.filter(Group.name == 'New Group').first() self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': self.test_user2.id, '$ref': '/api/users/%s' % self.test_user2.id, 'name': self.test_user2.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch(new_group.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(new_group.date_updated), 'description': 'This is a new test group', 'entity_type': 'Group', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % new_group.id, 'length': 0 }, 'generic_text': '', 'id': new_group.id, 'name': 'New Group', 'notes': { '$ref': '/api/entities/%s/notes' % new_group.id, 'length': 0 }, 'permissions': [ '%s_%s_%s' % (p.access, p.action, p.class_name) for p in self.all_permissions[4:10] ], 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % new_group.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.test_user2.id, '$ref': '/api/users/%s' % self.test_user2.id, 'name': self.test_user2.name, 'entity_type': 'User' }, 'users': { '$ref': '/api/groups/%s/users' % new_group.id, 'length': 2 } } )
def test_get_entities_is_working_properly(self): """testing if get_entities() method is working properly """ from stalker import db, User, Vacation user1 = User(name='Test User 1', login='******', email='*****@*****.**', password='******') db.DBSession.add(user1) user2 = User(name='Test User 2', login='******', email='*****@*****.**', password='******') db.DBSession.add(user2) admin = User.query.filter(User.login == 'admin').first() import datetime vac1 = Vacation(user=user1, start=datetime.datetime(2016, 4, 22), end=datetime.datetime(2016, 4, 23), created_by=admin) db.DBSession.add(vac1) vac2 = Vacation(user=user1, start=datetime.datetime(2016, 4, 24), end=datetime.datetime(2016, 4, 25), created_by=admin) db.DBSession.add(vac2) vac3 = Vacation(user=user2, start=datetime.datetime(2016, 4, 10), end=datetime.datetime(2016, 4, 12), created_by=admin) db.DBSession.add(vac3) vac4 = Vacation(user=user2, start=datetime.datetime(2016, 4, 13), end=datetime.datetime(2016, 4, 20), created_by=admin) db.DBSession.add(vac4) db.DBSession.commit() # get the id vac1 = Vacation.query.filter(Vacation.name == vac1.name).first() vac2 = Vacation.query.filter(Vacation.name == vac2.name).first() vac3 = Vacation.query.filter(Vacation.name == vac3.name).first() vac4 = Vacation.query.filter(Vacation.name == vac4.name).first() from stalker_pyramid.testing import DummyRequest request = DummyRequest() vacation_views = vacation.VacationViews(request) response = vacation_views.get_entities() self.assertEqual(response.json_body, [{ 'id': v.id, '$ref': '/api/vacations/%s' % v.id, 'name': v.name, 'entity_type': 'Vacation' } for v in [vac1, vac2, vac3, vac4]])
def test_get_entity_method_is_working_properly(self): """testing if the get_entity() method is working properly """ from stalker import db, Type test_type = Type(name='Test Type', code='TT', description='A test type', target_entity_type='Project', created_by=self.admin) db.DBSession.add(test_type) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_type.id type_view = type.TypeViews(request) response = type_view.get_entity() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'code': 'TT', 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch( test_type.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( test_type.date_updated), 'description': 'A test type', 'entity_type': 'Type', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % test_type.id, 'length': 0 }, 'id': test_type.id, 'name': 'Test Type', 'notes': { '$ref': '/api/entities/%s/notes' % test_type.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % test_type.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': self.admin.entity_type }, })
def test_get_entity_is_working_properly(self): """testing if get_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = self.test_group1.id group_view = group.GroupViews(request) response = group_view.get_entity() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch( self.test_group1.date_created ), 'date_updated': EntityViewBase.milliseconds_since_epoch( self.test_group1.date_updated ), 'description': '', 'entity_type': 'Group', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % self.test_group1.id, 'length': 0 }, 'generic_text': '', 'id': self.test_group1.id, 'name': 'Test Group', 'notes': { '$ref': '/api/entities/%s/notes' % self.test_group1.id, 'length': 0 }, 'permissions': [ 'Allow_Create_User', 'Allow_Read_User', 'Allow_Update_User', 'Deny_Delete_User' ], 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % self.test_group1.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'users': { '$ref': '/api/groups/%s/users' % self.test_group1.id, 'length': 2 } } )
def test_create_entity_method_is_working_properly(self): """testing if the create_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.params['name'] = 'Test Type' request.params['code'] = 'TT' request.params['target_entity_type'] = 'Project' request.params['description'] = 'A test type' request.params['created_by_id'] = self.admin.id type_view = type.TypeViews(request) response = type_view.create_entity() from stalker import Type test_type = Type.query.filter(Type.name == 'Test Type').first() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'code': 'TT', 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch( test_type.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( test_type.date_updated), 'description': 'A test type', 'entity_type': 'Type', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % test_type.id, 'length': 0 }, 'id': test_type.id, 'name': 'Test Type', 'notes': { '$ref': '/api/entities/%s/notes' % test_type.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % test_type.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, })
def test_get_entity_is_working_properly(self): """testing if get_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = self.test_repo1.id repo_view = repository.RepositoryViews(request) response = repo_view.get_entity() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, 'date_created': EntityViewBase.milliseconds_since_epoch( self.test_repo1.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( self.test_repo1.date_updated), 'description': '', 'entity_type': 'Repository', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % self.test_repo1.id, 'length': 0 }, 'id': self.test_repo1.id, 'linux_path': self.test_repo1.linux_path, 'name': 'Test Repo 1', 'notes': { '$ref': '/api/entities/%s/notes' % self.test_repo1.id, 'length': 0 }, 'osx_path': self.test_repo1.osx_path, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % self.test_repo1.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, 'windows_path': self.test_repo1.windows_path, })
def test_create_entity_is_working_properly(self): """testing if create_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.params['name'] = 'New Repository' request.params['windows_path'] = 'T:/new/repo/' request.params['linux_path'] = '/mnt/T/new/repo/' request.params['osx_path'] = '/Volumes/T/new/repo/' request.params['description'] = 'this is a new test repo' request.params['created_by_id'] = 3 repo_view = repository.RepositoryViews(request) self.patch_logged_in_user(request) response = repo_view.create_entity() from stalker import Repository repo_db = Repository.query\ .filter(Repository.name == 'New Repository')\ .first() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, 'date_created': EntityViewBase.milliseconds_since_epoch(repo_db.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(repo_db.date_updated), 'description': 'this is a new test repo', 'entity_type': 'Repository', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % repo_db.id, 'length': 0 }, 'id': repo_db.id, 'linux_path': '/mnt/T/new/repo/', 'name': 'New Repository', 'notes': { '$ref': '/api/entities/%s/notes' % repo_db.id, 'length': 0 }, 'osx_path': '/Volumes/T/new/repo/', 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % repo_db.id, 'length': 0 }, 'thumbnail': None, 'type': None, 'updated_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, 'windows_path': 'T:/new/repo/', })
def test_get_entity_is_working_properly(self): """testing if get_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = self.test_structure1.id structure_view = structure.StructureViews(request) response = structure_view.get_entity() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, 'custom_template': 'custom template code here', 'date_created': EntityViewBase.milliseconds_since_epoch( self.test_structure1.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( self.test_structure1.date_updated), 'description': '', 'entity_type': 'Structure', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % self.test_structure1.id, 'length': 0 }, 'id': self.test_structure1.id, 'name': 'Test Structure 1', 'notes': { '$ref': '/api/entities/%s/notes' % self.test_structure1.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % self.test_structure1.id, 'length': 0 }, 'templates': { '$ref': '/api/structures/%s/templates' % self.test_structure1.id, 'length': 2 }, 'thumbnail': None, 'type': None, 'updated_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, })
def test_create_entity_is_working_properly(self): """testing if create_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.params['name'] = 'New Structure' request.params['description'] = 'this is a new test structure' request.params['custom_template'] = 'custom template code here' request.params['template_id'] = [ self.test_filename_template1.id, self.test_filename_template2.id, self.test_filename_template3.id ] request.params['created_by_id'] = 3 structure_view = structure.StructureViews(request) self.patch_logged_in_user(request) response = structure_view.create_entity() from stalker import Structure structure_db = Structure.query\ .filter(Structure.name == 'New Structure')\ .first() import stalker from stalker_pyramid.views import EntityViewBase self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, 'custom_template': 'custom template code here', 'date_created': EntityViewBase.milliseconds_since_epoch( structure_db.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( structure_db.date_updated), 'description': 'this is a new test structure', 'entity_type': 'Structure', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % structure_db.id, 'length': 0 }, 'id': structure_db.id, 'name': 'New Structure', 'notes': { '$ref': '/api/entities/%s/notes' % structure_db.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % structure_db.id, 'length': 0 }, 'templates': { '$ref': '/api/structures/%s/templates' % structure_db.id, 'length': 3 }, 'thumbnail': None, 'type': None, 'updated_by': { 'name': 'admin', 'id': 3, 'entity_type': 'User', '$ref': '/api/users/3' }, })