def test_05_post_activate(self): mock_redis_save_user("*****@*****.**", hash_password("45eez**AB"), 1234) "Wrong Authorization header" r = self.app.post('http://*****:*****@gmail.com", "abC123*"), 'Content-type': 'application/json', 'Accept': 'text/plain', }) self.assertEqual(r.status_code, 401)
def sendemail(sender, receiver, text): data = {'sender': sender, 'receiver': receiver, 'text': text} auth_token = basicauth_encode(SMTP_API_CONFIG['user'], SMTP_API_CONFIG['password']) headers = { 'Authorization': auth_token, 'Content-type': 'application/json', 'Accept': 'text/plain', } try: response = requests.post(SMTP_API_CONFIG["api_sendemail_url"], data=json.dumps(data), headers=headers) except Exception as err: raise SendEmailError(err.args) if response.status_code not in [200, 201]: raise SendEmailError() return response.status_code
def test_chain_register(self): r = self.app.post('http://0.0.0.0:5000/api/register', data=json.dumps({ 'email': "*****@*****.**", "password": "******" }), headers={'Content-type': 'application/json'}) self.assertEqual(r.status_code, 200) mock_redis_save_user("*****@*****.**", hash_password("pASs123*"), 7568) r2 = self.app.post('http://0.0.0.0:5000/api/activate', data=json.dumps({'code': 7568}), headers={ 'Authorization': basicauth_encode("*****@*****.**", "pASs123*"), 'Content-type': 'application/json', 'Accept': 'text/plain', }) self.assertEqual(r2.status_code, 201)
def test_basicauth_encode(self): email, password = "******", "45eez**1A777" self.assertEqual(basicauth_encode(email, password), "Basic YWJjQGdtYWlsLmNvbTo0NWVleioqMUE3Nzc=")