Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
def get_search_query(phrase):
    query = Q(
        'function_score',
        query=MultiMatch(
            fields=['email'],
            query=phrase
        ),
    )
    return UserDocument.search().query(query)
Ejemplo n.º 4
0
    def test_get_many_users(self):
        UserDocument(name='willian', email='*****@*****.**',
                     _password='******',
                     ong_id=self.ong.id).save()
        limit = 10
        response = self.client.get("/user/?limit={limit}".format(limit=limit))
        decoded_response = json.loads(response.data.decode())

        self.assertEqual(len(decoded_response), 2)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 5
0
 def tearDown(self):
     UserDocument.drop_collection()
     OngDocument.drop_collection()
Ejemplo n.º 6
0
 def setUp(self):
     self.user = UserDocument(name="iury", email="*****@*****.**", _password="******").save()
Ejemplo n.º 7
0
class UserTests(unittest.TestCase):

    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()

    def tearDown(self):
        UserDocument.drop_collection()
        OngDocument.drop_collection()

    def test_get_one_user(self):
        response = self.client.get("/user/{id}".format(id=self.user.id))
        decoded_response = json.loads(response.data.decode())

        self.assertEquals(decoded_response, self.user.to_dict())

    def test_get_nonexistent_user(self):
        id_ = '123abc'
        response = self.client.get("/user/{id}".format(id=id_))

        self.assertEquals(response.status_code, 404)

    def test_get_many_users(self):
        UserDocument(name='willian', email='*****@*****.**',
                     _password='******',
                     ong_id=self.ong.id).save()
        limit = 10
        response = self.client.get("/user/?limit={limit}".format(limit=limit))
        decoded_response = json.loads(response.data.decode())

        self.assertEqual(len(decoded_response), 2)
        self.assertEqual(response.status_code, 200)

    def test_malformed_user_request(self):
        response = self.client.get("/user/")
        decoded_response = json.loads(response.data.decode())

        self.assertEqual(response.status_code, 400)
        self.assertDictEqual(decoded_response, {'message': 'You must provide limit or id'})

    def test_add_user(self):
        data = {
            'name': 'travis',
            'email': '*****@*****.**',
            'password': '******',
            'ong_id': self.ong.id
        }
        response = self.client.post("/user/", data=data)
        saved_user = UserDocument.objects.get(email='*****@*****.**')
        decoded_response = json.loads(response.data.decode())

        self.assertEqual(response.status_code, 201)
        self.assertDictEqual(decoded_response, saved_user.to_dict())

    def test_delete_user(self):
        id_ = self.user.id
        response = self.client.delete('/user/{id}'.format(id=id_))

        self.assertEqual(response.status_code, 204)

    def test_delete_user_insufficient_params(self):
        response = self.client.delete('/user/')
        decoded_response = json.loads(response.data.decode())

        self.assertEqual(response.status_code, 400)
        self.assertDictEqual(decoded_response, {"message": "You must provide an id"})

    def test_put_user_insufficient_params(self):
        response = self.client.put('/user/')
        decoded_response = json.loads(response.data.decode())

        self.assertEqual(response.status_code, 400)
        self.assertDictEqual(decoded_response, {"message": "You must provide an id"})

    def test_put_user(self):
        data = {"name": "newname", "email": "*****@*****.**"}
        response = self.client.put('/user/{id}'.format(id=self.user.id), data=data)
        user = UserDocument.objects.get(id=self.user.id)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(user.name, data['name'])
        self.assertEqual(user.email, data['email'])

    def test_put_not_found_user(self):
        response = self.client.put("/user/1012")

        self.assertEqual(response.status_code, 404)
 def setUp(self):
     UserDocument.drop_collection()
     self.user = UserDocument(name="iury", email="*****@*****.**", _password="******").save()