Example #1
0
def test_register_invalid_username(client, session):
    # valid
    resp = register(client, "*****@*****.**", "lasagnas",
                    "garfield", "I am lasagna")
    assert resp.status_code == 200

    resp = json.loads(resp.data)
    assert "created_at" in resp
    assert "access_token" in resp

    # Invalid 1
    resp = register(client, "*****@*****.**", "big_potat",
                    "ImUnique", "I am unique")
    assert resp.status_code == 400

    resp = json.loads(resp.data)
    # should have an error
    assert "error" in resp
    assert "ap_id" in resp["error"]

    # Invalid 2
    resp = register(client, "*****@*****.**", "to-to", "ImUnique",
                    "I am unique")
    assert resp.status_code == 400

    resp = json.loads(resp.data)
    # should have an error
    assert "error" in resp
    assert "ap_id" in resp["error"]
Example #2
0
def test_profile(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTP")
    helpers.login(client, "*****@*****.**", "fluttershy")
    rv = client.get("/user", follow_redirects=True)
    assert b"Please fill me !" in rv.data
    assert b"Please fill me !" in rv.data
    helpers.logout(client)
Example #3
0
 def test_valid_login(self):
     self.app.get('/register', follow_redirects=True)
     register(self, '*****@*****.**', 'FlaskIsAwesome',
              'FlaskIsAwesome')
     self.app.get('/login', follow_redirects=True)
     response = login(self, '*****@*****.**', 'FlaskIsAwesome')
     self.assertIn(b'*****@*****.**', response.data)
Example #4
0
def test_change_password(client, session):
    init_password = "******"
    new_password = "******"

    register(client, "*****@*****.**", init_password, "UserB")

    # Can login with initial password
    rv = login(client, "*****@*****.**", init_password)
    assert b"Logged as UserB" in rv.data

    # Change password
    resp = client.post(
        "/change",
        data=dict(password=init_password,
                  new_password=new_password,
                  new_password_confirm=new_password),
        follow_redirects=True,
    )

    assert resp.status_code == 200
    assert b"You successfully changed your password." in resp.data

    # Logout
    logout(client)

    # Test login with new password
    resp = login(client, "*****@*****.**", new_password)
    print(resp.data)
    assert b"Logged as UserB" in resp.data
    logout(client)

    # Test login with old password
    resp = login(client, "*****@*****.**", init_password)
    assert b"Invalid password" in resp.data
Example #5
0
def test_logging_user(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTLU")
    helpers.login(client, "*****@*****.**", "fluttershy")
    rv = client.get("/user", follow_redirects=True)
    assert b"*****@*****.**" in rv.data
    helpers.logout(client)
    assert b"Logged as UserTLU" in rv.data
Example #6
0
def test_add_contact(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTAC")
    helpers.login(client, "*****@*****.**", "fluttershy")
    helpers.update_profile(client, "F0COIN", "JN18CX")
    rv = helpers.add_contact(client, "F4TEST", "JN11DW")
    assert b"<td>F4TEST</td>" in rv.data
    assert b"<td>783.0 Km</td>" in rv.data
    assert b"<td>179.0</td>" in rv.data
    assert b"<td>S</td>" in rv.data
Example #7
0
 def test_duplicate_email_user_registration_error(self):
     self.app.get('/register', follow_redirects=True)
     register(self, '*****@*****.**', 'FlaskIsAwesome',
              'FlaskIsAwesome')
     self.app.get('/register', follow_redirects=True)
     response = register(self, '*****@*****.**',
                         'FlaskIsReallyAwesome', 'FlaskIsReallyAwesome')
     self.assertIn(b'ERROR! Email ([email protected]) already exists.',
                   response.data)
Example #8
0
def test_add_contact_missing_locator(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy",
                     "UserTACML")
    helpers.login(client, "*****@*****.**", "fluttershy")
    helpers.update_profile(client, "F4JFD", "JN09CX")
    rv = client.post("/contacts/new",
                     data=dict(callsign="F4TEST"),
                     follow_redirects=True)
    assert b"QTH is too broad or empty, please input valid QTH" in rv.data
Example #9
0
def test_add_contact_missing_call(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy",
                     "UserTACMC")
    helpers.login(client, "*****@*****.**", "fluttershy")
    helpers.update_profile(client, "F4JFD", "JN09CX")
    rv = client.post("/contacts/new",
                     data=dict(gridsquare="JN18CX"),
                     follow_redirects=True)
    assert b"This field is required." in rv.data
Example #10
0
 def test_user_profile_page(self):
     self.app.get('/register', follow_redirects=True)
     register(self, '*****@*****.**', 'FlaskIsAwesome',
              'FlaskIsAwesome')
     response = self.app.get('/user_profile')
     self.assertEqual(response.status_code, 200)
     self.assertIn(b'Email Address', response.data)
     self.assertIn(b'Account Actions', response.data)
     self.assertIn(b'Statistics', response.data)
     self.assertIn(b'First time logged in. Welcome!', response.data)
Example #11
0
def register_page():
    if request.method == 'POST':  # Handle registration request
        try:
            helpers.register(request)
        except RegistrationException as e:
            return render_template('register.html', error=e.message)

        flash('Registration successful')
        return redirect(url_for('show_entries'))
    else:
        return render_template('register.html', error=None)
Example #12
0
def test_delete_contact(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTDC")
    helpers.login(client, "*****@*****.**", "fluttershy")
    helpers.update_profile(client, "F4JFD", "JN18CX")
    rv = helpers.add_contact(client, "F4TEST", "JN11DW")
    contact_id = helpers.get_contact_id(rv.data, "F4TEST")
    rv = client.get(f"/contacts/{contact_id}/delete")
    assert b"<td>F4TEST</td>" not in rv.data
    assert b"<td>783.0 Km</td>" not in rv.data
    assert b"<td>179.0</td>" not in rv.data
    assert b"<td>S</td>" not in rv.data
Example #13
0
 def test_user_profile_page_after_logging_in(self):
     self.app.get('/register', follow_redirects=True)
     register(self, '*****@*****.**', 'FlaskIsAwesome',
              'FlaskIsAwesome')
     self.app.get('/logout', follow_redirects=True)
     login(self, '*****@*****.**', 'FlaskIsAwesome')
     response = self.app.get('/user_profile')
     self.assertEqual(response.status_code, 200)
     self.assertIn(b'Email Address', response.data)
     self.assertIn(b'Account Actions', response.data)
     self.assertIn(b'Statistics', response.data)
     self.assertIn(b'Last Logged In: ', response.data)
Example #14
0
def test_edit_contact(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTEC")
    helpers.login(client, "*****@*****.**", "fluttershy")
    helpers.update_profile(client, "F8TEST", "JN18CX")
    rv = helpers.add_contact(client, "F4TEST", "JN11DW")
    contact_id = helpers.get_contact_id(rv.data, "F4TEST")
    rv = client.post(f"/contacts/{contact_id}/edit",
                     follow_redirects=True,
                     data=dict(callsign="F8COIN", gridsquare="JN11DW"))
    assert b"<td>F8COIN</td>" in rv.data
    assert b"<td>783.0 Km</td>" in rv.data
    assert b"<td>179.0</td>" in rv.data
    assert b"<td>S</td>" in rv.data
Example #15
0
def test_login_logout(client, session):
    """Make sure login and logout works."""

    resp = register(client, "*****@*****.**", "fluttershy", "UserA",
                    "User A")
    assert resp.status_code == 200

    resp = json.loads(resp.data)
    assert "created_at" in resp
    assert "access_token" in resp

    rv = login(client, "*****@*****.**", "fluttershy")
    rv = client.get("/home")
    assert rv.status_code == 200
    assert b"Logged as UserA" in rv.data

    rv = logout(client)
    rv = client.get("/home")
    assert rv.status_code == 200
    assert b"UserA" not in rv.data

    rv = login(client, "*****@*****.**" + "x", "fluttershy")
    assert rv.status_code == 200
    assert b"Specified user does not exist" in rv.data

    rv = login(client, "*****@*****.**", "fluttershy" + "x")
    assert rv.status_code == 200
    assert b"Invalid password" in rv.data
Example #16
0
def test_webfinger(client, session):
    resp = register(client, "*****@*****.**", "fluttershy",
                    "TestWebfinger", "Test Webfinger")
    assert resp.status_code == 200

    resp = json.loads(resp.data)
    assert "created_at" in resp
    assert "access_token" in resp

    rv = client.get(
        f"/.well-known/webfinger?resource=acct:TestWebfinger@{current_app.config['AP_DOMAIN']}"
    )
    assert rv.status_code == 200

    assert rv.headers["Content-Type"] == "application/jrd+json; charset=utf-8"

    datas = rv.json

    assert "aliases" in datas
    assert f"https://{current_app.config['AP_DOMAIN']}/user/TestWebfinger" in datas[
        "aliases"]
    assert "links" in datas
    assert "subject" in datas
    assert datas[
        "subject"] == f"acct:TestWebfinger@" f"{current_app.config['AP_DOMAIN']}"
Example #17
0
def test_register_two_identical_users(client, session):
    # Will register
    register(client, "*****@*****.**", "fluttershy", "ImUnique")
    logout(client)
    # Try to register another identical
    resp = client.post(
        "/register",
        data=dict(email="*****@*****.**",
                  password="******",
                  password_confirm="fluttershy",
                  name="ImUnique"),
        follow_redirects=True,
    )
    # should error
    assert b"Logged as" not in resp.data
    assert b"[email protected] is already associated " b"with an account." in resp.data
    assert b"Username already taken" in resp.data
    assert resp.status_code == 200
Example #18
0
def test_register_two_identical_users(client, session):
    # Will register
    resp = register(client, "*****@*****.**", "fluttershy",
                    "ImUnique", "I am unique")
    assert resp.status_code == 200

    resp = json.loads(resp.data)
    assert "created_at" in resp
    assert "access_token" in resp

    # Try to register another identical
    resp = register(client, "*****@*****.**", "fluttershy",
                    "ImUnique", "I am unique")
    assert resp.status_code == 400

    resp = json.loads(resp.data)
    # should have an error
    assert "error" in resp
    assert "ap_id" in resp["error"]
Example #19
0
def test_login_logout(client, session):
    """Make sure login and logout works."""

    register(client, "*****@*****.**", "fluttershy", "UserA")

    rv = login(client, "*****@*****.**", "fluttershy")
    assert rv.status_code == 200
    assert b"Logged as UserA" in rv.data

    rv = logout(client)
    assert rv.status_code == 200
    assert b"UserA" not in rv.data

    rv = login(client, "*****@*****.**" + "x", "fluttershy")
    assert rv.status_code == 200
    assert b"Specified user does not exist" in rv.data

    rv = login(client, "*****@*****.**", "fluttershy" + "x")
    assert rv.status_code == 200
    assert b"Invalid password" in rv.data
Example #20
0
def test_webfinger_case(client, session):
    register(client, "*****@*****.**", "fluttershy",
             "TestWebfingerCase")
    logout(client)

    rv = client.get(
        f"/.well-known/webfinger?resource=acct:testwebfingercase@{current_app.config['AP_DOMAIN']}"
    )
    assert rv.status_code == 200

    assert rv.headers["Content-Type"] == "application/jrd+json; charset=utf-8"

    datas = rv.json

    assert "aliases" in datas
    assert f"https://{current_app.config['AP_DOMAIN']}" f"/user/TestWebfingerCase" in datas[
        "aliases"]
    assert "links" in datas
    assert "subject" in datas
    assert datas[
        "subject"] == f"acct:TestWebfingerCase@" f"{current_app.config['AP_DOMAIN']}"
Example #21
0
def test_change_password(client, session):
    pytest.skip("outdated test :(")
    init_password = "******"
    new_password = "******"

    resp = register(client, "*****@*****.**", init_password, "UserB",
                    "User B")
    assert resp.status_code == 200

    resp = json.loads(resp.data)
    assert "created_at" in resp
    assert "access_token" in resp

    # Can login with initial password
    rv = login(client, "*****@*****.**", init_password)
    rv = client.get("/home")
    assert rv.status_code == 200
    assert b"Logged as UserB" in rv.data

    # Change password
    # no follow redirect or boom
    resp = client.post(
        "/change",
        data=dict(password=init_password,
                  new_password=new_password,
                  new_password_confirm=new_password),
        follow_redirects=False,
    )

    assert resp.status_code == 302

    # Logout
    logout(client)

    # Test login with new password
    resp = login(client, "*****@*****.**", new_password)
    rv = client.get("/home")
    print(resp.data)
    # assert b"Logged as UserB" in resp.data
    logout(client)

    # Test login with old password
    resp = login(client, "*****@*****.**", init_password)
    assert b"Invalid password" in resp.data
Example #22
0
 def test_missing_field_user_registration_error(self):
     self.app.get('/register', follow_redirects=True)
     response = register(self, '*****@*****.**', 'FlaskIsAwesome', '')
     self.assertIn(b'This field is required.', response.data)
Example #23
0
def test_user_in_bdd(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy",
                     "UserTUIB")
    a = User.query.filter(User.name == "UserTUIB").first()
    assert a is not None
Example #24
0
def test_add_contact_no_locator(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy",
                     "UserTACNL")
    helpers.login(client, "*****@*****.**", "fluttershy")
    rv = helpers.add_contact(client, "F4TEST", "JN11DW")
    assert b"Missing locator_qso or locator_user" in rv.data
Example #25
0
def register():
    if request.method == "POST":
        return helpers.register()
    else:
        return render_template("register.html")
Example #26
0
def test_registration(client, session, app):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTR")
Example #27
0
 def test_valid_user_registration(self):
     self.app.get('/register', follow_redirects=True)
     response = register(self, '*****@*****.**', 'FlaskIsAwesome',
                         'FlaskIsAwesome')
     self.assertIn(b'Thanks for registering!', response.data)
Example #28
0
print()
print('**** E-ATM ****')
print()

# The user chooses whether to register or sign in
while True:		
	try:
		option = int(input('\nWhat do you want to do?\n1) Register\n2) Sign in\n'))
	except:
		option = 0
	if option == 1 or option == 2:
		break

if option == 1:
	user = register()
else:
	user = login()

# The user chooses an option:
# 1) See user information
# 2) Balance check
# 3) Deposit money
# 4) Withdraw money
# 5) Change pin code
# 6) Exit
options = '\nWhat do you want to do?\n1) SEE USER INFO\n2) CHECK BALANCE\n3) DEPOSIT MONEY\n4) WITHDRAW MONEY\n5) CHANGE PIN\n6) EXIT\n'

while True:
	try:
		option = int(input(options))
Example #29
0
def test_profile_edit(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTPE")
    helpers.login(client, "*****@*****.**", "fluttershy")
    rv = helpers.update_profile(client, "N0CALL", "JN18CX")
    assert b"<td>N0CALL</td>" in rv.data
    assert b"<td>JN18CX</td>" in rv.data
Example #30
0
def test_nonexist_logbook(client, session):
    helpers.register(client, "*****@*****.**", "fluttershy", "UserTNL")
    rv = client.get("/user/UserTNL/logbook/1-test", follow_redirects=True)
    assert b"Logbook not found" in rv.data