2

Мужики, я рискую словить много минусов, чую. Но глаза уже капитально замылились, а что не так - не пойму. Есть валидация протокола:

def is_url_with_correct_protocol(url):
    # Correct mean is https or http
    from urllib.parse import urlparse
    scheme = urlparse(url).scheme
    if scheme != "http" or scheme != "https":
        return False
    return True

Есть тест:

def test_is_url_with_correct_protocol(self):
    self.assertFalse(helpers.is_url_with_correct_protocol('vk.com/abc'))
    self.assertFalse(helpers.is_url_with_correct_protocol('ftp://vk.com/abc'))
    self.assertTrue(helpers.is_url_with_correct_protocol('http://vk.com/abc'))
    self.assertTrue(helpers.is_url_with_correct_protocol('https://vk.com/abc'))

Который благополучно валится. Функция ведет себя не пойми как, что я только не делал.

    self.assertTrue(helpers.is_url_with_correct_protocol('http://vk.com/abc'))
AssertionError: False is not true

1 ответ 1

2

if scheme != "http" and scheme != "https":

P.S.

Вам стоило бы обдумать тему отмечания ответов на Ваши вопросы как принятых.

2
  • Спасибо! Стыдно..) Отмечу через 9 минут, тайм аут сайта не позволяет 27 ноя 2017 в 17:36
  • На здоровье. Успехов!
    – user176262
    27 ноя 2017 в 17:36

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.