class TestMember(unittest.TestCase): def setUp(self): start_date = datetime.date(2020, 1, 1) self.member1 = Member("John", "Smith", "standard", start_date, True) def test_member_has_first_name(self): self.assertEqual("John", self.member1.first_name) def test_member_has_last_name(self): self.assertEqual("Smith", self.member1.last_name) def test_member_has_membership_type(self): self.assertEqual("standard", self.member1.type) def test_member_has_start_date(self): date = datetime.datetime.strftime(self.member1.start_date, "%x") self.assertEqual("01/01/20", date) def test_member_has_active_status(self): self.assertTrue(self.member1.active_status) def test_member_deactivation(self): self.member1.deactivate() self.assertFalse(self.member1.active_status) def test_member_reactivation(self): self.member1.active_status = False self.member1.activate() self.assertTrue(self.member1.active_status)
def post(self, *args, **kwargs): try: data = json.loads(self.request.body) m = Member(_id=data["_id"], body=data) member = m.get() yield self.db.Member.save(member) self.write_response("", status=1) except: self.write_response("", status=0)
def buildTree(): root = Member({ 'name': 'Derek', 'gender':'male', 'parent': None }) root.addChild(Member({ 'name': 'Chinn', 'gender':'male', 'parent': root })) return root
def communitiesInscription(): response = Response("", status=204, mimetype='application/json') if request.method == "GET": members = [] for member in membersMemory: members.append(member.toDict()) response = Response(json.dumps(members), status=200, mimetype='application/json') elif request.method == "POST": form = request.get_json() if "memberId" in form and "derLatitude" in form and "derLongitude" in form and "surname" in form and "name" in form and "derName" in form: if form["memberId"] != "": if validateFloat(form["derLatitude"]): derLatitude = float(form["derLatitude"]) if validateFloat(form["derLongitude"]): derLongitude = float(form["derLongitude"]) for community in communitiesMemory: if haversineMeasure(community.coords[0], community.coords[1], derLatitude, derLongitude) <= 500: member = Member(form["memberId"], form["name"], form["surname"], form["derLatitude"], form["derLongitude"], form["derName"], community.name) print(isInMembersMemory(member)) if not isInMembersMemory(member): membersMemory.append(member) response = Response(json.dumps(member.toDict()), status=200, mimetype='application/json') else: response = Response(error400Message, status=400, mimetype='application/json') else: response = Response(error400Message, status=400, mimetype='application/json') return response
def create_member(): name = request.form['name'] age = request.form['age'] membership_type = request.form['membership_type'] member = Member(name, age, membership_type) member_repository.save(member) return redirect('/members')
def new(self, params): member = Member.gql('where user=:user', user=users.get_current_user()).get() if member: self.redirect(member.url()) return template_values = { 'member_form' : MemberForm(), 'user' : users.get_current_user() } path = os.path.join(os.path.dirname(__file__), '..', 'views', 'member_new.html') self.response.out.write(template.render(path, template_values))
def get(self): member = None if users.get_current_user(): member = Member.gql('where user=:user', user=users.get_current_user()).get() template_values = { # 'login_url': users.create_login_url(self.request.uri), 'login_url': '/members/new', 'member': member } path = os.path.join(os.path.dirname(__file__), '..', 'views', 'index.html') self.response.out.write(template.render(path, template_values))
def show(self, id): current_user = users.get_current_user() member = Member.get_by_id(int(id)) # Only you the member can her page if not member or member.user != current_user: self.redirect('/') return template_values = { 'member' : member } path = os.path.join(os.path.dirname(__file__), '..', 'views', 'member_home.html') self.response.out.write(template.render(path, template_values))
def create_scotch(self, params): data = ScotchForm(data=self.request.POST) if data.is_valid() and users.get_current_user(): # Save the data, and redirect to the view page scotch = data.save(commit=False) scotch.owner = Member.gql('where user=:user', user=users.get_current_user()).get() scotch.put() self.redirect(scotch.url()) return else: # Reprint the form template_values = { 'scotch_form' : data } path = os.path.join(os.path.dirname(__file__), '..', 'views', 'scotch_new.html') self.response.out.write(template.render(path, template_values))
def index(self): members = Member.generate_fake_member_list() return render("views/members.html", members=members)