Example #1
0
    def create(self, request):
        required_fields = ("hash", "url", "xpath")
        optional_fields = ("title", "text", "connected_to")

        for field in required_fields + ("team",):
            if field not in request.POST.keys():
                return rc.BAD_REQUEST  # FIXME proper error msg?

        try:
            team = Team.objects.get(name=request.POST["team"])
        except:
            return rc.BAD_REQUEST  # FIXME proper error msg?

        if not team.is_member(request.user):
            return rc.FORBIDDEN  # FIXME proper error msg?

        dragable = Dragable()
        dragable.created_by = request.user
        dragable.team = team

        for field in required_fields:
            setattr(dragable, field, request.POST[field])

        for field in optional_fields:
            if field in request.POST:
                setattr(dragable, field, request.POST[field])

        dragable.save()
        return rc.CREATED
    def create(self, request):
        required_fields = ('hash', 'url', 'xpath')
        optional_fields = ('title', 'text', 'connected_to')

        for field in required_fields + ('team', ):
            if field not in request.POST.keys():
                return rc.BAD_REQUEST  # FIXME proper error msg?

        try:
            team = Team.objects.get(name=request.POST['team'])
        except:
            return rc.BAD_REQUEST  # FIXME proper error msg?

        if not team.is_member(request.user):
            return rc.FORBIDDEN  # FIXME proper error msg?

        dragable = Dragable()
        dragable.created_by = request.user
        dragable.team = team

        for field in required_fields:
            setattr(dragable, field, request.POST[field])

        for field in optional_fields:
            if field in request.POST:
                setattr(dragable, field, request.POST[field])

        dragable.save()
        return rc.CREATED
Example #3
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')