Beispiel #1
0
    def setUp(self):
        user = User.objects.create_user('existing_user',
                                        '*****@*****.**',
                                        'donthackmebro')

        user.save()

        ownsnoteam = User.objects.create_user('ownsnoteam',
                                              '*****@*****.**',
                                              'donthackmeeither')
        ownsnoteam.save()

        public_team = Team(name='public test team',
                           description='test me, dude',
                           created_by=user,
                           public=True)
        public_team.save()
        public_team.members.add(ownsnoteam)

        public_lolcats = Team(name='LOLcats',
                              description='internet memes FTW!',
                              created_by=user,
                              public=True)
        public_lolcats.save()

        private_lolcats = Team(name='existing_user_LOLcats',
                               description='adult lolcat content',
                               created_by=user,
                               public=False,
                               password='******')
        private_lolcats.save()
        private_lolcats.members.add(ownsnoteam)

        self.auth_client = BasicAuthClient('existing_user', 'donthackmebro')
Beispiel #2
0
 def handle(self, *args, **options):
     data = requests.get('https://onmyoji.rapospectre.com/s/file/scene_datiangou.json', verify=False).content
     json_data = json.loads(data)
     num = 0
     for item in json_data:
         scene = Scene(name=item.get('scene_name'))
         scene.save()
         for itm in item.get('team_list'):
             team = Team(name=itm.get('name'), index=itm.get('index'), belong=scene)
             team.save()
             for mitm in itm.get('monsters'):
                 hs = Hellspawn.objects.get(name=mitm.get('name'))
                 Membership(hellspawn=hs, count=mitm.get('count'), team=team).save()
Beispiel #3
0
def _get_teams_from_recruit_project_review(self, request, view):
    project_review = view.get_object()
    project = project_review.project
    user_ids = [user.id for user in project.recruit_users.all()] + [
        project_review.reviewer_user_id
    ]
    return Team.get_teams_from_user_ids(user_ids)
Beispiel #4
0
 def get_systems(team_id):
     """GET all systems currently controlled by team"""
     system_ids = set(
         System.objects(controller=Team.mongo_id(
             team_id=team_id)).distinct('system_id')) | set(
                 ship.location for ship in Team.objects.get(
                     team_id=team_id).ships.filter(alive=True))
     return jsonify([
         System.objects.get(system_id=s).to_dict(team_id)
         for s in system_ids
     ])
Beispiel #5
0
def test_user_precense_view(client: APIClient, team: Team, user: MyUser,
                            user2: MyUser) -> None:
    """
    ensure that only authorized users can access the user precense view
    """
    url = reverse("calendar-presence", kwargs={"team_pk": team.id})
    assert url == f"/api/v1/calendar-presence/{team.id}"

    res = client.post(url)
    assert res.status_code == status.HTTP_403_FORBIDDEN, "no auth provided"

    assert not team.is_member(user2)
    client.force_authenticate(user2)
    res = client.post(url)
    assert res.status_code == status.HTTP_403_FORBIDDEN, "unauthorized user"

    assert team.is_member(user)
    client.force_authenticate(user)
    res = client.post(url)
    assert res.status_code == status.HTTP_200_OK, "authorized user"
    def create(self, request):
        if not 'name' in request.POST:
            return rc.BAD_REQUEST

        if Team.objects.filter(name=request.POST['name']):
            return rc.DUPLICATE_ENTRY

        data = {}
        data['name'] = request.POST['name']
        data['created_by'] = request.user

        if 'description' in request.POST:
            data['description'] = request.POST['description']

        if 'password' in request.POST and request.POST['password'].strip():
            data['public'] = False
            data['password'] = request.POST['password']

        team = Team(**data)
        team.save()
        return rc.CREATED
Beispiel #7
0
    def create(self, request):
        if not "name" in request.POST:
            return rc.BAD_REQUEST

        if Team.objects.filter(name=request.POST["name"]):
            return rc.DUPLICATE_ENTRY

        data = {}
        data["name"] = request.POST["name"]
        data["created_by"] = request.user

        if "description" in request.POST:
            data["description"] = request.POST["description"]

        if "password" in request.POST and request.POST["password"].strip():
            data["public"] = False
            data["password"] = request.POST["password"]

        team = Team(**data)
        team.save()
        return rc.CREATED
 def test_add_match_duplicate(self):
     day = MatchDay('Tuesday')
     avb1 = Match(Team('A'), Team('B'))
     avb2 = Match(Team('B'), Team('A'))
     avb3 = Match(Team('A'), Team('B'))
     self.assertEqual(day.add_match(avb1), avb1)
     self.assertEqual(day.add_match(avb2), False)
     self.assertEqual(day.add_match(avb3), False)
Beispiel #9
0
 def _get_teams_from_user_filter(self, request, view):
     user_ids = get_clean_user_ids_from_filter(request, filter_name)
     return Team.get_teams_from_user_ids(user_ids)
Beispiel #10
0
    def setUp(self):
        user = User.objects.create_user('testuser',
                                        '*****@*****.**',
                                        'donthackmebro')
        user.save()

        user2 = User.objects.create_user('testuser2',
                                         '*****@*****.**',
                                         'donthackmebro')
        user2.save()

        public_team = Team(name='public test team',
                           description='test me, dude',
                           created_by=user,
                           public=True)
        public_team.save()

        public_team2 = Team(name='public test team 2',
                            description='test me, too',
                            created_by=user2,
                            public=True)
        public_team2.save()

        public_team3 = Team(name='public test team 3',
                            description='test me, also',
                            created_by=user2,
                            public=False,
                            password='******')
        public_team3.save()
        public_team3.members.add(user)

        dragable = Dragable()
        dragable.hash = '23425'
        dragable.team = public_team
        dragable.created_by = user
        dragable.url = 'http://www.example.com'
        dragable.title = 'test dragable 1'
        dragable.text = 'foo bar baz'
        dragable.xpath = 'foo/bar/baz'
        dragable.save()

        dragable2 = Dragable()
        dragable2.hash = '4711'
        dragable2.team = public_team2
        dragable2.created_by = user2
        dragable2.url = 'http://www.example2.com'
        dragable2.title = 'test dragable 2'
        dragable2.text = 'spam eggs spamneggs'
        dragable2.xpath = 'spam/eggs/ni!'
        dragable2.save()

        dragable3 = Dragable()
        dragable3.hash = '12345'
        dragable3.team = public_team3
        dragable3.created_by = user2
        dragable3.url = 'http://www.example3.com'
        dragable3.title = 'test dragable 3'
        dragable3.text = 'fu fa fi'
        dragable3.xpath = 'fi/fa/fu'
        dragable3.save()

        note_annotation1 = Annotation()
        note_annotation1.type = 'note'
        note_annotation1.hash = 'note_ann1'
        note_annotation1.dragable  = dragable
        note_annotation1.created_by = user
        note_annotation1.note = 'this is the first note annotation. evar!!'
        note_annotation1.save()

        url_annotation1 = Annotation()
        url_annotation1.type = 'url'
        url_annotation1.hash = 'url_ann1'
        url_annotation1.dragable = dragable
        url_annotation1.created_by = user
        url_annotation1.url = 'http://example.com'
        url_annotation1.save()

        url_annotation2 = Annotation()
        url_annotation2.type = 'url'
        url_annotation2.hash = 'url_ann2'
        url_annotation2.dragable = dragable2
        url_annotation2.created_by = user2
        url_annotation2.url = 'http://google.com'
        url_annotation2.save()

        self.client = BasicAuthClient('testuser', 'donthackmebro')
Beispiel #11
0
def _get_teams_from_repository_instance(repo):
    projects = repo.recruit_projects.all()
    for project in projects:
        user_ids = [user.id for user in project.recruit_users.all()]
        for team in Team.get_teams_from_user_ids(user_ids):
            yield team
Beispiel #12
0
def _get_teams_from_card(self, request, view):
    card = view.get_object()
    user_ids = [user.id for user in card.assignees.all()]
    user_ids += [user.id for user in card.reviewers.all()]
    return Team.get_teams_from_user_ids(user_ids)
Beispiel #13
0
def _get_teams_from_topic_review(self, request, view):
    review = view.get_object()
    user_ids = [review.topic_progress.user.id, review.reviewer_user.id]
    return Team.get_teams_from_user_ids(user_ids)
Beispiel #14
0
def _get_teams_from_topic_progress_instance(topic_progress):
    user_ids = [topic_progress.user.id]
    # user_ids = [user.id for user in project.recruit_users.all()]
    return Team.get_teams_from_user_ids(user_ids)
Beispiel #15
0
def _get_teams_from_workshop_attendance(self, request, view):
    attendance = view.get_object()
    user_ids = [attendance.attendee_user_id]
    return Team.get_teams_from_user_ids(user_ids=user_ids)
Beispiel #16
0
 def test_add_match_success(self):
     day = MatchDay('Tuesday')
     avb = Match(Team('A'), Team('B'))
     output = day.add_match(avb)
     self.assertEqual(output, avb)
Beispiel #17
0
 def create(self, data):
     team = Team(**data)
     team.slug_name = slugify(team.name, allow_unicode=True)
     team = Team.objects.create(name=team.name, slug_name=team.slug_name)
     return team
Beispiel #18
0
def setup_teams(team_names):
    teams = []
    for name in team_names:
        teams.append(Team(name))
    return teams
Beispiel #19
0
def _get_teams_from_user(self, request, view):
    user = view.get_object()
    return Team.get_teams_from_user_ids([user.id])