Ejemplo n.º 1
0
def test_reports_missing_cards(mock_get_articles, mock_get_pids, db_session,
                               app):
    mock_get_pids.return_value = amock([123])
    mock_get_articles.return_value = amock([{
        'language': 1,  # English only
        'price': 0.1,
        'seller_username': '******',
        'seller_url': 'seller_url',
        'seller_id': 'seller_id',
        'seller_country': 'AT',
        'count': 1,
        'id': 456,
    }])
    result = get_pricing(get_wishlist(quantity=2, languages=['German']))
    assert result['error'] is None
    assert result['result'] == [{
        'missing_cards': [{
            'name': 'Shock',
            'quantity': 1
        }],
        'seller_id':
        'seller_id',
        'seller_url':
        'seller_url',
        'seller_username':
        '******',
        'seller_country':
        'AT',
        'total_count':
        1,
        'total_price':
        0.1
    }]
Ejemplo n.º 2
0
def test_gets_cards_from_multiple_articles(mock_get_articles, mock_get_pids,
                                           db_session, app):
    mock_get_pids.return_value = amock([123])
    mock_get_articles.return_value = amock([{
        'language': 1,
        'price': 0.5,
        'seller_username': '******',
        'seller_url': 'seller_url',
        'seller_id': 'seller_id',
        'count': 2,
        'seller_country': 'AT',
        'id': 456,
    }, {
        'language': 1,
        'price': 0.1,
        'seller_username': '******',
        'seller_country': 'AT',
        'seller_url': 'seller_url',
        'seller_id': 'seller_id',
        'seller_country': 'AT',
        'count': 1,
        'id': 456,
    }])
    result = get_pricing(get_wishlist(quantity=2))
    assert result['error'] is None
    assert result['result'][0]['total_count'] == 2
    assert result['result'][0]['total_price'] == 0.6
Ejemplo n.º 3
0
def test_calls_get_articles_with_correct_params_without_language(
        mock_get_articles, mock_get_pids, db_session, app):
    mock_get_pids.return_value = amock([123])
    mock_get_articles.return_value = amock([])
    get_pricing(get_wishlist(foil=True))
    mock_get_articles.assert_called_once_with(123,
                                              language_id=None,
                                              foil=True,
                                              min_condition=None)
Ejemplo n.º 4
0
def test_handles_duplicated_card_names_in_wishlist(mock_get_articles,
                                                   mock_get_pids, db_session,
                                                   app):
    mock_get_pids.return_value = amock([123])
    mock_get_articles.return_value = amock([{
        'language': 1,
        'price': 0.1,
        'seller_username': '******',
        'seller_url': 'seller_url',
        'seller_id': 'seller_id',
        'seller_country': 'AT',
        'count': 2,  # only two shocks are available
        'id': 456,
    }])
    wishlist = get_wishlist()
    wishlist['cards'].extend([{
        'name': 'Shock',
        'languages': [],
        'expansions': [],
        'quantity': 1
    }, {
        'name': 'Shock',
        'languages': [],
        'expansions': [],
        'quantity': 1
    }])  # effectively searching for 3 shocks
    result = get_pricing(wishlist)
    assert result['error'] is None
    assert result['result'] == [{
        'missing_cards': [{
            'name': 'Shock',
            'quantity': 1
        }],
        'seller_id':
        'seller_id',
        'seller_url':
        'seller_url',
        'seller_username':
        '******',
        'seller_country':
        'AT',
        'total_count':
        2,  # only 2 were available
        'total_price':
        0.2
    }]
Ejemplo n.º 5
0
async def test_handles_flip_cards(name, http_client):
    response = [
        get_product(name='Search for Azcanta / Azcanta, the Sunken Ruin')
    ]
    http_client.get.return_value = amock(response)
    api = MkmApi(http_client)
    result = await api.get_product_ids(name, expansions=None)
    assert result == [123]
Ejemplo n.º 6
0
async def test_filters_articles_by_foil(foil, params, http_client, app):
    response = amock([get_article()])
    http_client.get.return_value = response
    api = MkmApi(http_client)
    await api.get_articles('some_product_id', foil=foil)
    http_client.get.assert_called_once_with('articles/some_product_id',
                                            params=params,
                                            headers={},
                                            field='article')
Ejemplo n.º 7
0
async def test_filters_out_product_that_are_not_cards(http_client):
    response = amock([
        get_product(category='Magic Single', product_id=123),
        get_product(category='some other category', product_id=456),
    ])
    http_client.get.return_value = response
    api = MkmApi(http_client)
    result = await api.get_product_ids('Shock', expansions=None)
    assert result == [123]
Ejemplo n.º 8
0
async def test_calls_api_with_correct_params(name, exact, http_client):
    http_client.get.return_value = amock([get_product()])
    api = MkmApi(http_client)
    await api.get_product_ids(name, expansions=None)
    params = {'search': name.lower(), 'exact': exact, 'idGame': 1}
    http_client.get.assert_called_once_with('products/find',
                                            params=params,
                                            headers={},
                                            field='product')
Ejemplo n.º 9
0
async def test_filters_articles_by_min_condition(http_client, app):
    response = amock([get_article()])
    http_client.get.return_value = response
    api = MkmApi(http_client)
    await api.get_articles('some_product_id', min_condition='NM')
    params = {'minCondition': 'NM'}
    http_client.get.assert_called_once_with('articles/some_product_id',
                                            params=params,
                                            headers={},
                                            field='article')
Ejemplo n.º 10
0
async def test_filters_articles_by_language(http_client, app):
    response = amock([get_article()])
    http_client.get.return_value = response
    api = MkmApi(http_client)
    await api.get_articles('some_product_id', language_id=10)
    params = {'idLanguage': 10}
    http_client.get.assert_called_once_with('articles/some_product_id',
                                            params=params,
                                            headers={},
                                            field='article')
Ejemplo n.º 11
0
async def test_filters_products_by_expansion(http_client):
    response = amock([
        get_product(expansion='Kaladesh', product_id=123),
        get_product(expansion='Dominaria', product_id=456),
        get_product(expansion='Magic 2019', product_id=789),
    ])
    http_client.get.return_value = response
    api = MkmApi(http_client)
    result = await api.get_product_ids('Shock',
                                       expansions=['Magic 2019', 'Dominaria'])
    assert set(result) == {456, 789}
Ejemplo n.º 12
0
def test_single_product_single_article(mock_get_articles, mock_get_pids,
                                       db_session, app):
    mock_get_pids.return_value = amock([123])
    mock_get_articles.return_value = amock([{
        'language': 1,
        'price': 0.1,
        'seller_username': '******',
        'seller_url': 'seller_url',
        'seller_id': 'seller_id',
        'seller_country': 'AT',
        'count': 1,
        'id': 456,
    }])
    result = get_pricing(get_wishlist())
    assert result['error'] is None
    assert result['result'] == [{
        'missing_cards': [],
        'seller_id': 'seller_id',
        'seller_url': 'seller_url',
        'seller_username': '******',
        'total_count': 1,
        'total_price': 0.1,
        'seller_country': 'AT',
    }]
Ejemplo n.º 13
0
async def test_get_article(http_client, app):
    response = amock([get_article()])
    http_client.get.return_value = response
    api = MkmApi(http_client)
    result = await api.get_articles('some_product_id')
    http_client.get.assert_called_once_with('articles/some_product_id',
                                            params={},
                                            headers={},
                                            field='article')
    assert len(result) == 1
    assert result[0] == {
        'language': 1,
        'price': 0.1,
        'seller_username': '******',
        'seller_country': 'D',
        'seller_url': 'http://dummy.user.url/some_seller',
        'seller_id': 'some_id',
        'count': 1,
        'id': 123,
    }
Ejemplo n.º 14
0
def test_gets_correct_quantity_of_foil_cards(mock_get_articles, mock_get_pids,
                                             db_session, app):
    mock_get_pids.return_value = amock([123])

    async def get_articles(product_id, foil=None, **kwargs):
        if foil:
            return [{
                'language': 1,
                'price': 10,  # foil
                'seller_username': '******',
                'seller_url': 'seller_url',
                'seller_id': 'seller_id',
                'seller_country': 'AT',
                'count': 5,
                'id': 789,
            }]
        return [{
            'language': 1,
            'price': 0.1,
            'seller_username': '******',
            'seller_url': 'seller_url',
            'seller_id': 'seller_id',
            'seller_country': 'AT',
            'count': 20,
            'id': 456,
        }]

    mock_get_articles.side_effect = get_articles
    wishlist = get_wishlist(foil=False, quantity=10)
    wishlist['cards'].append({
        'name': 'Shock',
        'quantity': 5,
        'languages': [],
        'expansions': [],
        'foil': True
    })
    result = get_pricing(wishlist)
    print(result)
    assert result['error'] is None
    assert result['result'][0]['total_count'] == 15
    assert result['result'][0]['total_price'] == 51
Ejemplo n.º 15
0
def test_reportsc_cards_that_no_seller_has_as_missing(mock_get_articles,
                                                      mock_get_pids,
                                                      db_session, app):
    mock_get_pids.return_value = amock([123])

    async def get_articles(product_id, language_id=None, **kwargs):
        if language_id == 1:
            return [{
                'language': 1,
                'price': 10,
                'seller_username': '******',
                'seller_url': 'seller_url',
                'seller_id': 'seller_id',
                'seller_country': 'AT',
                'count': 4,
                'id': 789,
            }]
        return []  # no cards in other languages

    mock_get_articles.side_effect = get_articles
    wishlist = get_wishlist(foil=False, quantity=4, languages=['English'])
    wishlist['cards'].append({
        'name': 'Missing card',
        'quantity': 4,
        'languages': ['German'],
        'expansions': [],
    })
    result = get_pricing(wishlist)
    print(result)
    assert result['error'] is None
    assert result['result'][0]['total_count'] == 4
    assert result['result'][0]['total_price'] == 40
    assert result['result'][0]['missing_cards'] == [{
        'name': 'Missing card',
        'quantity': 4
    }]
Ejemplo n.º 16
0
        }]
    }


LANGS_MAP = {
    'English': 1,
    'French': 2,
    'German': 3,
}


def echo(arg):
    return arg


@mock.patch.object(MkmApi, 'get_product_ids', return_value=amock([]))
def test_no_products_found(mock_api, db_session, app):
    result = get_pricing(get_wishlist())
    assert result['error'] is None
    assert result['result'] == []


@mock.patch.object(MkmApi, 'get_product_ids')
@mock.patch.object(MkmApi, 'get_articles')
def test_single_product_single_article(mock_get_articles, mock_get_pids,
                                       db_session, app):
    mock_get_pids.return_value = amock([123])
    mock_get_articles.return_value = amock([{
        'language': 1,
        'price': 0.1,
        'seller_username': '******',
Ejemplo n.º 17
0
async def test_handles_split_cards(name, http_client):
    response = [get_product(name='Fire // Ice')]
    http_client.get.return_value = amock(response)
    api = MkmApi(http_client)
    result = await api.get_product_ids(name, expansions=None)
    assert result == [123]