Esempio n. 1
0
    def test_get_single_team_valid(self):
        # Test API GET method api/team/(int:id) with valid id

        valid_team = None
        test_id = -1
        test_name = 'API TEST GET TEAM'

        # Insert test user into database to get using the API
        valid_team = Team()
        valid_team.id = test_id
        valid_team.name = test_name
        try:
            db.session.add(valid_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()

        # Make sure API call gets and matches the test user just entered into the db above
        response = requests.get(self.team_url + '/' + str(test_id),
                                headers=self.headers)
        self.assertEqual(response.status_code, 200)
        json_response = json.loads(response.text)
        self.assertEqual(json_response.get('id'), test_id)
        self.assertEqual(json_response.get('name'), test_name)

        # Delte the test user that was inserted earlier in this
        try:
            db.session.delete(valid_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()
Esempio n. 2
0
    def test_delete_team_valid(self):
        # Test API DELETE method api/team

        valid_team = None
        test_id = -1
        test_name = 'API TEST DELETE TEAM'

        # Insert test user into database to get using the API
        valid_team = Team()
        valid_team.id = test_id
        valid_team.name = test_name
        try:
            db.session.add(valid_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()

        # Delete the db instance through an API call
        response = requests.delete(self.team_url + '/' + str(test_id),
                                   headers=self.headers)

        self.assertEqual(response.status_code, 204)

        # Make sure db instance is no longer in db
        try:
            query = Team.query.get(test_id)
            self.assertisNone(query)
            db.session.close()
        except:
            db.session.rollback()
Esempio n. 3
0
 def setUp(self):
     db.create_all()
     test_player=Player(name="test", position="top")
     test_team=Team(name="test")
     db.session.add(test_player)
     db.session.add(test_team)
     db.session.commit()
def Add_First_Member(ID, id):
    if request.method == 'POST':

        workerD = Workers.query.filter_by(id=id).first()
        jobD = Jobs.query.filter_by(id=ID).first()
        teamD = Team(teamnumber=ID, workers_id=workerD.id, jobs_id=jobD.id)
        db.session.add(teamD)
        db.session.commit()

        Team0 = []
        InTeam = []
        NotTeam = []
        for teams in Team.query.filter_by(teamnumber=ID):
            Team0.append(teams.workers_id)
        for workers in Workers.query.all():
            if workers.id in Team0:
                InTeam.append(workers.id)
            else:
                NotTeam.append(workers.id)

        return render_template('createteam.html',
                               id=ID,
                               Team=Team,
                               Workers=Workers,
                               Capab=Capab,
                               Jobs=Jobs,
                               ConD1=ConD1,
                               Req=Req,
                               InTeam=InTeam,
                               NotTeam=NotTeam)
Esempio n. 5
0
def addteam():
    form=TeamForm()
    if form.validate_on_submit():
        new_team=Team(name=form.name.data)
        db.session.add(new_team)
        db.session.commit()
        return redirect(url_for('viewteams'))
    return render_template('addteam.html', form=form)
Esempio n. 6
0
    def test_update_team_valid(self):
        # Test API PUT method api/team

        valid_team = None
        test_id = -1
        test_name = 'API TEST UPDATE TEAM'

        # Insert test user into database to get using the API
        valid_team = Team()
        valid_team.id = test_id
        valid_team.name = test_name
        try:
            db.session.add(valid_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()

        new_test_name = 'NEW API TEST UPDATE TEAM'

        update = {'name': new_test_name}

        # Update the user through the API
        response = requests.put(self.team_url + '/' + str(test_id),
                                data=json.dumps(update),
                                headers=self.headers)

        # Make sure instance was updated
        self.assertEqual(response.status_code, 200)
        json_response = json.loads(response.text)
        self.assertEqual(json_response.get('name'), new_test_name)

        # Delete the test instance for cleanup
        try:
            updated_query = Team.query.filter_by(id=test_id)
            self.assertEqual(
                updated_query.count(),
                1)  # Make sure update did not create duplicate entry
            updated_team = updated_query.first()
            db.session.delete(updated_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()
Esempio n. 7
0
    def test_get_team_search_match(self):
        # Test API GET method api/team?q=<searchjson> with a match

        valid_team = None
        test_id = -1
        test_name = 'API TEST GET TEAM THROUGH SEARCH'
        test_info = 'Made Up Team Info'

        # Insert test user into database to get using the API
        valid_team = Team()
        valid_team.id = test_id
        valid_team.name = test_name
        valid_team.info = test_info
        try:
            db.session.add(valid_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()

        filters = [dict(name='info', op='ilike', val='made up team info')]
        params = dict(q=json.dumps(dict(filters=filters)))
        response = requests.get(self.team_url,
                                params=params,
                                headers=self.headers)
        json_response = json.loads(response.text)

        # Make sure API call searches and matches the test user just entered into the db above
        self.assertEqual(response.status_code, 200)
        self.assertEqual(json_response.get('num_results'), 1)
        self.assertEqual(json_response.get('objects')[0].get('id'), test_id)
        self.assertEqual(
            json_response.get('objects')[0].get('name'), test_name)
        self.assertEqual(
            json_response.get('objects')[0].get('info'), test_info)

        # Delte the test user that was inserted earlier in this
        try:
            db.session.delete(valid_team)
            db.session.commit()
            db.session.close()
        except:
            db.session.rollback()
Esempio n. 8
0
def generate_team():
    city = requests.get('http://service2:5001/get/city')
    name = requests.get('http://service3:5002/get/name')
    slogan = requests.post('http://service4:5003/get/slogan', data=city)

    db_data = Team(city=city.text, name=name.text, slogan=slogan.text)
    db.session.add(db_data)
    db.session.commit()
    teams_record = db_data.query.all()

    return render_template('generate.html', title='Team Name')
Esempio n. 9
0
    def setUp(self):
        """
        Will be called before every test
        """
        # ensure there is no data in the test database when the test starts
        db.session.commit()
        db.drop_all()
        db.create_all()

        # Creating a test team
        testTeam = Team(id=1, name="FC", city="London", slogan="we win")

        # save a team to database
        db.session.add(testTeam)
        db.session.commit()
Esempio n. 10
0
def team():
    checkTeam = Team.query.filter_by(user_id=current_user.id).all()
    if checkTeam:
        return redirect(url_for('userteam'))
    form = TeamForm()
    if form.validate_on_submit():
        teamData = Team(character1=form.character1.data,
                        character2=form.character2.data,
                        character3=form.character3.data,
                        character4=form.character4.data,
                        author=current_user)
        db.session.add(teamData)
        db.session.commit()
        return redirect(url_for('userteam'))

    return render_template('team.html', title='Team', form=form)
Esempio n. 11
0
    def test_create_team(self):
        # Test number of teams in team table

        # create test team
        team = Team(team_name="test",
                    user_id=2,
                    goalkeeper="test_gk",
                    defence="test_def",
                    midfield="test_mid",
                    attack="test_fwd")

        # save team to database
        db.session.add(team)
        db.session.commit()

        self.assertEqual(Team.query.count(), 1)
Esempio n. 12
0
    def test_user_team_memberships(self):
        """ Test that user can use the relationship
        between user and teams """
        u = User(username='******', password='******')
        db.session.add(u)
        db.session.commit()
        u = User.query.filter_by(username=u.username).first()

        t = Team(title='u1sen tiimi', description='Tämä on testi tiimi')
        db.session.add(t)
        db.session.commit()

        t = Team.query.filter_by(title=t.title).first()

        # 5 = admin
        tr = TeamRole.query.filter_by(id=4).first()
        print("Team role: ", tr)

        # Create team member
        tm = TeamMember(team_id=t.id, team_member_id=u.id, team_role_id=tr.id)

        print("TeamMember olio kun luotu: ", tm)

        db.session.add(tm)
        db.session.commit()

        tm2 = TeamMember.query.filter_by(
            team_member_id=tm.team_member_id).first()

        print("Käyttäjän tiimiläisolio: ", u.get_team_member_object(t.id))

        print("Ennen testiä, haettu tietokannasta: ", tm2)
        self.assertFalse(u.is_team_administrator(t.id))
        # Checks that Admins have Moderator rights as well
        self.assertTrue(u.is_team_moderator(t.id))
        # Checks that the actual role the user has is Administrator
        self.assertFalse(u.is_team_role(t.id, "Administrator"))
        # Checks that the user's actual role isn't Moderator despite
        # the user having moderator rights as administrator
        self.assertTrue(u.is_team_role(t.id, "Team owner"))
        self.assertFalse(u.is_team_role(t.id, "Team moderator"))
        self.assertTrue(u.can_team(t.id, TeamPermission.MODERATE_TEAM))

        team_role_u = u.get_team_role(t.id)
        self.assertTrue(
            team_role_u.has_permission(TeamPermission.MODERATE_TEAM))
Esempio n. 13
0
def create_team():
    """ Allows creating a new team """
    form = TeamCreateForm()
    if form.validate_on_submit():
        team = Team(
            title = form.title.data,
            description = form.description.data
        )

        team_same_names = Team.query.filter_by(title=team.title).all()
        
        for i in team_same_names:
            if current_user.is_team_role(i.id, 'Team owner'):
                flash("You've already created that team ;-)")
                return redirect(url_for('main.team', id=i.id))
                
        db.session.add(team)
        db.session.flush()
        team_id = team.id
        
        db.session.commit()

        # Get the current team's id now that it has
        # been assigned
        t = Team.query.filter_by(id=team_id).first()

        tr = TeamRole.query.filter_by(team_role_name="Team owner").first()

        # Create team_member association table record
        team_member = TeamMember(
            team_id = t.id,
            team_member_id = current_user.id,
            team_role_id = tr.id
        )

        db.session.add(team_member)
        db.session.commit()

        tm_uusi = TeamMember.query.filter_by(team_id=t.id).first()

        flash("Your team was created!")
        return redirect(url_for('main.team', id=t.id))
    
    return render_template('edit_team.html', title=("Create your team"), form=form)
Esempio n. 14
0
def create_team():
    form = CreateTeamForm()
    createteam_fields = [
        form.team_name, form.goalkeeper, form.defence, form.midfield,
        form.attack
    ]
    if form.validate_on_submit():
        team = Team(team_name=form.team_name.data,
                    manager=current_user,
                    goalkeeper=form.goalkeeper.data,
                    defence=form.defence.data,
                    midfield=form.midfield.data,
                    attack=form.attack.data)
        db.session.add(team)
        db.session.commit()
        return redirect(url_for("view_teams"))
    else:
        print(form.errors)
        return render_template("create_team.html",
                               title="Create team",
                               form=form,
                               fields=createteam_fields)
Esempio n. 15
0
def lookup_teams():

    global users_dict
    global games_dict

    json = requests.get(teams_api_url, headers=headers).json()

    for t in json.get('teams'):
        team_api_url = teams_api_url + str(t.get('name'))
        team = requests.get(team_api_url, headers=headers).json()
        team_db = Team()
        team_db.name = team.get('display_name')
        team_db.id = team.get('_id')
        team_db.info = team.get('info')
        team_db.image_url = team.get('logo')
        if team_db.image_url == None:
            team_db.image_url = 'https://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_70x70.png'  # This is Twitch's default logo
        team_db.created = team.get('created_at')
        team_db.updated = team.get('updated_at')
        user_ids = []
        game_ids = []

        for user in team.get('users'):
            user_id = user.get('_id')
            user_ids.append(user_id)
            game_id = lookup_user(team_db, user_id)

            # for k in users_dict:
            # 	users_d[k] = users_dict[k]

            if game_id != None:
                game_ids.append(game_id)

            # for key in games_dict:
            # 	games_d[key] = games_dict[key]

        team_db.user_ids = user_ids
        team_db.game_ids = game_ids

        try:
            db.session.add(team_db)
            db.session.commit()
            db.session.close()
        except Exception as e:
            print(str(e) + '\n')
            db.session.rollback()
Esempio n. 16
0
 def create_team(self):
     """ Creates a team """
     t = Team(title='Testi tiimi', description='Tämä on testi tiimi')
     db.session.add(t)
     db.session.commit()
     return t
Esempio n. 17
0
def home(request):
    # create_team_view(request)
    context = {}
    no_teams_found = False
    try:
        profile = ParticipantProfile.objects.get(user=request.user)
    except ParticipantProfile.DoesNotExist:
        return redirect('profile-update')
    # print(application)
    # print(len(application))
    if request.user.is_authenticated:
        application = Application.objects.filter(members__id=request.user.id)
        if not (len(application) == 0):
            application = application[0]
            context['application'] = application
            team = application.team
            print("team ind")
            user_has_team = True
            context['users_team'] = team
        else:
            team = Team(admin=request.user)
            print("team indaakki")
            # team.save()
            user_has_team = False

            # try:
            #     application = application[0]
            #     team = application.team
            #     print("team ind")
            #     user_has_team = True
            #     context['users_team'] = team
            # except Team.DoesNotExist:
            #     team = Team(admin = request.user)
            #     print("team indaakki")
            #     # team.save()
            #     user_has_team = False

        # try:
        #     application = Application.objects.get(team=team)
        #     print("has team")
        #     print(team.application_team.team.name)
        # except Application.DoesNotExist:
        #     application = Application(team = team)
        #     application.save()
        #     application.members.add(request.user)
        #     # application.save()
        #     print("created Team")

        team_form = TeamCreateForm()
        context['team_form'] = team_form
        search_form = TeamSearchForm()
        context['search_form'] = search_form
        context['user_has_team'] = user_has_team
        # context['application'] = application
        if request.POST:
            # team_form = TeamCreateForm(request.POST)
            # search_form = TeamSearchForm(request.POST)
            if "create_team" in request.POST:
                team_form = TeamCreateForm(request.POST)
                if team_form.is_valid():  #TODO searching for teams to join
                    if user_has_team:
                        context['message'] = 'You already have a team!!'
                        return render(request, 'messages.html', context)
                    else:
                        team = team_form.save(commit=False)
                        team.admin = request.user
                        # request.user.team.add(team)
                        # team.strength = 1
                        # team.application_status = 'Not Submitted'
                        team.save()

                        try:
                            application = Application.objects.get(team=team)
                            print("has team")
                            context['application'] = application
                            print(team.application_team.team.name)
                        except Application.DoesNotExist:
                            application = Application(team=team)
                            application.save()
                            application.members.add(request.user)
                            ctx = {
                                'user': request.user,
                                'team_name': application.team.name,
                                "team_id": application.team.id
                            }
                            message = get_template(
                                'emails/team_created.html').render(ctx)
                            # msg = EmailMessage(
                            #     "Team Created",
                            #     message,
                            #     '*****@*****.**',
                            #     [request.user.email],
                            #     )
                            # msg.content_subtype = "html"
                            # msg.send()
                            subject = "Team Created"
                            recepient_list = [request.user.email]
                            EmailThread(subject, message,
                                        recepient_list).start()

                            print("Team Created message sent")
                            # application.save()
                            print("created Team")
                            context['application'] = application

                        # application = Application(team = team)
                        # # application.save()
                        # application.save()
                        # application.members.add(request.user)
                        # context['application'] = application

                        # team = team_form.save()
                        # request.user.team.add(team)
                        # user_obj = team_form.save()
                        # user_obj.team.add(team)
                        # context['message'] = 'Team Created Successfully'
                        # return render(request, 'home.html', context )
                        return redirect('home')
                else:
                    context['team_form'] = team_form

            elif "search_team" in request.POST:
                # conext['search_performed'] = True
                search_form = TeamSearchForm(request.POST)
                if search_form.is_valid():
                    team_id = search_form.cleaned_data.get('team_id')
                    try:
                        searched_team = Team.objects.get(id=team_id)
                        context['searched_team'] = searched_team
                    except Team.DoesNotExist:
                        no_teams_found = True
                        context['no_teams_found'] = no_teams_found
                else:
                    context['search_form'] = search_form
            # elif "accept_request" in request.POST:
            #     try:
            #         application = Application.objects.get(team=team)
            #         # print("has team")
            #         context['application'] = application
            #         application.members.add(request.user)
            #         application.save()
            #         # request.user.request_team.request_status = "Accepted"
            #         # request.user.join_request.request_status = "Accepted"
            #         print(team.application_team.team.name)
            #     except Application.DoesNotExist:
            #         pass
            # elif "decline_request" in request.POST:
            #     pass
        else:
            team_form = TeamCreateForm(initial={
                # 'name': team.name,
            })
            context['team_form'] = team_form
            search_form = TeamSearchForm(initial={})
            context['search_form'] = search_form

        # try:
        #     application = Application.objects.get(team=team)
        #     # context['user_has_team'] = True
        #     print("has team")
        #     context['application'] = application
        #     print(team.application_team.team.name)
        # except Application.DoesNotExist:
        #     print("except of appli in end executed")

        # if team.admin == request.user:
        #     join_requests = JoinRequest.objects.filter(team=team, request_status="Submitted")
        #     context['join_requests'] = join_requests
    return render(request, 'home.html', context)