Beispiel #1
0
 def testMultiPlayerMatch(self):
     init_db()
     player_one = Player(owner=1, desc="I'm uniq", enabled=True)
     db_session.add(player_one)
     db_session.commit()
     print "player_one.id:", player_one.id
     player_two = Player(owner=2, desc="I'm not", enabled=True)
     db_session.add(player_two)
     db_session.commit()
     print "player_two.id:", player_two.id
     match = Match(players=[player_one, player_two])
     db_session.add(match)
     assert match.state == 'unplayed'
     print "Match before commit: %s"%(match,)
     db_session.add(match)
     db_session.commit()
     match_persist = db_session.query(Match).first()
     print "Match re-read: %s"%(match_persist,)
     assert match_persist.playerresults[0].result == 0
     assert match_persist.playerresults[0].player.owner == 1
     assert match_persist.playerresults[0].player.desc == "I'm uniq"
     assert match_persist.playerresults[0].player.enabled == True
     assert match_persist.playerresults[1].result == 0
     assert match_persist.playerresults[1].player.owner == 2
     assert match_persist.playerresults[1].player.desc == "I'm not"
     assert match_persist.playerresults[1].player.enabled == True
     reset_db()
 def reset_db(self):
     ans = messagebox.askyesno(
         'reset databasse', 'are you sure you want to reset the databse?')
     if ans:
         database.reset_db(database.file_name)
         self.load_db()
         messagebox.showinfo('reset database', 'the database is reset!')
Beispiel #3
0
    def test_add_user(self):
        db.reset_db()
        # insert user
        test_user = {unicode('id'):1234, unicode('buyer'):True}
        db.update_user_obj(test_user)

        get_user = db.get_user_obj(1234)
        self.assertEqual(get_user, test_user)
Beispiel #4
0
 def testCreateTrivialMatch(self):
     init_db()
     match = Match()
     assert match.state == 'unplayed'
     db_session.add(match)
     db_session.commit()
     match_persist = db_session.query(Match).first()
     assert match_persist.state == 'unplayed'
     reset_db()
Beispiel #5
0
    def test_user_complete(self):
        db.reset_db()

        db.add_time(1234, 4)
        self.assertEqual(db.is_user_complete(1234), False)

        db.add_hall(1234, "bplate")
        self.assertEqual(db.is_user_complete(1234), False)

        db.set_buyer(1234, True)
        self.assertEqual(db.is_user_complete(1234), True)
Beispiel #6
0
    def test_add_time(self):
        db.reset_db()
        db.add_time(1234, 4)

        get_user = db.get_user_obj(1234)
        self.assertEqual(get_user["when"], [4])

        db.add_time(1234, 5)
        get_user = db.get_user_obj(1234)
        self.assertEqual(4 in get_user["when"], True)
        self.assertEqual(5 in get_user["when"], True)
        self.assertEqual(len(get_user["when"]), 2)
Beispiel #7
0
    def test_add_hall(self):
        db.reset_db()
        db.add_hall(1234, "bplate")

        get_user = db.get_user_obj(1234)
        self.assertEqual(get_user["where"], ["bplate"])

        db.add_hall(1234, "deneve")
        get_user = db.get_user_obj(1234)
        self.assertEqual("bplate" in get_user["where"], True)
        self.assertEqual("deneve" in get_user["where"], True)
        self.assertEqual(len(get_user["where"]), 2)
Beispiel #8
0
 def testPersistPlayer(self):
     init_db()
     #You must specify an onwer to be allowed to create a player
     player = Player(owner=1, desc="My description.", files="null_tmpfile")
     self.assertTrue(player.desc == "My description.")
     print "player, pre add()", player
     db_session.add(player)
     print "player, pre commit()", player
     db_session.commit()
     print "player, post commit()", player
     pid = player.id
     player_persist = db_session.query(Player).first()
     print "pid =", pid
     print "player_presist", player_persist
     self.assertTrue(player_persist.id == pid)
     self.assertTrue(player_persist.desc == "My description.")
     reset_db()
Beispiel #9
0
 def testSinglePlayerMatch(self):
     init_db()
     player_one = Player(owner=1, desc="I'm uniq", enabled=True)
     db_session.add(player_one)
     db_session.commit()
     match = Match(players=[player_one])
     assert match.state == 'unplayed'
     print "Match before commit: %s"%(match,)
     db_session.add(match)
     db_session.commit()
     match_persist = db_session.query(Match).first()
     print "Match re-read: %s"%(match_persist,)
     assert match_persist.playerresults[0].result == 0
     assert match_persist.playerresults[0].player.owner == 1
     assert match_persist.playerresults[0].player.desc == "I'm uniq"
     assert match_persist.playerresults[0].player.enabled == True
     reset_db()
Beispiel #10
0
    def testSinglePlayerMatchSerialize(self):
        init_db()
        player_one = Player(owner=1, desc="I'm uniq", enabled=True)
        db_session.add(player_one)
        db_session.commit()
        print "player_one.id:", player_one.id
        player_two = Player(owner=2, desc="I'm not", enabled=True)
        db_session.add(player_two)
        db_session.commit()
        print "player_two.id:", player_two.id
        match = Match(players=[player_one, player_two])
        db_session.add(match)
        assert match.state == 'unplayed'
        print "Match before commit: %s"%(match,)
        db_session.add(match)
        db_session.commit()
        match_persist = db_session.query(Match).first()
        print match_persist

        serialized_match = match_persist.serialize()
        assert len(serialized_match['playerresults']) == 2

        reset_db()
Beispiel #11
0
    def test_set_buyer(self):
        db.reset_db()
        db.set_buyer(1234, True)

        get_user = db.get_user_obj(1234)
        self.assertEqual(get_user["is_buyer"], True)
Beispiel #12
0
                                   end=datetime.utcnow()),
            visit_reason=factory.text(900),
            patient_comments=factory.text(900),
            doctor_comments=factory.text(900))
    MedicalVisit.run_sql(statement)


def random_date(start, end):
    """
    This function will return a random datetime between two datetime
    objects.
    """
    delta = end - start
    int_delta = (delta.days * 24 * 60 * 60) + delta.seconds
    random_second = random.randrange(int_delta)
    return start + timedelta(seconds=random_second)


if __name__ == '__main__':
    if clear_data_first:
        reset_db()

    for i in range(num_of_groups):
        if i % 10 == 0:
            print('Record number: ' + str(i * num_in_group))
        add_patient_record(num_in_group)
        add_medical_visit(num_in_group)

    copy_table_to_col_version(MedicalVisit.__tablename__)
    copy_table_to_col_version(PatientRecord.__tablename__)