def test_get_envois():
    """Test get_envois with a mock."""
    with requests_mock.Mocker() as m:
        api_response = open("pydelivengo/tests/assets/get_envois_ok.json",
                            "rb",
                            encoding='utf8').read()
        m.get('https://mydelivengo.laposte.fr/api/v2.4/envois',
              text=api_response)

        api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
        result = api.get_envois()

        assert result == {
            "data": [{
                "id": "5256598",
                "id_support": "33",
                "id_utilisateur": "22852",
                "date_creation": "2018-01-18 10:48:37",
                "date_impression": "2018-01-18 10:48:37",
                "descriptif": "DESCRIPTIF DELIVENGO SUIVI 18",
                "total": "2",
                "plis": ["11349969", "11349970"]
            }],
            "recordsFiltered":
            1,
            "recordsTotal":
            1
        }
def test_get_user_info():
    """Test get_user_info  with a mock."""
    with requests_mock.Mocker() as m:
        api_response = open("pydelivengo/tests/assets/get_utilisateur_ok.json", "rb", encoding='utf8').read()
        m.get('https://mydelivengo.laposte.fr/api/v2.4/utilisateurs/0', text=api_response)

        api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
        result = api.get_user_info()

        assert result == {"data": {"id": "22852", "email": "johndoe@my_best_company.com",
                                   "nom": "Doe", "prenom": "John"}}
Esempio n. 3
0
def test_get_depot():
    """Test get_depot with a mock."""
    with requests_mock.Mocker() as m:
        api_response = open("pydelivengo/tests/assets/get_depot_ok.json", "rb", encoding='utf8').read()
        m.get('https://mydelivengo.laposte.fr/api/v2.4/depots/1814183', text=api_response)

        api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
        result = api.get_depot(1814183)

        assert result == {"data": {"id": 1814183, "id_utilisateur": 22855, "date": "2018-01-15 14:57:51",
                                   "num_coclico": "2205490", "num_siret": "",
                                   "bordereaux": [{"id": 1727987,  "numero": "0000000001",
                                                   "nb_pages": 2, "type": 35, "plis": []}]}
                          }
Esempio n. 4
0
def test_get_pli():
    """Test get_pli when the pdf is requested."""
    with requests_mock.Mocker() as m:
        api_response = open("pydelivengo/tests/assets/get_pli_pdf_ok.json",
                            "rb",
                            encoding='utf8').read()
        m.get('https://mydelivengo.laposte.fr/api/v2.4/plis/11437479',
              text=api_response)

        api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
        result = api.get_pli(11437479, print_pdf=True)

        # Check if 'id', 'plis' and 'documents_supports' are keys of result
        data_keys_set = set(result['data'].keys())
        assert {'id', 'documents_supports'}.issubset(data_keys_set)
Esempio n. 5
0
def test_get_plis():
    """Test get_plis with a mock."""
    with requests_mock.Mocker() as m:
        api_response = open("pydelivengo/tests/assets/get_plis_ok.json",
                            "rb",
                            encoding='utf8').read()
        m.get('https://mydelivengo.laposte.fr/api/v2.4/plis',
              text=api_response)

        api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
        result = api.get_plis()

        assert 'data' in result.keys()

        # Check if there are some keys in the result
        data_keys_set = set(result['data'][0].keys())
        assert {'id', 'id_envoi', 'numero',
                'date_creation'}.issubset(data_keys_set)
def test_get_envoi_pdf():
    """Test get_envoi with a mock."""
    with requests_mock.Mocker() as m:
        api_response = open("pydelivengo/tests/assets/get_envoi_ok.json",
                            "rb",
                            encoding='utf8').read()
        m.get('https://mydelivengo.laposte.fr/api/v2.4/envois/5306429',
              text=api_response)

        api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
        result = api.get_envoi(5306429)

        # Check if 'id', 'plis' and 'documents_supports' are keys of result
        data_keys_set = set(result['data'].keys())
        assert {
            'id', 'id_support', 'id_utilisateur', 'date_creation',
            'date_impression'
        }.issubset(data_keys_set)
def test_get_imputation():
    """Test get_imputation when imputation_id is none."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.get_imputation(imputation_id=None)
Esempio n. 8
0
def test_post_depot_param_none():
    """Test post_depot when data_dict is none."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.post_depot(data_dict=None)
Esempio n. 9
0
def test_get_depot_type_error():
    """Test get_depot when params is not a dictionary."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.get_depot(123, params='lolcatz')
Esempio n. 10
0
def test_get_depot_missing_parameter():
    """Test get_depot when depot_id is none."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.get_depot(depot_id=None)
Esempio n. 11
0
def test_delete_plis_missing_parameter():
    """Test delete_plis when pli_id is none."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.delete_plis(pli_id=None)
Esempio n. 12
0
def test_post_envoi_type_param_error():
    """Test post_envois when params is not a dictionary."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.post_envois(data_dict={}, params='')
Esempio n. 13
0
def test_delete_envois_type_error():
    """Test delete_envois when there is a type error on envoi_id."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.delete_envois(envoi_id='lolcatz')
def test_get_user_info_type_error():
    """Test get_user_info when user_id is not an integer."""
    api = PyDelivengo(api_authorization='Loremipsumdolorsitametconsectetu')
    with pytest.raises(PyDelivengoTypeError):
        # noinspection PyTypeChecker
        api.get_user_info(user_id='lolcatz')