def setUp(self): self._citizen = user.Citizen(-1, "Test Testington", "*****@*****.**", [], [], "Teststrasse 10", "Testerup", "1000") citizen_header = { "user": self._citizen.serialize().replace("\"", "\\\"") } self._citizen = user.deserialize( get_response( requests.post( "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/user/", headers=citizen_header)))
def get_citizen(id): conn = psycopg2.connect(connect_str) cursor = conn.cursor() cursor.execute( "SELECT id, name, email, address, city, postnr FROM users, citizen WHERE users.id = citizen.userID AND users.id = %s", [id]) ctz = cursor.fetchone() contacts = get_citizen_contacts(ctz[0]) devices = get_user_devices(ctz[0]) conn.commit() cursor.close() conn.close() return user.Citizen(ctz[0], ctz[1], ctz[2], contacts, devices, ctz[3], ctz[4], ctz[5])
def get_all_citizens(): allCitizens = [] conn = psycopg2.connect(connect_str) cursor = conn.cursor() cursor.execute( "SELECT id, name, email, address, city, postnr FROM users, citizen WHERE users.id = citizen.userID") ctzs = cursor.fetchall() for ctz in ctzs: contacts = get_citizen_contacts(ctz[0]) devices = get_user_devices(ctz[0]) allCitizens.append(user.Citizen(ctz[0], ctz[1], ctz[2], contacts, devices, ctz[3], ctz[4], ctz[5])) conn.commit() cursor.close() conn.close() return allCitizens
def test_get_and_post_user_citizen(self): _user = user.Citizen(-1, "Test Testington", "*****@*****.**", [], [], "Teststrasse 10", "Testerup", "1000") user_post_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/user/" user_delete_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/user/" user_post_header = { "user": _user.serialize().replace("\"", "\\\""), "password": "******" } user_get_header = {"email": "*****@*****.**", "password": "******"} _user = user.deserialize( get_response(requests.post(user_post_uri, headers=user_post_header))) user_get_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/user/" _user_response = user.deserialize( get_response(requests.get(user_get_uri, headers=user_get_header))) user_delete_header = { "user": _user_response.serialize().replace("\"", "\\\""), "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMjM0IiwidXNlcl9yb2xlIjoidXNlckFkbWluIn0._zMvLSI7elh4ebv-1iaE8nXYdbzjyvpBNlDNhNSJMc0" } _delete_response = user.deserialize( get_response( requests.delete(user_delete_uri, headers=user_delete_header))) _user.token = "" _user_response.token = "" self.assertDictEqual( json.loads(_user.serialize().replace("'", "\"")), json.loads(_user_response.serialize().replace("'", "\""))) self.assertEqual(-1, _delete_response.id)
def get_citizen_admins_citizens(admin_id): citizens = [] conn = psycopg2.connect(connect_str) cursor = conn.cursor() cursor.execute( "SELECT id, name, email, address, city, postnr FROM users, citizen, manages WHERE users.id = citizen.userID AND manages.citizenid = users.id AND manages.adminid = %s", [admin_id]) ctz = cursor.fetchall() for citizen in ctz: contacts = get_citizen_contacts(citizen[0]) devices = get_user_devices(citizen[0]) citizens.append( user.Citizen(citizen[0], citizen[1], citizen[2], contacts, devices, citizen[3], citizen[4], citizen[5])) conn.commit() cursor.close() conn.close() return citizens
def make_citizen(self, data): _user = user.Citizen(data["id"], data["name"], data["email"], data["contacts"], data["devices"], data["address"], data["city"], data["postnr"]) _user.token = data["token"] return _user