Пример #1
0
def test_immutability(valid_random_number):
    dz_phone_number = DZPhoneNumber(valid_random_number())
    dz_phone_number2 = dz_phone_number.with_number(valid_random_number())

    assert dz_phone_number is not dz_phone_number2

    # Explicitly setting an attribute is prohibited
    with pytest.raises(TypeError):
        dz_phone_number.number = valid_random_number()
Пример #2
0
def updateMagasin(request, pk):
    user = request.user
    data = request.data
    magasin = Magasin.objects.get(_id=pk)
    if (data.get('telephone')):
        try:
            DZPhoneNumber(data['telephone'])
        except ValueError:
            content = {'detail': 'Ce numéro de telephone est erroné!!'}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    ##starting update
    magasin.nom = data['nom']

    magasin.categorie = Categorie.objects.get(_id=data['categorie'])
    print(data['categorie'])

    magasin.user = user

    if (data.get('telephone')):
        magasin.telephone = data['telephone']
        magasin.save()
    if (data.get('adresse')):
        magasin.adresse = data['adresse']
        magasin.save()
    if (data.get('latitude')):
        try:
            float(data['latitude'])
            magasin.latitude = data['latitude']
            magasin.save()
        except ValueError:
            content = {'detail': 'La latitude doit etre un numeric!!'}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)
    if (data.get('longitude')):
        try:
            float(data['longitude'])
            magasin.longitude = data['longitude']
            magasin.save()
        except ValueError:
            content = {'detail': 'La longitude doit etre un numeric!!'}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)
    if (data.get('overture')):
        magasin.overture = data['overture']
        magasin.save()
    if (data.get('fermeture')):
        magasin.fermeture = data['fermeture']
        magasin.save()
    if (data.get('commune')):

        magasin.commune = get_or_none(Communes, id=data['commune'])
        magasin.save()

    user.is_merchant = True
    user.save()
    if (request.FILES.get('image')):
        magasin.image = request.FILES.get('image')
        magasin.save()

    serializer = MagasinsCreateSerializer(magasin, many=False)
    return Response(serializer.data)
Пример #3
0
def test_equality():
    dz_phone_number = DZPhoneNumber("0550123456")
    dz_phone_number2 = DZPhoneNumber("+213 550123456")
    assert dz_phone_number == dz_phone_number2

    dz_phone_number = DZPhoneNumber("0550123456")
    dz_phone_number2 = DZPhoneNumber("00213 550123456")
    assert dz_phone_number == dz_phone_number2

    dz_phone_number = DZPhoneNumber("+(213)550123456")
    dz_phone_number2 = DZPhoneNumber("0 55-012-34-56")
    assert dz_phone_number == dz_phone_number2
Пример #4
0
def test_inequality():
    dz_phone_number = DZPhoneNumber("0550123456")
    dz_phone_number2 = DZPhoneNumber("0650123456")
    assert dz_phone_number != dz_phone_number2
Пример #5
0
def test_is_value_error():
    with pytest.raises(ValueError):
        DZPhoneNumber("bla bla")
def test_invalid_phone_numbers(invalid_phone_numbers):
    for number in invalid_phone_numbers:
        with pytest.raises(InvalidDZPhoneNumber):
            DZPhoneNumber(number)
def test_valid_phone_numbers_with_some_formatting(valid_phone_numbers):
    for number in valid_phone_numbers:
        dz_phone_number = DZPhoneNumber(number)
        assert dz_phone_number.raw_number == number
Пример #8
0
def test_is_mobile():
    number = DZPhoneNumber("0512345678")
    assert number.is_mobile()
    assert not number.is_landline()
Пример #9
0
def test_is_wilayas():

    for wilaya, dial_number in LandlinePrefix.__members__.items():
        pn = DZPhoneNumber(f"0{dial_number.value}123456")
        attr = getattr(pn, f"is_{wilaya.lower()}")
        assert attr()
Пример #10
0
def test_is_mobilis():
    number = DZPhoneNumber("0612345678")
    assert number.is_mobilis()
    assert not number.is_ooredoo()
    assert not number.is_djezzy()