Refactor functional tests

Bug #1395191 reported by Victoria Martinez de la Cruz on 2014-11-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zaqar
Undecided
Unassigned

Bug Description

Functional tests should be refactored in order to avoid code duplication.

A way to fix it would be to move the common tests from v1/ and v1_1/ to the parent location and simply specialize the changes in v1/ and v1_1/.

Changed in zaqar:
assignee: nobody → Victoria Martínez de la Cruz (vkmc)
Download full text (9.8 KiB)

Just to illustrate my point... this is the diff of test_messages.py for v1 and v1_1

1c1
< # Copyright (c) 2013 Rackspace, Inc.
---
> # Copyright (c) 2014 Rackspace, Inc.
27,29c27,28
< class TestMessages(base.V1FunctionalTestBase):
<
< """Tests for Messages."""
---
> class TestMessages(base.V1_1FunctionalTestBase):
> """Message Tests Specific to V1.1."""
36c35
< self.queue = uuid.uuid1()
---
> self.queue = uuid.uuid1() # Generate a random queue ID
38,40c37,39
< url=self.cfg.zaqar.url,
< version="v1",
< queue=self.queue))
---
> url=self.cfg.zaqar.url,
> version="v1.1",
> queue=self.queue))
42c41,42
< self.client.put(self.queue_url)
---
> self.headers = helpers.create_zaqar_headers(self.cfg)
> self.client.headers = self.headers
43a44
> self.client.put(self.queue_url) # Create the queue
48c49
< self.client.delete(self.queue_url)
---
> self.client.delete(self.queue_url) # Remove the queue
54c55,56
< doc = '[{{"body": "{0}", "ttl": 300}}, {{"body": "{1}", "ttl": 120}}]'
---
> doc = ('{{"messages":[{{"body": "{0}", "ttl": 300}},'
> '{{"body": "{1}", "ttl": 120}}]}}')
69c71
< doc = helpers.create_message_body(messagecount=1)
---
> doc = helpers.create_message_body_v1_1(messagecount=1)
86c88
< posted_metadata = doc[0]['body']
---
> posted_metadata = doc['messages'][0]['body']
105c107
< self.assertEqual(result.status_code, 204)
---
> self.assertEqual(result.status_code, 200)
112c114
< doc = helpers.create_message_body(messagecount=message_count)
---
> doc = helpers.create_message_body_v1_1(messagecount=message_count)
123,125d124
< self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
< '(happens randomly)')
<
128a128,130
> self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
> '(happens randomly)')
>
130,131c132
< result_body = [result.json()[i]['body']
< for i in range(len(result.json()))]
---
> result_body = [msg['body'] for msg in result.json()['messages']]
134,135c135
< posted_metadata = [doc[i]['body']
< for i in range(message_count)]
---
> posted_metadata = [msg['body'] for msg in doc['messages']]
141a142,162
> def test_message_default_ttl(self):
> """Insert Single Message into the Queue using the default TTL."""
> doc = helpers.create_message_body_v1_1(messagecount=1,
> default_ttl=True)
>
> result = self.client.post(data=doc)
> self.assertEqual(result.status_code, 201)
>
> # GET on posted message
> href = result.json()['resources'][0]
> url = self.cfg.zaqar.url + href
>
> result = self.client.get(url)
> self.assertEqual(result.status_code, 200)
>
> # Compare message metadata
> default_ttl = result.json()['ttl']
> self.assertEqual(default_...

Changed in zaqar:
status: New → Invalid
assignee: Victoria Martinez de la Cruz (vkmc) → nobody
Changed in zaqar:
status: Invalid → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers