Esempio n. 1
0
 def add_user():
     store = InMemoryDataStore()
     user_json = request.get_json(force=True)
     store.add_user(firstname=user_json["firstname"],
                    lastname=user_json["lastname"],
                    age=user_json["age"],
                    email=user_json["email"])
     return jsonify("Success")
Esempio n. 2
0
    def test_datastore_add_user(self):
        # create store with default data
        store = InMemoryDataStore(
            users_pck_file=os.path.join(self.TEST_STORAGE_PATH, "users.pck"))

        # add a new user
        store.add_user("Jane", "Doe", 18, "*****@*****.**")
        self.assertEqual(InMemoryDataStore._USERS[1].email,
                         "*****@*****.**")

        # add an existing email
        with self.assertRaises(ValueError):
            store.add_user(self.TEST_USER.first_name, self.TEST_USER.last_name,
                           self.TEST_USER.age, self.TEST_USER.email)
Esempio n. 3
0
    def test_datastore_persists_to_disk(self):
        users_file = os.path.join(self.TEST_STORAGE_PATH, "users.pck")
        # get contents of the current file
        with open(users_file, "rb") as fp:
            orig_users = pickle.load(fp)

        # create store and populate with file, then add user
        store = InMemoryDataStore(users_pck_file=users_file)
        store.add_user("Jane", "Doe", 18, "*****@*****.**")

        # persist to disk
        store.save_to_disk(loc=self.TEST_STORAGE_PATH)

        # get contents and check that list is appended
        with open(users_file, "rb") as fp:
            new_users = pickle.load(fp)

        self.assertGreater(len(new_users), len(orig_users))
        self.assertIsNone(new_users[1].portfolio)
Esempio n. 4
0
 def setUp(self):
     self.host = "localhost"
     self.port = 50123
     # add to the datastore
     store = InMemoryDataStore()
     store.add_user("John", "Doe", 23, "*****@*****.**")