コード例 #1
0
 def setUp(self):
     config = ConfigManager(os.getcwd() +
                            '/test_adam_config.json').get_config()
     self.service = Service(config)
     self.assertTrue(self.service.setup())
     self.assertIsNotNone(self.service.new_working_project())
コード例 #2
0
class AnonymousTest(unittest.TestCase):
    """Tests anonymous access to API.

    """

    def setUp(self):
        cwd = os.getcwd()
        cwd_str = str(cwd).split("/")
        os.chdir("..")
        self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').read_config(os.getcwd() + '/test_adam_config.json')
        self.config.set_token("")
        self.service = Service(self.config)
        self.assertTrue(self.service.setup())
        #if len(cwd_str) > 4: 
        #    # TRAVIS CI option
        #    if cwd_str[1] == "home" and cwd_str[2] == "travis" and cwd_str[3] == "build":
        #        self.config = ConfigManager(os.getcwd() + '/adam_home/config/adam_config_template.json').get_config()
        #        print("home/travis/build found in root dir - USE JSON TEMPLATE")
        #        #self.config = ConfigManager(None).get_config()
        #        self.config.set_token("")
        #        self.service = Service(self.config)
        #        self.assertTrue(self.service.setup())
        #    else:
        #        #self.config = ConfigManager(os.getcwd() + '/adam_test_config.json').get_config()
        #        # next line used for testing Travis output with decrypted json info.
        #        self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').read_config(os.getcwd() + '/test_adam_config.json')
        #        self.config.set_token("")
        #        self.service = Service(self.config)
        #        self.assertTrue(self.service.setup())
        #else:
        #    # PERSONAL WORKSTATION option
        #    self.config = ConfigManager(os.getcwd() + '/test_config.json').get_config()
        #    # next line used for testing Travis output with decrypted json info.
        #    #self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').read_config(os.getcwd() + '/test_adam_config.json')
        #    self.config.set_token("")
        #    self.service = Service(self.config)
        #    self.assertTrue(self.service.setup())
        #self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').get_config()
        #self.config.set_token("")
        #self.service = Service(self.config)
        #self.assertTrue(self.service.setup())

    def tearDown(self):
        self.service.teardown()

    def test_access(self):
        projects_module = self.service.get_projects_module()
        permissions_module = self.service.get_permissions_module()
        groups_module = self.service.get_groups_module()

        projects = projects_module.get_projects()
        self.assertEqual(1, len(projects))
        self.assertEqual("public", projects[0].get_name())

        # Can't add a project to public project.
        public_project = "00000000-0000-0000-0000-000000000001"
        with (self.assertRaises(RuntimeError)):
            projects_module.new_project(public_project, "", "")

        # Can't run a batch in the public project.
        batches_module = self.service.get_batches_module()
        dummy_propagation_params = PropagationParams({
            'start_time': 'AAA',
            'end_time': 'BBB',
            'project_uuid': 'CCC'
        })
        dummy_opm_params = OpmParams({
            'epoch': 'DDD',
            'state_vector': [1, 2, 3, 4, 5, 6]
        })
        with (self.assertRaises(RuntimeError)):
            batches_module.new_batch(dummy_propagation_params, dummy_opm_params)

        # Anon should have no permissions.
        permissions = permissions_module.get_my_permissions()
        self.assertEqual(1, len(permissions))
        self.assertEqual(0, len(permissions[""]))

        # And anon is in no groups.
        groups = groups_module.get_my_memberships()
        self.assertEqual(0, len(groups))

        # Therefore anon can grant no permissions.
        with (self.assertRaises(RuntimeError)):
            permissions_module.grant_user_permission(
                "*****@*****.**", Permission("READ", "PROJECT", public_project))

        # And can add/modify no groups.
        with (self.assertRaises(RuntimeError)):
            groups_module.new_group("", "")
        all_group = "00000000-0000-0000-0000-000000000001"
        with (self.assertRaises(RuntimeError)):
            groups_module.add_user_to_group("*****@*****.**", all_group)

        # Not even allowed to see the members of the magic all group.
        with (self.assertRaises(RuntimeError)):
            groups_module.get_group_members(all_group)
コード例 #3
0
 def setUp(self):
     config = ConfigManager(os.getcwd() + '/test_config.json').get_config()
     self.service = Service(config)
     self.assertTrue(self.service.setup())
コード例 #4
0
 def setUp(self):
     config = ConfigManager(os.getcwd() + '/test_config.json').get_config()
     self.service = Service(config)
     self.assertTrue(self.service.setup())
     self.me = "*****@*****.**"
     self.added_groups = []