def test_get_ong(self):
     ong = OngDocument(name='Expresso Voluntário', description='Unindo ONGs e voluntários').save()
     response = self.client.get('/ong/{id}'.format(id=ong.id))
     response_data_decoded = response.data.decode()
     ong_response = json.loads(response_data_decoded)
     self.assertEquals(response.status_code, 200)
     self.assertDictEqual(ong.to_dict(), ong_response)
Beispiel #2
0
 def test_get_ong(self):
     ong = OngDocument(name='Expresso Voluntário', description='Unindo ONGs e voluntários').save()
     response = self.client.get('/ong/{id}'.format(id=ong.id))
     response_data_decoded = response.data.decode()
     ong_response = json.loads(response_data_decoded)
     self.assertEquals(response.status_code, 200)
     self.assertDictEqual(ong.to_dict(), ong_response)
Beispiel #3
0
 def setUp(self):
     self.client = app.test_client()
     self.ong = OngDocument(name='ong', description='The coolest ong').save()
     self.user = UserDocument(name="iury",
                              email="*****@*****.**",
                              _password="******",
                              ong_id=self.ong.id).save()
Beispiel #4
0
 def setUp(self):
     UserDocument.drop_collection()
     self.ong = OngDocument(name='ong', description='The coolest ong').save()
     self.user = UserDocument(name="iury",
                              email="*****@*****.**",
                              _password="******",
                              ong_id=self.ong.id).save()
Beispiel #5
0
 def test_get_all_ongs(self):
     OngDocument(name='Expresso Voluntário', description='Unindo ONGs e voluntários').save()
     response = self.client.get('/ong/', data={'limit': 10})
     response_data_decoded = response.data.decode()
     ongs = json.loads(response_data_decoded)
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(ongs), 1)
Beispiel #6
0
    def test_add_task(self):
        ong = OngDocument(name="Ongzinha", description="Uma ongzinha").save()
        data = {
            'title': 'A cool task',
            'description': 'Hasta la vista baby!',
            'status': 'NEW',
            'ong_id': ong.id
        }
        response = self.client.post('/task/', data=data)
        task = TaskDocument.objects(title=data['title'],
                                    description=data['description']).get()

        self.assertEqual(response.status_code, 201)
        self.assertEqual(task.title, data['title'])
        self.assertEqual(task.description, data['description'])
Beispiel #7
0
    def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('limit', type=int)
        parser.add_argument('title', type=str)
        parser.add_argument('tag', type=str)
        parser.add_argument('location', type=str)
        args = parser.parse_args(strict=True)
        limit = args.get("limit", None)
        title = args.get("title", None)
        tag = args.get('tag', None)
        location = args.get('location', None)

        if not any([id, limit, tag, location, title]):
            abort(
                400,
                message="You must provide an id, limit, location, title or tag"
            )

        elif limit is not None:
            tasks = TaskDocument.objects[:limit]
            return [task.to_dict() for task in tasks], 200

        elif tag is not None:
            tasks = TaskDocument.objects(tags__in=[tag])
            return [task.to_dict() for task in tasks], 200

        elif location is not None:
            ongs = OngDocument.objects(
                address__localidade__in=[location]).all()

            tasks = []
            for ong in ongs:
                tasks.extend(ong.tasks)

            return [task.to_dict() for task in tasks], 200

        elif title is not None:
            tasks = TaskDocument.objects(title__icontains=title)
            return [task.to_dict() for task in tasks], 200

        task = TaskDocument.objects.get_or_404(id=id)
        return task.to_dict(), 200
    def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('limit', type=int)
        parser.add_argument('title', type=str)
        parser.add_argument('tag', type=str)
        parser.add_argument('location', type=str)
        args = parser.parse_args(strict=True)
        limit = args.get("limit", None)
        title = args.get("title", None)
        tag = args.get('tag', None)
        location = args.get('location', None)

        if not any([id, limit, tag, location, title]):
            abort(400, message="You must provide an id, limit, location, title or tag")

        elif limit is not None:
            tasks = TaskDocument.objects[:limit]
            return [task.to_dict() for task in tasks], 200

        elif tag is not None:
            tasks = TaskDocument.objects(tags__in=[tag])
            return [task.to_dict() for task in tasks], 200

        elif location is not None:
            ongs = OngDocument.objects(address__localidade__in=[location]).all()

            tasks = []
            for ong in ongs:
                tasks.extend(ong.tasks)

            return [task.to_dict() for task in tasks], 200

        elif title is not None:
            tasks = TaskDocument.objects(title__icontains=title)
            return [task.to_dict() for task in tasks], 200

        task = TaskDocument.objects.get_or_404(id=id)
        return task.to_dict(), 200
Beispiel #9
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('data', type=str)
        parser.add_argument('location', type=str)
        parser.add_argument('title', type=str)
        parser.add_argument('tag', type=str)
        parser.add_argument('remote', type=bool)
        parser.add_argument('name', type=str)
        args = parser.parse_args()
        data = args.get('data', None)
        location = args.get('location', None)
        title = args.get('title', None)
        tag = args.get('tag', None)
        remote = args.get('remote', None)
        name= args.get('name', None)

        if data is not None:
            # BUSCA TODAS AS CIDADES CADASTRADAS (ONG)

            if data == 'cities':
                cities = []
                ongs = OngDocument.objects[:]
                for ong in ongs:
                    cities.append(ong.address['localidade'])
                cities = set(cities)
                cities = sorted(cities)
                return json.dumps(cities, default="utf-8")

            # BUSCA TASKS DE ACORDO COM OS PARÂMETROS PASSADOS
            elif data == 'task':
                if all([location]):
                    ongs = OngDocument.objects(address__localidade__icontains=location).all()
                    tasks = []
                    for ong in ongs:
                        tasks.extend(ong.tasks)
                    return [task.to_dict() for task in tasks], 200

                elif all([tag]):
                    tasks = TaskDocument.objects(tags__icontains=tag)
                    for task in tasks:
                        ong = OngDocument.objects.get(id=task.ong_id)
                        task.location = ong.address['localidade']
                    return [task.to_dict_with_address() for task in tasks], 200

                elif all([title]):
                    tasks = TaskDocument.objects(title__icontains=title)
                    for task in tasks:
                        ong = OngDocument.objects.get(id=task.ong_id)
                        task.location = ong.address['localidade']
                    return [task.to_dict_with_address() for task in tasks], 200

                elif all([remote]):
                    tasks = TaskDocument.objects(is_remote__eq=remote)
                    return [task.to_dict_with_address]

            # BUSCA ONGS DE ACORDO COM OS PARÂMETROS PASSADOS
            elif data == 'ong':
                if all([name]):
                    ongs = OngDocument.objects(name__icontains=name)
                    return [ong.to_dict() for ong in ongs], 200

                elif all([location]):
                    ongs = OngDocument.objects(address__localidade__icontains=location)
                    return [ong.to_dict() for ong in ongs], 200

        abort(400, message="You must provide data attribute")
Beispiel #10
0
 def tearDown(self):
     UserDocument.drop_collection()
     OngDocument.drop_collection()
Beispiel #11
0
 def test_delete_ong(self):
     ong = OngDocument(name='Expresso Voluntário', description='Unindo ONGs e voluntários').save()
     response = self.client.delete('/ong/{id}'.format(id=ong.id))
     self.assertEquals(response.status_code, 204)