Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from microservices-demo/usersupdate
Browse files Browse the repository at this point in the history
added new user tests
  • Loading branch information
jasonrichardsmith authored Aug 26, 2016
2 parents f3a7db4 + 2f4de8f commit 134bb9a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class APITasks(TaskSet):
@task
def purchaseItem(self):
self.createCustomer()
self.createCard()
self.createAddress()
self.login()
self.addItemToCart()
self.buy()
self.deleteCustomer()
self.deleteCard()
self.deleteAddress()

# @task
# def addRemoveFromCart(self):
Expand Down Expand Up @@ -60,35 +64,40 @@ def addItemToCart(self):
self.client.post("/cart", json={"id": self.item_id, "quantity": 1})

def buy(self):
self.client.post("/orders", json={"customer": self.cust_id})
cookie = {'logged_in': self.cust_id}
self.client.post("/orders", cookies=cookie)

def login(self):
base64string = base64.encodestring('%s:%s' % (self.username, self.password)).replace('\n', '')
login = self.client.get("/login", headers={"Authorization":"Basic %s" % base64string})
# self.cust_id = login.cookies["logged_in"]

def createCustomer(self):
# TODO just use same address/card for all generated customers?
address = self.client.post("/addresses", json={"street": "my road", "number": "3", "country": "UK", "city": "London"})

self.address_id = address.json()["_links"]["self"]["href"][26:]
card = self.client.post("/cards", json={"longNum": "5429804235432", "expires": "04/16", "ccv": "432"})

self.card_id = card.json()["_links"]["self"]["href"][22:]
global counter
counter += 1
self.username = "test_user_" + str(uuid.uuid4())

self.password = "test_password"
customer = self.client.post("/customers", json={"firstName": "testUser_" + str(counter), "lastName": "Last_Name", "username": self.username, "addresses": ["http://accounts/addresses/" + self.address_id], "cards": ["http://accounts/cards/" + self.card_id]})
customer = self.client.post("/register", json={"username": self.username, "password": self.password})

self.cust_id = customer.json()["_links"]["self"]["href"][27:]
self.client.get("/register?username=" + self.username + "&password=" + self.password)
self.cust_id = customer.json()["id"]

def createCard(self):
self.client.post("/cards", json={"longNum": "5429804235432", "expires": "04/16", "ccv": "432"})
card = self.client.post("/cards", json={"longNum": "5429804235432", "expires": "04/16", "ccv": "432", "userId": self.cust_id})
self.card_id = card.json()["id"]

def createAddress(self):
self.client.post("/addresses", json={"street": "my road", "number": "3", "country": "UK", "city": "London"})
addr = self.client.post("/addresses", json={"street": "my road", "number": "3", "country": "UK", "city": "London", "userId":self.cust_id})
self.addr_id = addr.json()["id"]

def deleteCustomer(self):
self.client.delete("/customers/" + self.cust_id)
self.client.delete("/addresses/" + self.address_id)
def deleteCard(self):
self.client.delete("/cards/" + self.card_id)
def deleteAddress(self):
self.client.delete("/addresses/" + self.addr_id)

class ErrorTasks(TaskSet):

Expand Down Expand Up @@ -130,4 +139,4 @@ class UnknownUser(HttpLocust):
class ErrorUser(HttpLocust):
task_set = ErrorTasks
min_wait = 2000
max_wait = 5000
max_wait = 5000

0 comments on commit 134bb9a

Please sign in to comment.