def setup_module(): cfg.dse_keyspace = TEST_KEYSPACE initialise() connect() create_tables() create_default_users() create_root() grp1 = Group.create(name=GRP1_NAME) grp2 = Group.create(name=GRP2_NAME) grp3 = Group.create(name=GRP3_NAME) user_name = USR1_NAME email = uuid.uuid4().hex password = uuid.uuid4().hex administrator = True groups = [GRP1_NAME] user1 = User.create(name=user_name, email=email, password=password, administrator=administrator, groups=groups) user_name = USR2_NAME email = uuid.uuid4().hex password = uuid.uuid4().hex administrator = False groups = [GRP1_NAME, GRP2_NAME] user2 = User.create(name=user_name, email=email, password=password, administrator=administrator, groups=groups)
def setup_module(): cfg.dse_keyspace = TEST_KEYSPACE initialise() connect() create_tables() create_root() Group.create(name="grp1")
def test_create(): grp_name = uuid.uuid4().hex grp = Group.create(name=grp_name) assert grp.name == grp_name # Test already existing group with pytest.raises(GroupConflictError): grp = Group.create(name=grp_name) grp.delete() # Test the username for the notification grp = Group.create(name=grp_name, username="******") grp.delete()
def test_add_user(): grp1_name = uuid.uuid4().hex grp2_name = uuid.uuid4().hex grp3_name = uuid.uuid4().hex g1 = Group.create(name=grp1_name) g2 = Group.create(name=grp2_name) g3 = Group.create(name=grp3_name) u1 = create_random_user([]) u2 = create_random_user([]) u3 = create_random_user([]) u4 = create_random_user([g2.name, g3.name]) # g2 = [u4] # g3 = [u4] g1.add_user(u1.name) assert u1.name in g1.get_usernames() # g1 = [u1] added, not_added, already_there = g2.add_users( [u1.name, u2.name, u4.name, "unknown_user"]) # g2 = [u1, u2, u4] assert u1.name in g2.get_usernames() assert u2.name in g2.get_usernames() assert u4.name in g2.get_usernames() # From create assert added == [u1.name, u2.name] assert not_added == ["unknown_user"] assert already_there == [u4.name] g2.rm_user(u4.name) # g2 = [u1, u2] assert not u4.name in g2.get_usernames() removed, not_there, not_exist = g2.rm_users( [u1.name, u2.name, u4.name, "unknown_user"]) assert removed == [u1.name, u2.name] assert not_there == [u4.name] assert not_exist == ["unknown_user"] g1.delete() g2.delete() g3.delete() u1.delete() u2.delete() u3.delete() u4.delete()
def test_update(): grp1_name = uuid.uuid4().hex g1 = Group.create(name=grp1_name) g1.update(uuid=default_uuid()) g1.update(uuid=default_uuid(), username="******") g1.delete()
def test_group(): grp1_name = uuid.uuid4().hex grp2_name = uuid.uuid4().hex grp1 = Group.create(name=grp1_name) grp2 = Group.create(name=grp2_name) user_name = uuid.uuid4().hex email = uuid.uuid4().hex password = uuid.uuid4().hex administrator = True groups = [grp1_name, grp2_name] user = User.create(name=user_name, email=email, password=password, administrator=administrator, groups=groups) assert set(user.get_groups()) == set([grp1_name, grp2_name]) user.rm_group(grp1_name) assert set(user.get_groups()) == set([grp2_name])
def create_default_users(): """Create some users and groups Users and groups are defined in DEFAULT_GROUPS and DEFAULT_USERS in the :mod:`radon.model.config` module, . """ for name in cfg.default_groups: try: Group.create(name=name) except GroupConflictError: pass for name, email, pwd, is_admin, groups in cfg.default_users: try: User.create(name=name, email=email, password=pwd, administrator=is_admin, groups=groups) except UserConflictError: pass
def test_to_dict(): grp1_name = uuid.uuid4().hex g1 = Group.create(name=grp1_name) u1 = create_random_user([g1.name]) g_dict = g1.to_dict() assert g_dict['uuid'] == g1.uuid assert g_dict['name'] == grp1_name assert g_dict['members'] == [u1.name] g1.delete() u1.delete()
def mk_group(self, args): """Create a new group. Ask in the terminal for mandatory fields""" if not args[ARG_NAME]: name = input("Please enter the group name: ") else: name = args[ARG_NAME] group = Group.find(name) if group: self.print_error(MSG_GROUP_EXIST.format(name)) return group = Group.create(name=name) print(MSG_GROUP_CREATED.format(group.name))
def create_group(request): """Expecting json in the body: { "groupname": groupname } """ try: body = request.body request_body = json.loads(body) except (TypeError, json.JSONDecodeError): return Response("Invalid JSON body", status=HTTP_400_BAD_REQUEST) try: groupname = request_body["groupname"] except KeyError: return Response("Missing groupname", status=HTTP_400_BAD_REQUEST) group_db = Group.find(groupname) if group_db: return Response("Group already exists", status=HTTP_409_CONFLICT) new_group_db = Group.create(name=groupname) return Response(new_group_db.to_dict(), status=HTTP_201_CREATED)
def new_group(request): """Display the form to create a new group""" if request.method == "POST": form = GroupForm(request.POST) if form.is_valid(): data = form.cleaned_data group = Group.create(name=data.get("name"), username=request.user.name) messages.add_message( request, messages.INFO, "The group '{}' has been created".format(group.name), ) return redirect("groups:home") else: form = GroupForm() ctx = { "form": form, } return render(request, "groups/new.html", ctx)
def setup_module(): cfg.dse_keyspace = TEST_KEYSPACE initialise() connect() create_tables() create_default_users() create_root() pwd = uuid.uuid4().hex email = uuid.uuid4().hex grp1 = Group.create(name="grp1") u1 = User.create(name="user1", password=pwd, email=email, administrator=True) u2 = User.create(name="user2", password=pwd, email=email, administrator=False) grp1.add_users(["user2"]) try: coll = Collection.create("/", "1") coll = Collection.create("/1", "11") coll = Collection.create("/1", "12") coll = Collection.create("/1", "13") coll = Collection.create("/", "2") coll = Collection.create("/2", "21") coll = Collection.create("/2/21", "211") coll = Collection.create("/2/21", "212") r = Resource.create("/1/11", "a") r = Resource.create("/1/11", "b", url=TEST_URL) r = Resource.create("/1/12", "c") r = Resource.create("/1/13", "d") r = Resource.create("/2/21/211", "e") r = Resource.create("/2/21/212", "f") r = Resource.create("/", "g") except: # If collections or resources already exist pass