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_delete_entity_is_working_properly(self): """testing if delete_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) self.patch_logged_in_user(request) response = structure_view.delete_entity() from stalker import Structure self.assertIsNone( Structure.query.filter( Structure.id == self.test_structure1.id).first())
def test_get_entities_is_working_properly(self): """testing if GET: /api/structures view is working properly """ from stalker_pyramid.testing import DummyRequest request = DummyRequest() structure_view = structure.StructureViews(request) response = self.test_app.get('/api/structures', status=200) from stalker import Structure self.assertEqual(response.json_body, [{ 'id': r.id, 'name': r.name, 'entity_type': 'Structure', '$ref': '/api/structures/%s' % r.id } for r in Structure.query.all()])
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_get_templates_is_working_properly(self): """testing if get_templates() 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_templates() self.maxDiff = None self.assertEqual( sorted(response.json_body), sorted([ { 'id': ft.id, 'name': ft.name, 'entity_type': ft.entity_type, '$ref': '/api/filename_templates/%s' % ft.id } for ft in [self.test_filename_template1, self.test_filename_template2] ]))
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_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' }, })