Пример #1
0
def test_refresh():
    clearDatabase()
    userId = registerUser('loginTest', 'login_pass')
    resp = requests.post(f'{url}/login',
                         json={
                             'login': '******',
                             'password': '******'
                         }).json()
    accessToken, refreshToken = resp['access'], resp['refresh']

    resp = requests.post(f'{url}/refresh',
                         headers={
                             'authorization': f'Bearer {refreshToken}'
                         }).json()

    newAccessToken, newRefreshToken = resp['access'], resp['refresh']

    # old access do not work
    invalidResp = requests.get(
        f'{url}/whoami', headers={'authorization': f'Bearer {accessToken}'})
    assert invalidResp.status_code == 400
    assert_that(invalidResp.json()).is_equal_to({'error': 'Wrong token'})

    # old refresh do not work
    invalidResp = requests.post(
        f'{url}/refresh', headers={'authorization': f'Bearer {refreshToken}'})
    assert invalidResp.status_code == 400
    assert_that(invalidResp.json()).is_equal_to({'error': 'Wrong token'})

    resp = requests.get(f'{url}/whoami',
                        headers={
                            'authorization': f'Bearer {newAccessToken}'
                        }).json()
    assert_that(resp).is_equal_to({'id': userId, 'login': '******'})
Пример #2
0
def test_login():
    clearDatabase()
    userId = registerUser('loginTest', 'login_pass')

    resp = requests.post(f'{url}/login',
                         json={
                             'login': '******',
                             'password': '******'
                         })
    accessToken = resp.json()['access']
    resp = requests.get(f'{url}/whoami',
                        headers={
                            'authorization': f'Bearer {accessToken}'
                        }).json()
    assert_that(resp).is_equal_to({'id': userId, 'login': '******'})

    # test invalid password
    respInvalid = requests.post(f'{url}/login',
                                json={
                                    'login': '******',
                                    'password': '******'
                                })
    assert respInvalid.status_code == 400
    assert_that(respInvalid.json()).is_equal_to(
        {'error': 'Invalid credentials'})
Пример #3
0
    def __init__(self):
        self.userInfo = common.registerUser(
            config.useGUI)  #Inital info-box with subjectNUM and INITALS

        self.baseRates = excelConfig.excelBaseRates()
        self.subjectExcel = excelConfig.excelNewSubject(self.userInfo)
        self.edfFile = eyeConfig.eyeConfigFile(self.userInfo)
        self.audioDevice = sd.default.device
Пример #4
0
def test_create_order_authorized():
    clearDatabase()
    userId = registerUser('test', 'test_pass')
    requestAuthorized = RequestAuthorized('test', 'test_pass')
    resp = requestAuthorized.post(f'{url}/order',
                                  json={
                                      'address': 'Lenina street',
                                      'name': 'James',
                                      'surname': 'Bond',
                                      'products': {
                                          1: 2,
                                          3: 1
                                      }
                                  }).json()
    orderId = resp['id']

    result = blockingDatabaseClient.query(f"""
        SELECT id, user_id, address, name, surname, status, shipping_price
        FROM public.orders
        WHERE id = {orderId}
    """)
    expectedResult = [(orderId, userId, 'Lenina street', 'James', 'Bond',
                       'NEW', Decimal('15.4300000000'))]
    assert_that(result).is_equal_to(expectedResult)
Пример #5
0
 def __init__(self):
     self.userInfo = common.registerUser(config.useGUI)
     print(self.userInfo)
     self.baseRates = excelConfig.excelBaseRates()
     self.subjectExcel = excelConfig.excelNewSubject(self.userInfo)
     self.edfFile = eyeConfig.eyeConfigFile(self.userInfo)
Пример #6
0
def test_get_orders():
    clearDatabase()
    userId = registerUser('test', 'test_pass')
    requestAuthorized = RequestAuthorized('test', 'test_pass')

    bodies = [{
        'address': 'Lenina street',
        'name': 'James',
        'surname': 'Bond',
        'products': {
            1: 2,
            3: 1
        }
    }, {
        'address': 'Boulevard of broken dreams',
        'name': 'Billy',
        'surname': 'Joe',
        'products': {
            2: 1,
            3: 2
        }
    }, {
        'address': 'Street of Rage',
        'name': 'Axel',
        'surname': 'Blaze',
        'products': {
            1: 1,
            3: 2,
            5: 3
        }
    }]

    orderIds = []

    for body in bodies:
        resp = requestAuthorized.post(f'{url}/order', json=body).json()
        orderIds.append(resp['id'])

    result = requestAuthorized.get(f'{url}/order', json={}).json()
    expectedResult = [{
        'id':
        orderIds[0],
        'userId':
        userId,
        'address':
        'Lenina street',
        'name':
        'James',
        'surname':
        'Bond',
        'status':
        'New order',
        'products': [{
            'id': 1,
            'name': 'margarita',
            'picture': 'margarita.png',
            'price': '12.07',
            'amount': 2
        }, {
            'id': 3,
            'name': 'carbonara',
            'picture': 'carbonara.png',
            'price': '11.26',
            'amount': 1
        }],
        'shippingPrice':
        '15.43'
    }, {
        'id':
        orderIds[1],
        'userId':
        userId,
        'address':
        'Boulevard of broken dreams',
        'name':
        'Billy',
        'surname':
        'Joe',
        'status':
        'New order',
        'products': [{
            'id': 2,
            'name': 'pepperoni',
            'picture': 'pepperoni.png',
            'price': '10.75',
            'amount': 1
        }, {
            'id': 3,
            'name': 'carbonara',
            'picture': 'carbonara.png',
            'price': '11.26',
            'amount': 2
        }],
        'shippingPrice':
        '15.43'
    }, {
        'id':
        orderIds[2],
        'userId':
        userId,
        'address':
        'Street of Rage',
        'name':
        'Axel',
        'surname':
        'Blaze',
        'status':
        'New order',
        'products': [{
            'id': 1,
            'name': 'margarita',
            'picture': 'margarita.png',
            'price': '12.07',
            'amount': 1
        }, {
            'id': 3,
            'name': 'carbonara',
            'picture': 'carbonara.png',
            'price': '11.26',
            'amount': 2
        }, {
            'id': 5,
            'name': 'four cheeses',
            'picture': 'four_cheeses.png',
            'price': '12.5',
            'amount': 3
        }],
        'shippingPrice':
        '15.43'
    }]
    assert_that(result).is_equal_to(expectedResult)

    # test unauthorized
    invalidResp = requests.get(f'{url}/order', json={})
    assert invalidResp.status_code == 401
Пример #7
0
def test_get_orders_with_currency():
    clearDatabase()
    userId = registerUser('test', 'test_pass')
    requestAuthorized = RequestAuthorized('test', 'test_pass')

    bodies = [{
        'address': 'Lenina street',
        'name': 'James',
        'surname': 'Bond',
        'products': {
            1: 2
        }
    }, {
        'address': 'Boulevard of broken dreams',
        'name': 'Billy',
        'surname': 'Joe',
        'products': {
            2: 1
        }
    }]
    orderIds = []
    for body in bodies:
        resp = requestAuthorized.post(f'{url}/order', json=body).json()
        orderIds.append(resp['id'])

    result = requestAuthorized.get(f'{url}/order', json={
        'currency': 'RUB'
    }).json()
    expectedResult = [{
        'id':
        orderIds[0],
        'userId':
        userId,
        'address':
        'Lenina street',
        'name':
        'James',
        'surname':
        'Bond',
        'status':
        'New order',
        'products': [{
            'id': 1,
            'name': 'margarita',
            'picture': 'margarita.png',
            'price': '936.3906',
            'amount': 2
        }],
        'shippingPrice':
        '1197.0594'
    }, {
        'id':
        orderIds[1],
        'userId':
        userId,
        'address':
        'Boulevard of broken dreams',
        'name':
        'Billy',
        'surname':
        'Joe',
        'status':
        'New order',
        'products': [{
            'id': 2,
            'name': 'pepperoni',
            'picture': 'pepperoni.png',
            'price': '833.985',
            'amount': 1
        }],
        'shippingPrice':
        '1197.0594'
    }]
    assert_that(result).is_equal_to(expectedResult)