Exemple #1
0
def test_app_sign_in(mocked_print, mocked_input):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    mocked_print.assert_any_call('*** SIGN IN ***')
    mocked_print.assert_any_call('0:\tExit')
    mocked_print.assert_any_call('Bye!')
    mocked_input.assert_called()
Exemple #2
0
def test_app_add_computer_with_duplicates(mocked_print, mocked_input,
                                          mocked_requests_get,
                                          mocked_requests_post):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    assert list(
        filter(lambda x: 'Computer already present in the list!' in str(x),
               mocked_print.mock_calls))
Exemple #3
0
def test_app_change_quantity_operation_cancelled(mocked_print, mocked_input,
                                                 mocked_requests_get,
                                                 mocked_requests_post):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    assert list(
        filter(lambda x: 'Operation cancelled!' in str(x),
               mocked_print.mock_calls))
Exemple #4
0
def test_app_sort_by_price(mocked_print, mocked_input, mocked_requests_get,
                           mocked_requests_post):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    mocked_input.assert_called()
    mocked_print.assert_called()
    assert list(
        filter(lambda x: '1   Computer                       Mac' in str(x),
               mocked_print.mock_calls))
Exemple #5
0
def test_app_sign_in_resists_wrong_password(mocked_print, mocked_input,
                                            mocked_requests_get,
                                            mocked_requests_post):
    with patch('builtins.open', mock_open()):
        App().run()
    mocked_print.assert_any_call('*** SIGN IN ***')
    mocked_requests_post.assert_called()
    mocked_requests_get.assert_called()
    mocked_print.assert_any_call('*** SHOPPING LIST ***')
Exemple #6
0
def test_app_remove_item(mocked_print, mocked_input, mocked_requests_get,
                         mocked_requests_post, mocked_requests_delete):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    assert list(
        filter(lambda x: 'Item removed!' in str(x), mocked_print.mock_calls))
    mocked_requests_delete.assert_called_with(
        url='http://localhost:8000/api/v1/shopping-list/edit/1',
        headers={
            'Authorization': 'Token 3be7163c1baea2a220777a82ec7e59a4ef545f26'
        })
Exemple #7
0
def test_app_change_quantity(mocked_print, mocked_input, mocked_requests_get,
                             mocked_requests_post, mocked_requests_patch):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    mocked_input.assert_called()
    mocked_print.assert_called()
    assert list(
        filter(lambda x: 'Quantity changed!' in str(x),
               mocked_print.mock_calls))
    mocked_requests_patch.assert_called_with(
        url='http://localhost:8000/api/v1/shopping-list/edit/1',
        headers={
            'Authorization': 'Token 3be7163c1baea2a220777a82ec7e59a4ef545f26'
        },
        data={'quantity': 5})
Exemple #8
0
def test_app_shopping_list(mocked_print, mocked_input, mocked_requests_get,
                           mocked_requests_post):
    with patch('builtins.open', mock_open()):
        App().run()
    mocked_print.assert_any_call('*** SIGN IN ***')
    mocked_print.assert_any_call('1:\tLogin')
    mocked_requests_post.assert_called()
    mocked_requests_get.assert_called()
    mocked_print.assert_any_call('*** SHOPPING LIST ***')
    mocked_requests_get.assert_called_once_with(
        url='http://localhost:8000/api/v1/shopping-list/',
        headers={
            'Authorization': 'Token 3be7163c1baea2a220777a82ec7e59a4ef545f26'
        })
    mocked_input.assert_called()
Exemple #9
0
def test_app_add_computer(mocked_print, mocked_input, mocked_requests_get,
                          mocked_requests_post):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    assert list(
        filter(lambda x: 'Computer added!' in str(x), mocked_print.mock_calls))
    mocked_requests_post.assert_called_with(
        url='http://localhost:8000/api/v1/shopping-list/add/',
        headers={
            'Authorization': 'Token 3be7163c1baea2a220777a82ec7e59a4ef545f26'
        },
        data={
            'name': 'Mi Air',
            'category': 'Computer',
            'manufacturer': 'Xiaomi',
            'price': 40000,
            'description': 'really excellent product',
            'quantity': 1
        })
Exemple #10
0
def test_app_add_smartphone_resists_wrong_price(mocked_print, mocked_input,
                                                mocked_requests_get,
                                                mocked_requests_post):
    with patch('builtins.open', mock_open()) as mocked_open:
        App().run()
    assert list(
        filter(lambda x: 'Smartphone added!' in str(x),
               mocked_print.mock_calls))
    mocked_requests_post.assert_called_with(
        url='http://localhost:8000/api/v1/shopping-list/add/',
        headers={
            'Authorization': 'Token 3be7163c1baea2a220777a82ec7e59a4ef545f26'
        },
        data={
            'name': 'Xperia z1',
            'category': 'Smartphone',
            'manufacturer': 'Sony',
            'price': 90000,
            'description': '',
            'quantity': 2
        })
Exemple #11
0
def test_app_registration_existent_user(mocked_print, mocked_input,
                                        mocked_requests_post):
    with patch('builtins.open', mock_open()):
        App().run()
    mocked_requests_post.assert_called()
    mocked_print.assert_any_call('This user already exists!')
Exemple #12
0
def test_app_sign_in_nonexistent_user(mocked_print, mocked_input,
                                      mocked_requests_post):
    with patch('builtins.open', mock_open()):
        App().run()
    mocked_requests_post.assert_called()
    mocked_print.assert_any_call('This user does not exist!')