def test_get_entities_is_working_properly_with_filters(self): """testing if get_entities() method is working properly with filters """ 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() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.params['target_entity_type'] = 'Project' 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 [test_status_list_1]])
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_structure1.id request.method = 'POST' request.params = DummyMultiDict() request.params['name'] = 'New Structure Name' request.params['description'] = 'New description' request.params['custom_template'] = 'New custom template code' request.params['template_id'] = [ self.test_filename_template2.id, self.test_filename_template3.id ] structure_view = structure.StructureViews(request) self.patch_logged_in_user(request) response = structure_view.update_entity() from stalker import Structure structure_db = Structure.query.get(self.test_structure1.id) self.assertEqual(structure_db.name, 'New Structure Name') self.assertEqual(structure_db.description, 'New description') self.assertEqual(structure_db.custom_template, 'New custom template code') self.assertEqual( sorted(structure_db.templates), sorted( [self.test_filename_template2, self.test_filename_template3]))
def test_update_entity_method_is_working_properly(self): """testing if the update_entity() method is working properly """ from stalker import db, ImageFormat test_image_format = ImageFormat(name='HD 1080', description='A test image format', width=1920, height=1080, pixel_aspect=1.0, print_resolution=300.0, created_by=self.admin) db.DBSession.add(test_image_format) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_image_format.id request.params = DummyMultiDict() request.params['description'] = 'New description' request.params['name'] = 'HD 720' request.params['width'] = 1280 request.params['height'] = 720 self.patch_logged_in_user(request) image_format_view = format.ImageFormatViews(request) response = image_format_view.update_entity() test_image_format_db = ImageFormat.query.get(test_image_format.id) self.assertEqual(test_image_format_db.name, 'HD 720') self.assertEqual(test_image_format_db.description, 'New description') self.assertEqual(test_image_format_db.width, 1280) self.assertEqual(test_image_format_db.height, 720)
def test_update_entity_method_is_working_properly(self): """testing if the update_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, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_type.id request.params = DummyMultiDict() request.params['description'] = 'New description' request.params['name'] = 'New Name' request.params['code'] = 'New Code' self.patch_logged_in_user(request) type_view = type.TypeViews(request) response = type_view.update_entity() test_type_db = Type.query.get(test_type.id) self.assertEqual(test_type_db.name, 'New Name') self.assertEqual(test_type_db.code, 'New Code') self.assertEqual(test_type_db.description, 'New description')
def test_create_entity_with_missing_end(self): """testing if create_entity() method is working properly with missing end parameter """ from stalker import db, User user1 = User(name='Test User 1', login='******', email='*****@*****.**', password='******') db.DBSession.add(user1) db.DBSession.commit() import datetime start = datetime.datetime(2016, 4, 22, 10) 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) 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 "end" parameter')
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_repo1.id request.params = DummyMultiDict() request.params['name'] = 'New Repo Name' request.params['description'] = 'New description' request.params['windows_path'] = 'C:/new/windows/path/' request.params['linux_path'] = '/mnt/new/linux/path/' request.params['osx_path'] = '/Volumes/new/osx/path/' repo_view = repository.RepositoryViews(request) self.patch_logged_in_user(request) response = repo_view.update_entity() from stalker import Repository repo_db = Repository.query.get(self.test_repo1.id) self.assertEqual(repo_db.name, 'New Repo Name') self.assertEqual(repo_db.description, 'New description') self.assertEqual(repo_db.windows_path, 'C:/new/windows/path/') self.assertEqual(repo_db.linux_path, '/mnt/new/linux/path/') self.assertEqual(repo_db.osx_path, '/Volumes/new/osx/path/')
def test_update_entity_is_working_properly(self): """testing if the update_entity() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_department1.id request.params = DummyMultiDict() new_name = 'New Department Name' new_description = 'New Description' request.params['name'] = new_name request.params['description'] = new_description request.params['user_id'] = [self.test_user1.id, self.test_user2.id] department_view = department.DepartmentViews(request) self.patch_logged_in_user(request) response = department_view.update_entity() from stalker import Department test_department1_db = Department.query\ .filter(Department.id == self.test_department1.id)\ .first() self.assertEqual(test_department1_db.name, new_name) self.assertEqual(test_department1_db.description, new_description) self.assertEqual(sorted(test_department1_db.users), sorted([self.test_user1, self.test_user2]))
def test_remove_tags_is_working_properly_with_non_existing_tags(self): """testing if the remove_tags() method is working properly """ # create some tags from stalker import db, Tag t1 = Tag(name='tag1') t2 = Tag(name='tag2') t3 = Tag(name='tag3') from stalker import Entity test_entity = Entity(name='Test Entity', tags=[t1, t2]) db.DBSession.add_all([t1, t2, t3, test_entity]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.method = 'DELETE' request.matchdict['id'] = test_entity.id request.params = DummyMultiDict() request.params['tag'] = ['tag3'] request.POST = request.params entity_view = entity.EntityViews(request) entity_view.remove_tags() # now query entity tags test_entity = Entity.query.filter(Entity.id == test_entity.id).first() response = [t.name for t in test_entity.tags] expected = ['tag1', 'tag2'] self.assertEqual(sorted(response), sorted(expected))
def test_update_entity_is_working_properly_with_patch(self): """testing if update_entity() method is working properly with PATCH """ from stalker import db, Tag new_tag = Tag(name='Test Tag 1') db.DBSession.add(new_tag) db.DBSession.flush() 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 = 'PATCH' 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') self.assertEqual(new_tag_db.updated_by, self.admin)
def test_remove_users_is_working_properly_with_non_related_user(self): """testing if remove_users() method is working properly with users that is not related to the department """ from stalker import db # add some users first to see if patching works self.test_department1.users = \ [self.test_user1, self.test_user2] db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_department1.id request.params = DummyMultiDict() request.params['user_id'] = [self.test_user2.id, self.test_user3.id] department_view = department.DepartmentViews(request) response = department_view.remove_users() from stalker import Department test_dep_db = Department.query\ .filter(Department.id == self.test_department1.id)\ .first() self.assertEqual(sorted(test_dep_db.users), sorted([self.test_user1]))
def test_update_entity_is_working_properly(self): """testing if update_note is working properly """ from stalker import db, Note, User test_user = User(name='Test User', login='******', email='*****@*****.**', password='******') db.DBSession.add(test_user) note1 = Note(content='This is a test note') db.DBSession.add(note1) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = note1.id request.params = DummyMultiDict() request.params['content'] = 'this is the new content' request.params['updated_by_id'] = test_user.id note_view = note.NoteViews(request) note_view.update_entity() note1 = Note.query.first() self.assertEqual(note1.content, 'this is the new content') self.assertEqual(note1.updated_by, test_user)
def test_update_entity_is_working_properly(self): """testing if update_entity() is working properly """ from stalker import db, Status test_status1 = Status(name='Test Status 1', code='TST1') db.DBSession.add(test_status1) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.params = DummyMultiDict() request.matchdict['id'] = test_status1.id self.patch_logged_in_user(request) new_name = 'New Status Name' new_code = 'NSN' new_description = 'This should also be present' request.params['name'] = new_name request.params['code'] = new_code request.params['description'] = new_description status_view = status.StatusViews(request) response = status_view.update_entity() test_status1_db = Status.query.get(test_status1.id) self.assertEqual(test_status1_db.name, new_name) self.assertEqual(test_status1_db.code, new_code) self.assertEqual(test_status1_db.description, new_description)
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_link1.id request.params = DummyMultiDict() request.params['name'] = 'New Link Name' request.params['description'] = 'New description' request.params['full_path'] = '/new/path/to/a/file' request.params['original_filename'] = 'new_original_file_name' link_view = link.LinkViews(request) self.patch_logged_in_user(request) response = link_view.update_entity() from stalker import Link link_db = Link.query.get(self.test_link1.id) self.assertEqual(link_db.name, 'New Link Name') self.assertEqual(link_db.description, 'New description') self.assertEqual(link_db.full_path, '/new/path/to/a/file') self.assertEqual(link_db.original_filename, 'new_original_file_name')
def test_delete_statuses_is_working_properly(self): """testing if delete_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, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_status_list.id request.params = DummyMultiDict() request.params['status_id'] = [test_status4.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_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_group1.id request.params = DummyMultiDict() request.params['name'] = 'New Group Name' request.params['user_id'] = [self.test_user1.id, self.test_user2.id] request.params['description'] = 'New description' request.params['permission'] = \ ['%s_%s_%s' % (p.access, p.action, p.class_name) for p in self.all_permissions[0:5]] group_view = group.GroupViews(request) self.patch_logged_in_user(request) response = group_view.update_entity() # get group1 from db from stalker import Group test_group1_db = Group.query.get(self.test_group1.id) self.assertEqual(test_group1_db.name, 'New Group Name') self.assertEqual( sorted(test_group1_db.users), sorted([self.test_user1, self.test_user2]) ) self.assertEqual(test_group1_db.description, 'New description') self.assertEqual( sorted(test_group1_db.permissions), sorted(self.all_permissions[0:5]) )
def test_update_tags_is_working_properly_with_post(self): """testing if the update_tags() view is working properly when the request.method is POST """ # create some tags from stalker import db, Tag t1 = Tag(name='tag1') t2 = Tag(name='tag2') t3 = Tag(name='tag3') db.DBSession.add_all([t1, t2, t3]) from stalker import Entity test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_entity.id request.method = 'POST' request.params = DummyMultiDict() request.params['tag'] = ['tag1', 'tag2'] request.POST = request.params entity_view = entity.EntityViews(request) entity_view.update_tags() # now query entity tags test_entity = Entity.query.filter(Entity.id == test_entity.id).first() self.assertEqual(sorted([t.name for t in test_entity.tags]), sorted(['tag1', 'tag2']))
def test_update_notes_is_working_properly_with_patch(self): """testing if update_notes is working properly when the request method is PATCH """ from stalker import db, Entity, Note test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) # Note 1 test_note1 = Note(content='Note 1') db.DBSession.add(test_note1) # Note 2 test_note2 = Note(content='Note 2') db.DBSession.add(test_note2) # Note 3 test_note3 = Note(content='Note 3') db.DBSession.add(test_note3) # Note 4 test_note4 = Note(content='Note 4') db.DBSession.add(test_note4) # Note 5 test_note5 = Note(content='Note 5') db.DBSession.add(test_note5) test_entity.notes = [test_note1, test_note2, test_note3] db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_entity.id request.method = 'PATCH' # add the 4th and 5th notes request.params = DummyMultiDict() request.params['note_id'] = [test_note4.id, test_note5.id] request.POST = request.params entity_view = entity.EntityViews(request) entity_view.update_notes() test_entity = Entity.query.filter(Entity.id == test_entity.id).first() self.assertEqual( sorted(test_entity.notes), sorted( [test_note1, test_note2, test_note3, test_note4, test_note5]))
def test_update_entity_change_user(self): """testing if update_entity() method is working properly for changing user attribute """ 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) import datetime start = datetime.datetime(2016, 4, 22, 10) end = datetime.datetime(2016, 4, 22, 16) vac1 = Vacation(user=user1, start=start, end=end) db.DBSession.commit() user2 = User.query.filter(User.login == user2.login).first() vac1 = Vacation.query.filter(Vacation.name == vac1.name).first() # also update updated_by_id attribute from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = vac1.id request.params = DummyMultiDict() # change user request.params['user_id'] = user2.id request.params['updated_by_id'] = user2.id self.patch_logged_in_user(request) vacation_views = vacation.VacationViews(request) vacation_views.update_entity() vac = Vacation.query.filter(Vacation.name == vac1.name).first() self.assertEqual(vac.start, start) self.assertEqual(vac.end, end) self.assertEqual(vac.user, user2) self.assertEqual(vac.updated_by, user2)
def test_update_user_roles_is_working_properly_with_non_related_user(self): """testing if update_user_roles() method is working properly with non related user """ from stalker import db, DepartmentUser # create a role for the user du1 = DepartmentUser(department=self.test_department1, user=self.test_user1, role=self.test_role1) db.DBSession.add(du1) db.DBSession.commit() du2 = DepartmentUser(department=self.test_department1, user=self.test_user2, role=self.test_role1) db.DBSession.add(du2) db.DBSession.commit() # now update the user role to something new from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_department1.id request.method = 'POST' request.params = DummyMultiDict() request.params['user_role'] = [ '%s,%s' % (self.test_user1.id, self.test_role2.id), '%s,%s' % (self.test_user2.id, self.test_role3.id), '%s,%s' % (self.test_user3.id, self.test_role1.id) ] department_view = department.DepartmentViews(request) department_view.update_user_role() du1_db = DepartmentUser.query\ .filter(DepartmentUser.department == self.test_department1)\ .filter(DepartmentUser.user == self.test_user1)\ .first() du2_db = DepartmentUser.query\ .filter(DepartmentUser.department == self.test_department1)\ .filter(DepartmentUser.user == self.test_user2)\ .first() self.assertEqual(du1_db.role, self.test_role2) self.assertEqual(du2_db.role, self.test_role3)
def test_remove_users_is_working_properly(self): """testing if remove_users() method is working properly """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_group1.id request.params = DummyMultiDict() request.params['user_id'] = [self.test_user2.id] group_view = group.GroupViews(request) response = group_view.remove_users() from stalker import Group test_group1_db = Group.query.get(self.test_group1.id) self.assertEqual( sorted(test_group1_db.users), sorted([self.test_user1]) )
def test_remove_templates_is_working_properly(self): """testing if remove_templates() method is working properly """ 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_template1.id] structure_view = structure.StructureViews(request) response = structure_view.remove_templates() from stalker import Structure structure_db = Structure.query.get(self.test_structure1.id) self.assertEqual(sorted(structure_db.templates), sorted([self.test_filename_template2]))
def test_update_statuses_is_working_properly_with_patch(self): """testing if update_statuses() method is working properly when the request method is PATCH """ 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_status5.id] request.method = 'PATCH' status_list_view = status.StatusListViews(request) response = status_list_view.update_statuses() self.maxDiff = None self.assertEqual( sorted(test_status_list.statuses), sorted([ test_status1, test_status2, test_status3, test_status4, test_status5 ]))
def test_remove_user_roles_is_working_properly(self): """testing if remove_user_roles() method is working properly """ from stalker import db, DepartmentUser # create a role for the user du1 = DepartmentUser(department=self.test_department1, user=self.test_user1, role=self.test_role1) db.DBSession.add(du1) db.DBSession.commit() du2 = DepartmentUser(department=self.test_department1, user=self.test_user2, role=self.test_role1) db.DBSession.add(du2) db.DBSession.commit() # now update the user role to something new from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_department1.id request.method = 'POST' request.params = DummyMultiDict() request.params['user_id'] = [self.test_user1.id, self.test_user2.id] department_view = department.DepartmentViews(request) department_view.remove_user_role() du1_db = DepartmentUser.query\ .filter(DepartmentUser.department == self.test_department1)\ .filter(DepartmentUser.user == self.test_user1)\ .first() du2_db = DepartmentUser.query\ .filter(DepartmentUser.department == self.test_department1)\ .filter(DepartmentUser.user == self.test_user2)\ .first() self.assertIsNone(du1_db.role) self.assertIsNone(du2_db.role)
def test_update_entity_change_end(self): """testing if update_entity() method is working properly for changing end attribute """ 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, 10) end = datetime.datetime(2016, 4, 22, 16) new_end = datetime.datetime(2016, 4, 22, 17) vac1 = Vacation(user=user1, start=start, end=end) db.DBSession.commit() user1 = User.query.filter(User.login == user1.login).first() vac1 = Vacation.query.filter(Vacation.name == vac1.name).first() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = vac1.id request.params = DummyMultiDict() # change start from stalker_pyramid.views import EntityViewBase request.params['end'] = \ EntityViewBase.milliseconds_since_epoch(new_end) self.patch_logged_in_user(request) vacation_views = vacation.VacationViews(request) vacation_views.update_entity() vac = Vacation.query.filter(Vacation.name == vac1.name).first() self.assertEqual(vac.start, start) self.assertEqual(vac.end, new_end) self.assertEqual(vac.user, user1)
def test_update_users_is_working_properly_with_post(self): """testing if update_users() method is working properly with request method is post """ from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = self.test_group1.id request.params = DummyMultiDict() request.params['user_id'] = [self.test_user2.id, self.test_user3.id] request.method = 'POST' group_view = group.GroupViews(request) response = group_view.update_users() from stalker import Group test_group1_db = Group.query.get(self.test_group1.id) self.assertEqual( sorted(test_group1_db.users), sorted([self.test_user2, self.test_user3]) )
def test_update_entity_is_working_properly(self): """testing if update_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, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_status_list.id self.patch_logged_in_user(request) request.params = DummyMultiDict() name = 'New Status List Name' description = 'This is a new description' request.params['name'] = name request.params['description'] = description status_list_view = status.StatusListViews(request) status_list_view.update_entity() test_status_list_db = StatusList.query.get(test_status_list.id) self.assertEqual(test_status_list_db.name, name) self.assertEqual(test_status_list_db.description, description)
def test_update_entity_is_working_properly_with_post(self): """testing if the update_entity() method is working properly when the request method is POST """ from stalker import db, Entity, User test_user_1 = User(name='Test User 1', login='******', email='*****@*****.**', password='******') db.DBSession.add(test_user_1) test_user_2 = User(name='Test User 2', login='******', email='*****@*****.**', password='******') db.DBSession.add(test_user_2) test_entity = Entity(name='Test Entity', created_by=test_user_1) db.DBSession.add(test_entity) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.method = 'POST' request.matchdict['id'] = test_entity.id request.params = DummyMultiDict() request.params['name'] = 'New Entity Name' request.params['description'] = 'New Description' request.params['updated_by_id'] = test_user_2.id self.patch_logged_in_user(request) entity_view = entity.EntityViews(request) entity_view.update_entity() test_entity_db = Entity.query.get(test_entity.id) self.assertEqual(test_entity_db.name, 'New Entity Name') self.assertEqual(test_entity_db.description, 'New Description') self.assertEqual(test_entity_db.updated_by, test_user_2)
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_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_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')