Example #1
0
  def setUp( self ):
    Test_controller.setUp( self )
    Groups.urllib2 = Stub_urllib2

    self.group_name = u"my group"
    self.group_name2 = u"other group"
    self.username = u"mulder"
    self.password = u"trustno1"
    self.email_address = u"*****@*****.**"
    self.username2 = u"scully"
    self.password2 = u"trustsome1"
    self.email_address2 = u"*****@*****.**"
    self.username3 = u"skinner"
    self.password3 = u"trustne1"
    self.email_address3 = u"*****@*****.**"

    self.group = Group.create( self.database.next_id( Group ), self.group_name )
    self.database.save( self.group, commit = False )

    self.group2 = Group.create( self.database.next_id( Group ), self.group_name )
    self.database.save( self.group2, commit = False )

    self.user = User.create( self.database.next_id( User ), self.username, self.password, self.email_address )
    self.database.save( self.user, commit = False )
    self.database.execute( self.user.sql_save_group( self.group.object_id, admin = False ) )

    self.user2 = User.create( self.database.next_id( User ), self.username2, self.password2, self.email_address2 )
    self.database.save( self.user2, commit = False )
    self.database.execute( self.user2.sql_save_group( self.group.object_id, admin = True ) )

    self.user3 = User.create( self.database.next_id( User ), self.username3, self.password3, self.email_address3 )
    self.database.save( self.user3, commit = False )
    self.database.execute( self.user3.sql_save_group( self.group.object_id, admin = False ) )

    self.database.commit()
Example #2
0
class TestGroup(TestSuite):
    group1 = Group({
        'id': 2,
        'group_name': 'mensxc',
        'group_title': "Men's Cross Country",
        'grouppic': None,
        'grouppic_name': None,
        'week_start': 'monday',
        'description': '',
        'deleted': False
    })

    group2 = Group({
        'id': 1,
        'group_name': 'wmenstf',
        'group_title': "Women's Track & Field",
        'grouppic': None,
        'grouppic_name': None,
        'week_start': 'monday',
        'description': '',
        'deleted': False
    })

    def test_group_str(self) -> None:
        """
        Prove that the human readable string representation of an Group object is as expected.
        """
        group_str = "Group: [id: 2, group_name: mensxc, group_title: Men's Cross Country, grouppic: None, " \
            'grouppic_name: None, week_start: monday, description: , deleted: False]'

        self.assertEquals(str(self.group1), group_str)
        self.assertEquals(self.group1.__str__(), group_str)

    def test_group_repr(self) -> None:
        """
        Prove that the machine readable string representation of an Group object is as expected.
        """
        self.assertEquals(repr(self.group1), "<Group 2, 'mensxc'>")
        self.assertEquals(self.group1.__repr__(), "<Group 2, 'mensxc'>")

    def test_group_eq(self) -> None:
        """
        Prove that two Group objects with the same property values test positive for value equality.
        """
        self.assertTrue(self.group1 == self.group1)
        self.assertTrue(self.group1.__eq__(self.group1))

    def test_group_ne(self) -> None:
        """
        Prove that two Group objects with different property values test negative for value equality.
        """
        self.assertTrue(self.group1 != self.group2)
        self.assertTrue(self.group1.__ne__(self.group2))
def loadGrupos(measurs):
    try:
        grupos = {}
        grupos['5'] = Group(5, 30)
        grupos['10'] = Group(10, 50)

        for grupo in grupos.values():
            for measur in measurs.values():
                if measur.grupo_time == grupo.time_interval:
                    grupo.insert_measur(measur)
        return grupos
    except Exception as e:
        print e
        logging.error(str(e))
Example #4
0
  def setUp( self ):
    self.object_id = "17"
    self.name = u"my group"
    self.delta = timedelta( seconds = 1 )
    self.admin = True

    self.group = Group.create( self.object_id, self.name, self.admin )
Example #5
0
 def add_group(self, name):
     """Add and return new group or will return existing group"""
     name = name.replace(' ', '_')
     group = self.get_group(name)
     if group is None:
         group = Group(self, name)
         self._groups.append(group)
     return group
def test_modify_group_name(app, db, check_ui):
    if app.group.count() == 0:
        app.group.create(Group(name='new group for edit'))
    old_groups = app.group.get_group_list()

    group = random.choice(old_groups)
    edited_group = Group(name="edited group name",
                         header=group.header,
                         footer=group.footer,
                         group_id=group.group_id)
    app.group.edit_group_by_id(group.group_id, edited_group)

    new_groups = db.get_group_list()
    old_groups.remove(group)
    old_groups.append(edited_group)
    assert old_groups == new_groups
    if check_ui:
        assert sorted(new_groups, key=Group.id_or_max) == sorted(
            app.group.get_group_list(), key=Group.id_or_max)
Example #7
0
def group_snapshot_by_group_name_get(team_name: str,
                                     group_name: str) -> Response:
    """
    Get a snapshot about a group based on the group name.
    :param team_name: Unique name which identifies a team.
    :param group_name: Unique name which identifies a group within a team.
    :return: A response object for the GET API request.
    """
    group_row: Optional[RowProxy] = GroupDao.get_group(team_name=team_name,
                                                       group_name=group_name)

    if group_row is None:
        response = jsonify({
            'self': f'/v2/groups/snapshot/{team_name}/{group_name}',
            'group': f'/v2/groups/{team_name}/{group_name}',
            'group_snapshot': None,
            'error': 'the group does not exist'
        })
        response.status_code = 400
        return response

    group_dict = {key: value for key, value in group_row.items()}
    group = Group(group_dict)

    group_members: ResultProxy = GroupMemberDao.get_group_members(
        group_name=group_name, team_name=team_name)
    group_members_list = [{
        'username': member.username,
        'first': member.first,
        'last': member.last,
        'member_since': member.member_since,
        'user': member.user,
        'status': member.status
    } for member in group_members]

    # All group statistics are queried separately but combined into a single map
    statistics = compile_group_statistics(group_object=group)

    group_dict: dict = GroupData(group).__dict__

    try:
        group_dict['grouppic'] = group_dict['grouppic'].decode('utf-8')
    except AttributeError:
        pass

    group_dict['members'] = group_members_list
    group_dict['statistics'] = statistics

    response = jsonify({
        'self': f'/v2/groups/snapshot/{team_name}/{group_name}',
        'group': f'/v2/groups/{team_name}/{group_name}',
        'group_snapshot': group_dict
    })
    response.status_code = 200
    return response
Example #8
0
    def get_group_list(self):
        if self.group_cache is None:
            wd = self.app.wd
            self.open_group_page()
            self.group_cache = []
            for element in wd.find_elements_by_css_selector("span.group"):
                text = element.text
                group_id = element.find_element_by_name(
                    'selected[]').get_attribute('value')
                self.group_cache.append(Group(name=text, group_id=group_id))

        return list(self.group_cache)
Example #9
0
def test_group_add_units():
    group = Group()

    u1 = Unit(1, 1)
    u2 = Unit(2, 2)
    u3 = Unit(3, 3)

    group.addUnit(u1)
    group.addUnit(u2)
    group.addUnit(u3)

    assert group.unitList == [u1, u2, u3]
    assert group.getX() == 2 # mass X
    assert group.getY() == 2 # mass Y
Example #10
0
def test_group_renew():
    group = Group()

    u1 = Unit(1, 1)
    group.addUnit(u1)
    assert group.unitList == [u1]

    u2 = Unit(2, 2)
    group.renew([u2])
    assert group.unitList == [u2]
Example #11
0
 def get(self):
     jgroup = self.request.get('join')
     usr = self.verify_user_cookie()
     if usr:
         if jgroup !=  "":
             group = Group()
             if group.by_name(jgroup):
                 logging.error(usr.name)
                 group.add_join_request(usr.name)
                 group.commit(True)
                 self.redirect('/')
                 return
         self.formpost(usr)
     else:
         self.redirect("/login")
Example #12
0
 def clean(group):
     return Group(group_id=group.group_id, name=group.name.strip())
Example #13
0
def group_by_id_put(group_id: str) -> Response:
    """
    Update a group based on the unique group id.
    :param group_id: Unique id which identifies a group.
    :return: A response object for the PUT API request.
    """
    old_group = GroupDao.get_group_by_id(int(group_id))

    jwt_claims: dict = get_claims(request)
    jwt_username = jwt_claims.get('sub')

    group_member: GroupMember = GroupMemberDao.get_group_member(
        group_id=int(group_id), username=jwt_username)

    if group_member is not None and group_member.user == 'admin' and group_member.status == 'accepted':
        current_app.logger.info(
            f'Admin user {jwt_username} is updating a group with id {group_id}.'
        )
    else:
        current_app.logger.info(
            f'User {jwt_username} is not authorized to update a group with id {group_id}.'
        )
        response = jsonify({
            'self':
            f'/v2/groups/{group_id}',
            'updated':
            False,
            'group':
            None,
            'error':
            f'User {jwt_username} is not authorized to update a group with id {group_id}.'
        })
        response.status_code = 400
        return response

    if old_group is None:
        response = jsonify({
            'self': f'/v2/groups/{group_id}',
            'updated': False,
            'group': None,
            'error': 'There is no existing group with this id.'
        })
        response.status_code = 400
        return response

    group_data: dict = request.get_json()
    new_group = Group(group_data)

    if new_group != old_group:
        new_group.modified_date = datetime.now()
        new_group.modified_app = 'saints-xctf-api'

        is_updated = GroupDao.update_group(group=new_group)

        if is_updated:
            updated_group = GroupDao.get_group_by_id(int(group_id))
            updated_group_dict: dict = GroupData(updated_group).__dict__

            response = jsonify({
                'self': f'/v2/groups/{group_id}',
                'updated': True,
                'group': updated_group_dict
            })
            response.status_code = 200
            return response
        else:
            response = jsonify({
                'self': f'/v2/groups/{group_id}',
                'updated': False,
                'group': None,
                'error': 'The group failed to update.'
            })
            response.status_code = 500
            return response
    else:
        response = jsonify({
            'self':
            f'/v2/groups/{group_id}',
            'updated':
            False,
            'group':
            None,
            'error':
            'The group submitted is equal to the existing group with the same id.'
        })
        response.status_code = 400
        return response
Example #14
0
def group_by_group_name_put(team_name: str, group_name: str) -> Response:
    """
    Update a group in the database.
    :param team_name: Unique name which identifies a team.
    :param group_name: Unique name which identifies a group within a team.
    :return: A response object for the PUT API request.
    """
    old_group_row: Optional[RowProxy] = GroupDao.get_group(
        team_name=team_name, group_name=group_name)

    if old_group_row is None:
        response = jsonify({
            'self': f'/v2/groups/{team_name}/{group_name}',
            'updated': False,
            'group': None,
            'error': 'there is no existing group with this name'
        })
        response.status_code = 400
        return response

    jwt_claims: dict = get_claims(request)
    jwt_username = jwt_claims.get('sub')

    group_member: GroupMember = GroupMemberDao.get_group_member_by_group_name(
        team_name=team_name, group_name=group_name, username=jwt_username)

    if group_member is not None and group_member.user == 'admin' and group_member.status == 'accepted':
        current_app.logger.info(
            f'Admin user {jwt_username} is updating a group with name {group_name} in team {team_name}.'
        )
    else:
        current_app.logger.info(
            f'User {jwt_username} is not authorized to update a group with name {group_name} in team {team_name}.'
        )
        response = jsonify({
            'self':
            f'/v2/groups/{team_name}/{group_name}',
            'updated':
            False,
            'group':
            None,
            'error':
            f'User {jwt_username} is not authorized to update a group with name {group_name} in team '
            f'{team_name}.'
        })
        response.status_code = 400
        return response

    old_group_dict = {key: value for key, value in old_group_row.items()}
    old_group = Group(old_group_dict)
    group_data: dict = request.get_json()
    new_group = Group(group_data)

    if old_group != new_group:

        new_group.modified_date = datetime.now()
        new_group.modified_app = 'saints-xctf-api'

        is_updated = GroupDao.update_group(group=new_group)

        if is_updated:
            updated_group_row: Optional[RowProxy] = GroupDao.get_group(
                team_name=team_name, group_name=new_group.group_name)

            updated_group_dict = {
                key: value
                for key, value in updated_group_row.items()
            }
            response = jsonify({
                'self': f'/v2/groups/{team_name}/{group_name}',
                'updated': True,
                'group': updated_group_dict
            })
            response.status_code = 200
            return response
        else:
            response = jsonify({
                'self': f'/v2/groups/{team_name}/{group_name}',
                'updated': False,
                'group': None,
                'error': 'the group failed to update'
            })
            response.status_code = 500
            return response
    else:
        response = jsonify({
            'self':
            f'/v2/groups/{team_name}/{group_name}',
            'updated':
            False,
            'group':
            None,
            'error':
            'the group submitted is equal to the existing group with the same name'
        })
        response.status_code = 400
        return response
Example #15
0
import getopt
import sys

try:
    opts, args = getopt.getopt(sys.argv[1:], 'n:f:',
                               ['number of groups', 'file'])
except getopt.GetoptError as err:
    getopt.usage(0)
    sys.exit(2)

n = 5
f = 'data/groups.json'

for o, a in opts:
    if o == '-n':
        n = int(a)
    elif o == '-f':
        f = a

test_data = [Group(name="", header="", footer="")] + [
    Group(name=random_string('name', 10),
          header=random_string('header', 20),
          footer=random_string('footer', 20)) for i in range(n)
]

file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', f)

with open(file, 'w') as out:
    jsonpickle.set_encoder_options('json', indent=2)
    out.write(jsonpickle.encode(test_data))
Example #16
0
from model.Group import Group

test_data = [
    Group(name="name1", header="header1", footer="footer1"),
    Group(name="name2", header="header2", footer="footer2")
]
Example #17
0
def test_untitled_test_case(app):
    app.Open_home_directory()
    app.session.Enter_Login(Login="******", Password="******")
    app.group.Create(Group(name="rty", header="recfghh", footer="dffgdfgdg"))
Example #18
0
def join(groupID):
    Group.addUser(groupID, current_user)
    return redirect(url_for('groups', groupID=groupID))