def test_get_all_breaches_raise_if_not_string(self): # def get_all_breaches(domain=1): with pytest.raises(AttributeError) as excinfo: # Will raise because the domain must be a string (specifically, six.text_type) pyhibp.get_all_breaches(domain=1) assert "The domain parameter, if specified, must be a string" in str( excinfo.value)
def test_user_agent_must_be_set_or_raise(self, monkeypatch): """ The HIBP backend requires a User-Agent; ensure we're forcing one to be set on all functions """ monkeypatch.setitem(pyhibp.pyHIBP_HEADERS, 'User-Agent', None) with pytest.raises(RuntimeError) as execinfo: pyhibp.get_all_breaches() assert "The User-Agent must be set. Call pyhibp.set_user_agent(ua=your_agent_string) first." in str( execinfo.value)
def test_get_all_breaches_filter_to_domain(self): # def get_all_breaches(domain=TEST_DOMAIN): resp = pyhibp.get_all_breaches(domain=TEST_DOMAIN) assert isinstance(resp, list) # There can be multiple breaches in the system for a given domain assert len(resp) >= 1 assert isinstance(resp[0], dict) assert resp[0]['Name'] == TEST_DOMAIN_NAME
def email(): pyhibp.set_user_agent( ua="Awesome application/0.0.1 (An awesome description)") HIBP_API_KEY = 'aa3876c762b9457385e2278befd83ac8' if HIBP_API_KEY: pyhibp.set_api_key(key=HIBP_API_KEY) resp = pyhibp.get_all_breaches() dict = [] email_name = "*****@*****.**" _resp = pyhibp.get_account_breaches(account=email_name, truncate_response=True) print(_resp) for x in _resp: email = models.infected_email(email=email_name, site=x['Name']) email.save() print(x['Name'])
def getbreaches(): pyhibp.set_user_agent( ua="Awesome application/0.0.1 (An awesome description)") HIBP_API_KEY = 'aa3876c762b9457385e2278befd83ac8' if HIBP_API_KEY: # Set the API key prior to using the functions which require it. pyhibp.set_api_key(key=HIBP_API_KEY) resp = pyhibp.get_all_breaches() dict = [] print("this is for all the breach") for x in resp: dict.append({ 'name': x['Name'], 'domain': x['Domain'], 'time': x['PwnCount'] }) for y in dict: print(y['name']) book = models.all_breaches(name=y['name'], domain=y['domain'], time_breached=y['time']) book.save()
def test_get_all_breaches(self): # def get_all_breaches(domain=None): resp = pyhibp.get_all_breaches() assert isinstance(resp, list) assert len(resp) > 50 assert isinstance(resp[0], dict)
def test_get_all_breaches_false_if_domain_does_not_exist(self): resp = pyhibp.get_all_breaches(domain=TEST_NONEXISTENT_ACCOUNT_NAME) assert not resp assert isinstance(resp, bool)