class PrivilegesTestCase(TestCase): def setUp(self): super().setUp() with self.app.app_context(): self.service = UsersService('users', backend=superdesk.get_backend()) def test_admin_has_all_privileges(self): with self.app.app_context(): user = {'user_type': 'administrator'} self.service.set_privileges(user, None) self.assertEqual(user['active_privileges']['users'], 1) def test_user_has_merged_privileges(self): with self.app.app_context(): user = {'user_type': 'user', 'privileges': {'users': 1}} role = {'privileges': {'archive': 1}} self.service.set_privileges(user, role) self.assertEqual(user['active_privileges']['users'], 1) self.assertEqual(user['active_privileges']['archive'], 1) def test_user_with_privilege_can_change_his_role(self): with self.app.app_context(): flask.g.user = {'user_type': 'administrator'} ids = self.service.create([{ 'name': 'user', 'user_type': 'administrator' }]) doc_old = self.service.find_one(None, _id=ids[0]) self.service.update(ids[0], {'role': '1'}, doc_old) self.assertIsNotNone(self.service.find_one(req=None, role='1')) def test_compare_preferences(self): original_preferences = { "unlock": 1, "archive": 1, "spike": 1, "unspike": 1, "ingest_move": 0 } updated_preferences = { "unlock": 0, "archive": 1, "spike": 1, "ingest": 1, "ingest_move": 1, } added, removed, modified = compare_preferences(original_preferences, updated_preferences) self.assertEqual(1, len(added)) self.assertEqual(1, len(removed)) self.assertEqual(2, len(modified)) self.assertTrue((1, 0) in modified.values()) self.assertTrue((0, 1) in modified.values())
class PrivilegesTestCase(TestCase): def setUp(self): with self.app.app_context(): self.service = UsersService("users", backend=get_backend()) def test_admin_has_all_privileges(self): with self.app.app_context(): user = {"user_type": "administrator"} self.service.set_privileges(user, None) self.assertEqual(user["active_privileges"]["users"], 1) def test_user_has_merged_privileges(self): with self.app.app_context(): user = {"user_type": "user", "privileges": {"users": 1}} role = {"privileges": {"archive": 1}} self.service.set_privileges(user, role) self.assertEqual(user["active_privileges"]["users"], 1) self.assertEqual(user["active_privileges"]["archive"], 1) def test_user_with_privilege_can_change_his_role(self): with self.app.app_context(): flask.g.user = {"user_type": "administrator"} ids = self.service.create([{ "name": "user", "user_type": "administrator" }]) doc_old = self.service.find_one(None, _id=ids[0]) self.service.update(ids[0], {"role": "1"}, doc_old) self.assertIsNotNone(self.service.find_one(req=None, role="1")) def test_compare_preferences(self): original_preferences = { "unlock": 1, "archive": 1, "spike": 1, "unspike": 1, "ingest_move": 0 } updated_preferences = { "unlock": 0, "archive": 1, "spike": 1, "ingest": 1, "ingest_move": 1, } added, removed, modified = compare_preferences(original_preferences, updated_preferences) self.assertEqual(1, len(added)) self.assertEqual(1, len(removed)) self.assertEqual(2, len(modified)) self.assertTrue((1, 0) in modified.values()) self.assertTrue((0, 1) in modified.values())
class PrivilegesTestCase(TestCase): def setUp(self): super().setUp() with self.app.app_context(): self.service = UsersService('users', backend=superdesk.get_backend()) def test_admin_has_all_privileges(self): with self.app.app_context(): user = {'user_type': 'administrator'} self.service.set_privileges(user, None) self.assertEqual(user['active_privileges']['users'], 1) def test_user_has_merged_privileges(self): with self.app.app_context(): user = {'user_type': 'user', 'privileges': {'users': 1}} role = {'privileges': {'archive': 1}} self.service.set_privileges(user, role) self.assertEqual(user['active_privileges']['users'], 1) self.assertEqual(user['active_privileges']['archive'], 1) def test_user_with_privilege_can_change_his_role(self): with self.app.app_context(): flask.g.user = {'user_type': 'administrator'} ids = self.service.create([{'name': 'user', 'user_type': 'administrator'}]) doc_old = self.service.find_one(None, _id=ids[0]) self.service.update(ids[0], {'role': '1'}, doc_old) self.assertIsNotNone(self.service.find_one(req=None, role='1')) def test_compare_preferences(self): original_preferences = { "unlock": 1, "archive": 1, "spike": 1, "unspike": 1, "ingest_move": 0 } updated_preferences = { "unlock": 0, "archive": 1, "spike": 1, "ingest": 1, "ingest_move": 1, } added, removed, modified = compare_preferences(original_preferences, updated_preferences) self.assertEqual(1, len(added)) self.assertEqual(1, len(removed)) self.assertEqual(2, len(modified)) self.assertTrue((1, 0) in modified.values()) self.assertTrue((0, 1) in modified.values())
def setUp(self): setup(context=self) with self.app.app_context(): # mock one user: user_service = UsersService( 'users', backend=superdesk.get_backend()) self.user_id = user_service.create([{ 'name': 'user', 'user_type': 'administrator', 'email': '*****@*****.**' }])[0] provider = {'name': 'Test'} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename)) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], provider)
def setUp(self): setup(context=self) with self.app.app_context(): # mock one user: user_service = UsersService('users', backend=superdesk.get_backend()) self.user_id = user_service.create([{ 'name': 'user', 'user_type': 'administrator', 'email': '*****@*****.**' }])[0] provider = {'name': 'Test'} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.join(dirname, 'fixtures', self.filename) with open(fixture, mode='rb') as f: bytes = f.read() parser = rfc822Parser() self.items = parser.parse_email([(1, bytes)], provider)
def setUp(self): setup(context=self) with self.app.app_context(): # mock one user: user_service = UsersService("users", backend=superdesk.get_backend()) self.user_id = user_service.create([{ "name": "user", "user_type": "administrator", "email": "*****@*****.**" }])[0] provider = {"name": "Test"} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, "../fixtures", self.filename)) with open(fixture, mode="rb") as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], provider)
class PrivilegesTestCase(TestCase): def setUp(self): with self.app.app_context(): self.service = UsersService("users", backend=get_backend()) def test_admin_has_all_privileges(self): with self.app.app_context(): user = {"user_type": "administrator"} self.service.set_privileges(user, None) self.assertEqual(user["active_privileges"]["users"], 1) def test_user_has_merged_privileges(self): with self.app.app_context(): user = {"user_type": "user", "privileges": {"users": 1}} role = {"privileges": {"archive": 1}} self.service.set_privileges(user, role) self.assertEqual(user["active_privileges"]["users"], 1) self.assertEqual(user["active_privileges"]["archive"], 1) def test_user_with_privilege_can_change_his_role(self): with self.app.app_context(): flask.g.user = {"user_type": "administrator"} ids = self.service.create([{"name": "user", "user_type": "administrator"}]) doc_old = self.service.find_one(None, _id=ids[0]) self.service.update(ids[0], {"role": "1"}, doc_old) self.assertIsNotNone(self.service.find_one(req=None, role="1")) def test_compare_preferences(self): original_preferences = {"unlock": 1, "archive": 1, "spike": 1, "unspike": 1, "ingest_move": 0} updated_preferences = {"unlock": 0, "archive": 1, "spike": 1, "ingest": 1, "ingest_move": 1} added, removed, modified = compare_preferences(original_preferences, updated_preferences) self.assertEqual(1, len(added)) self.assertEqual(1, len(removed)) self.assertEqual(2, len(modified)) self.assertTrue((1, 0) in modified.values()) self.assertTrue((0, 1) in modified.values())
def setUp(self): setup(context=self) with self.app.app_context(): # mock one user: user_service = UsersService('users', backend=superdesk.get_backend()) self.user_id = user_service.create([{ 'name': 'user', 'user_type': 'administrator', 'email': '*****@*****.**' }])[0] provider = {'name': 'Test'} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', self.filename)) with open(fixture, mode='rb') as f: data = [(1, f.read())] parser = EMailRFC822FeedParser() self.items = parser.parse(data, provider) instance = EmailBelgaFeedingService() instance.save_attachment(data, self.items)