Exemplo n.º 1
0
 def two_groups(self):
     """ Returns set of people where a single chain is not possible """
     return [
         Person('a', restrictions=['a', 'c', 'd']),
         Person('b', restrictions=['b', 'c', 'd']),
         Person('c', restrictions=['a', 'b', 'c']),
         Person('d', restrictions=['a', 'b', 'd'])
     ]
Exemplo n.º 2
0
 def few_restrictions(self):
     """ Returns set of Person with few restrictions """
     return {
         Person('a', restrictions=['a', 'b', 'c']),
         Person('b', restrictions=['b']),
         Person('c', restrictions=['c', 'd']),
         Person('d', restrictions=['d']),
         Person('e', restrictions=['b', 'c', 'e'])
     }
Exemplo n.º 3
0
def test_person_init():
    person = Person("John", "Smith", datetime.datetime(2019, 1, 1))
    assert person._first_name == "John"
    assert person._last_name == "Smith"
    assert person._DOB == datetime.datetime(2019, 1, 1)
    assert person._email is None

    # test optional email
    person = Person("John", "Smith", datetime.datetime(2019, 1, 1), "*****@*****.**")
    assert person._email == "*****@*****.**"
Exemplo n.º 4
0
def report(id):
    with open("staff.json", encoding='utf-8') as write_file:
        data = json.loads(write_file.read())
    data = data[id]
    p = Person()
    p.name = data['name']
    p.patronymic = data['patronymic']
    p.surname = data['surname']
    p.tasks = data['tasks']
    p.calc()
    p.doc()
    return url_for('static', filename='%s.pdf' % p.name)
Exemplo n.º 5
0
def test_person_get_age():
    now = datetime.datetime.now()
    person = Person("", "", datetime.datetime(now.year, 1, 1))
    assert person.get_age() == 0

    person = Person("", "", datetime.datetime(now.year-1, 1, 1))
    assert person.get_age() == 1

    person = Person("", "", datetime.datetime(now.year-5, 1, 1))
    assert person.get_age() == 5
Exemplo n.º 6
0
def percent_by_gender(gender):
    """
    Get the percentage of the specified gender in the whole community
    """
    count_all = 0
    count_choice = 0

    if gender == 'female' or gender == 'male':
        count_all = Person.select().count()
        count_choice = Person.select().where(Person.gender == gender).count()
        click.echo('Percent of {}: {:.1f}%'.format(
            gender, count_choice * 100 / count_all))
    else:
        click.echo('Wrong gender, try again!')
Exemplo n.º 7
0
def people_by_dob_range():
    """
    Provide the date range and get all the people within this range
    """
    flag_change = ''
    flag_found = False
    date1 = click.prompt("Provide the first date (YYYY-MM-DD)",
                         value_proc=get_date)
    date2 = click.prompt("Provide the second date (YYYY-MM-DD)",
                         value_proc=get_date)

    if date1 > date2:
        flag_change = date2
        date2 = date1
        date1 = flag_change

    persons = Person.select()
    for person in persons:
        dob = Dob.select().join(Person).where(Person.id == person.id).get()
        name = Name.select().join(Person).where(Person.id == person.id).get()
        dt = datetime.strptime(dob.date, "%Y-%m-%dT%H:%M:%S.%fZ")
        dob_new = date(dt.year, dt.month, dt.day)

        if date1 <= dob_new <= date2:
            result = name.first + ' ' + name.last + ' - ' + str(dob_new)
            click.echo(result)
            flag_found = True
    if not flag_found:
        click.echo("No results!")
Exemplo n.º 8
0
class UnitTest(unittest.TestCase):
    fd1 = Date(1900, 8, 1)
    f1 = Franchise('Chris', 'Palmer', fd1)
    b1 = Date(2001, 4, 3)
    p1 = Person('The "Real" Deal', 'M', b1, False, 0.00, 1111, None, None, f1)

    test = serialize.to_json(p1)
    print(test)
Exemplo n.º 9
0
 def loadProfiles(self):
     with open('profiles.csv',
               'rt') as csvfile:  # opens the file of profile info
         profilesreader = csv.reader(csvfile, delimiter=',', quotechar='|')
         profiles = pd.read_csv(csvfile)
         for index, row in profiles.iterrows():
             person = Person(row['age'], row['sex'], row['height'],
                             row['income'])
             self.Population.append(person)
Exemplo n.º 10
0
def client():
    app.config['TESTING'] = True
    database.engine = create_engine("sqlite:///")

    with app.test_client() as client:
        database.create_schema()
        with database.Session() as s:
            s.add(Person(id=ID, name=NAME, age=AGE, address=ADDRESS,
                         work=WORK))
        yield client
Exemplo n.º 11
0
def register():
    fname = request.form.get("fname")
    lname = request.form.get("lname")
    address = request.form.get("address")
    city = request.form.get("my_city")
    newPerson = Person(fname, lname, address, city)

    cur.execute('INSERT INTO persons VALUES (newPerson.id, newPerson.l_name, newPerson.f_name, newPerson.address, newPerson.city)')
    # fullname = fname + lname

    return render_template("hello.html", foo = fullname)
Exemplo n.º 12
0
class Test(unittest.TestCase):
    """
    The basic class that inherits unittest.TestCase
    """
    person = Person()  # instantiate the Person Class
    user_id = []  # variable that stores obtained user_id
    user_name = []  # variable that stores person name

    # test case function to check the Person.set_name function
    def test_0_set_name(self):
        print("Start set_name test\n")
        for i in range(4):
            # initialize a name
            name = 'name' + str(i)
            # store the name into the list variable
            self.user_name.append(name)
            # get the user id obtained from the function
            user_id = self.person.set_name(name)
            # check if the obtained user id is null or not
            self.assertIsNotNone(user_id)  # null user id will fail the test
            # store the user id to the list
            self.user_id.append(user_id)
        print("user_id length = ", len(self.user_id))
        print(self.user_id)
        print("user_name length = ", len(self.user_name))
        print(self.user_name)
        print("\nFinish set_name test\n")

    # test case function to check the Person.get_name function
    def test_1_get_name(self):
        print("\nStart get_name test\n")
        length = len(self.user_id)  # total number of stored user information
        print("user_id length = ", length)
        print("user_name length = ", len(self.user_name))
        for i in range(6):
            # if i not exceed total length then verify the returned name
            if i < length:
                # if the two name not matches it will fail the test case
                self.assertEqual(self.user_name[i],
                                 self.person.get_name(self.user_id[i]))
            else:
                print("Testing for get_name no user test")
                # if length exceeds then check the 'no such user' type message
                self.assertEqual('There is no such user',
                                 self.person.get_name(i))
        print("\nFinish get_name test\n")
Exemplo n.º 13
0
def addCustomer():
    if ("user" in session) and (session["position"] == "admin"):
        if request.method == "POST":
            from main import Person, db
            username = request.form["username"]
            password = request.form["password"]
            name = request.form["name"]
            address = request.form["address"]
            phone = request.form["phone"]
            fax = request.form["fax"]
            email = request.form["email"]
            contact = request.form["contact"]
            customer = Person(username, password, 4, name, address, phone, fax,
                              email, contact, "")
            db.session.add(customer)
            db.session.commit()
            flash("New customer added successfully")
            return redirect(url_for("adminbp.addCustomer"))
        else:
            return render_template("add_customer.html")
    else:
        return redirect(url_for("login"))
Exemplo n.º 14
0
def admin_report():
    with open("staff.json", encoding='utf-8') as write_file:
        data = json.loads(write_file.read())
    user_info = []
    data_report = [['name', 'surname', 'patronymic', 'tasks']]
    print(data)
    for user in data:
        data_user = data[user]
        p = Person()
        p.name = data_user['name']
        p.patronymic = data_user['patronymic']
        p.surname = data_user['surname']
        p.tasks = data_user['tasks']
        p.calc()
        user_info.append(p.name)
        user_info.append(p.surname)
        user_info.append(p.patronymic)
        user_info.append(str(len(p.tasks)))
        data_report.append(user_info)
        user_info = []

    print(data_report)
    admin_doc(data_report)
    return url_for('static', filename='admin.pdf')
Exemplo n.º 15
0
 def test_order_first_name(self):
     harry = Person('Harry', 'Potter', '*****@*****.**')
     hermione = Person('Hermione', 'Granger', '*****@*****.**')
     self.assertTrue(order_first_name(harry, hermione))
     self.assertFalse(order_first_name(hermione, harry))
Exemplo n.º 16
0
def test_person_setters_getters():
    person = Person("John", "Smith", datetime.datetime(2019, 1, 1), "*****@*****.**")
    
    person.set_first_name("Johnny")
    assert person.get_first_name() == "Johnny"

    person.set_last_name("Smithly")
    assert person.get_last_name() == "Smithly"

    person.set_email("*****@*****.**")
    person.get_email() == "*****@*****.**"

    # cannot set DOB
    with pytest.raises(AttributeError):
        person.set_DOB(datetime.datetime.now())
    
    person.get_DOB() == datetime.datetime(2019, 1, 1)
Exemplo n.º 17
0
def test_person_greet():
    person = Person("John", "Smith", datetime.datetime(2019, 1, 1))
    assert person.greet() == "Hello, my name is John Smith."

    person = Person("Blah", "Test", datetime.datetime(2019, 1, 1))
    assert person.greet() == "Hello, my name is Blah Test."
Exemplo n.º 18
0
Arquivo: test.py Projeto: gbird3/is537
 def setUp(self):
     self.date = Date(2010, 10, 2)
     self.f1 = Franchise('Spiderman', 'Marvel', self.date)
     self.p1 = Person('Peter "Spidey" Parker', 'M', self.date, False,
                      15000.00, 1967, None, None, self.f1)
def makePerson(rank, **kwd):
    person = Person(addresses=[str(random())+"@example.com"], rank=rank, **kwd)
    person.put()
    return person
Exemplo n.º 20
0
        first_row = True
        rows = 0

        for e in query:
            #print e
            # Write column labels as first row
            row_dict = e.to_dict()
            if first_row:
                first_row = False
                keys = sorted(row_dict.keys())
                csvWriter.writerow(keys)
            values = []
            v_str = None
            for k in keys:
                v_row = row_dict[k]
                try:
                    v_str = v_row.encode('utf-8') if v_row is str else str(v_row)
                except UnicodeEncodeError:
                    v_str = '--'
                values.append(v_str)
            #print('adding:' + str(values))
            csvWriter.writerow(values)
            rows += 1

        print 'Finished saving ' + str(rows) + ' rows.'


exportToCsv(query = Person.query().order(-Person.last_mod), csvFileName='data/Person_Table.csv')
exportToCsv(query = Ride.query().order(-Ride.start_daytime), csvFileName='data/Ride_Table.csv')
exportToCsv(query = RideRequest.query().order(-RideRequest.passenger_last_seen), csvFileName='data/RideRequest_Table.csv')
Exemplo n.º 21
0
from main import Person, Task

user1 = Person("Bruce", "Wayne")
task1 = Task("become the Batman", "7 years", "2005")
task2 = Task("defeat the Joker", "1 month", "2008")
task3 = Task("to retire", "1 year", "2012")

# add all tasks:
user1.add_new_task(task1)
user1.add_new_task(task2)
user1.add_new_task(task3)
print(user1.task_list)

#finish task1:
user1.complete_current_task(task1)
print(user1.task_list)

print(user1.completes_numbers())

print(user1.uncompletes_tasks())
user1.clear_tasks()