Exemplo n.º 1
0
    def test_getDataSource(self):
        # arrange
        id = '5a8f1e368f7936badfbb0cfa'
        future = go(self.app.get, f'/dataSource/{id}')
        request = self.server.receives(
            Command(
                {
                    'find': 'dataSources',
                    'filter': {
                        '_id': mockup_oid(id)
                    },
                    'limit': 1,
                    'singleBatch': True
                },
                flags=4,
                namespace='app'))
        request.ok(
            cursor={
                'id':
                0,
                'firstBatch': [{
                    'name': 'bla',
                    'url': 'http://google.com/rest/api'
                }]
            })

        # act
        http_response = future()

        # assert
        self.assertIn('http://google.com/rest/api',
                      http_response.get_data(as_text=True))
Exemplo n.º 2
0
    def test_deleteDataSource_notFound(self):
        # arrange
        id = '5a8f1e368f7936badfbb0000'
        future = go(self.app.delete, f'/dataSource/{id}')
        request = self.server.receives(
            Command(
                {
                    'delete': 'dataSources',
                    'ordered': True,
                    'deletes': [{
                        'q': {
                            '_id': mockup_oid(id)
                        },
                        'limit': 1
                    }]
                },
                namespace='app'))
        request.ok({'acknowledged': True, 'n': 0})

        # act
        http_response = future()

        # assert
        self.assertIn(f'{id} not found', http_response.get_data(as_text=True))
        self.assertEqual(http_response.status_code, 404)
Exemplo n.º 3
0
    def test_addDataSource(self):
        # arrange
        id = '5a924d7a29a6e5484dcf68be'
        headers = [('Content-Type', 'application/json')]
        #   need to pass _id because pymongo creates one so it's impossible to match insert request without _ids
        toInsert = {'name': 'new', 'url': 'http://google.com', '_id': id}
        future = go(self.app.put,
                    '/dataSource',
                    data=dumps(toInsert),
                    headers=headers)
        request = self.server.receives(
            Command(
                {
                    'insert':
                    'dataSources',
                    'ordered':
                    True,
                    'documents': [{
                        'name': 'new',
                        'url': 'http://google.com',
                        '_id': mockup_oid(id)
                    }]
                },
                namespace='app'))
        request.ok(cursor={'inserted_id': id})

        # act
        http_response = future()

        # assert
        data = http_response.get_data(as_text=True)
        self.assertIn(id, data)
        self.assertEqual(http_response.status_code, 201)
Exemplo n.º 4
0
    def test_getDataSource_404(self):
        id = '5a8f1e368f7936badfbb0cfb'
        future = go(self.app.get, f'/dataSource/{id}')
        request = self.server.receives(
            Command(
                {
                    'find': 'dataSources',
                    'filter': {
                        '_id': mockup_oid(id)
                    },
                    'limit': 1,
                    'singleBatch': True
                },
                flags=4,
                namespace='app'))
        request.ok(cursor={'id': 0, 'firstBatch': []})

        # act
        http_response = future()

        # assert
        self.assertEqual(http_response.status_code, 404)
Exemplo n.º 5
0
            "_id": "5b3a7297d2e5ce5bbd3d0121",
            "login": "******",
            "password": "******",
            "role": "admin"
        }
    }
    access_token = jwt.encode(payload, private_key, algorithm="RS256")
    return {
        "access_token": access_token.decode(),
        "token_type": "JWT",
        "expire_in": 1800
    }


DISLIKER = {
    "shop_id": mockup_oid("5b3c30005e5aad3626b1a456"),
    "login": "******",
}
SHOP_RESULT = {
    "_id": mockup_oid("5b37fff8bbf300b7ef185042"),
    "name": "Restaurant Zayna",
    "address": "104 Boulevard Omar Al Khiam, Casablanca 20850",
    "longitude": 33.577321,
    "latitude": -7.607404
}
SHOP_REQ = {"_id": "5b37fff8bbf300b7ef185042"}


class TestLikedDislikedShop(unittest.TestCase):
    def setUp(self):
        """
Exemplo n.º 6
0
    """
    with open("private.pem", 'rb') as f:
        private_key = f.read()
    payload = {
        "iss": "localhost",
        "exp": time.time() + 1800,
        "user": {"_id" : "5b3a7297d2e5ce5bbd3d0121", "login" : "*****@*****.**", "password" : "123456", "role" : "admin"}
    }
    access_token = jwt.encode(payload, private_key, algorithm="RS256")
    return {
        "access_token": access_token.decode(),
        "token_type": "JWT",
        "expire_in": 1800
    }

SHOP_RESULT = { "_id" : mockup_oid("5b37fff8bbf300b7ef185042"), "name" : "Restaurant Zayna", "address" : "104 Boulevard Omar Al Khiam, Casablanca 20850", "longitude" : 33.577321, "latitude" : -7.607404}
SHOP_REQ={
            "name" : "Restaurant Zayna",
            "address" : "104 Boulevard Omar Al Khiam, Casablanca 20850",
            "longitude" : 33.577321,
            "latitude" : -7.607404
        }

class TestShop(unittest.TestCase):

    def setUp(self):
        """
        Prepare the test envirement.
        start the server to mockup the database
        """
        self.server = MockupDB(auto_ismaster=True, verbose=True)
Exemplo n.º 7
0
import unittest

from mockupdb import go, MockupDB, OpMsg
from mockupdb._bson import ObjectId as mockup_oid

from authservice import app
from authentication_service.common import generate_access_token


USER = {
        "_id": mockup_oid("5b37fff8bbf300b7ef185042"),
        "login": "******",
        "password": "******",
        "role": "admin"
    }

CLIENT = {
    "_id" : mockup_oid("5b37fff8bbf300b7ef185045"),
    "client_id" : "midleware1",
    "client_secret" : "1sfg135df1d32fsdf489d7q6sdq6s4d"
}


class SignInTest(unittest.TestCase):
    def setUp(self):
        self.server = MockupDB(auto_ismaster=True, verbose=True)
        self.server.run()
        app.testing = True
        app.config['MONGO_URI'] = self.server.uri
        self.app = app.test_client()