-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from grahamu/refactored
Refactored
- Loading branch information
Showing
10 changed files
with
139 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ MANIFEST | |
*.egg | ||
docs/_build/ | ||
htmlcov/ | ||
.eggs/ | ||
.python-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,117 @@ | ||
from __future__ import unicode_literals | ||
|
||
import json | ||
from ..test import TestCase | ||
|
||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
|
||
|
||
class Tests(TestCase): | ||
class TestAssertResourceGraph(TestCase): | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def test_something(self): | ||
r = self.client.get(reverse("user-list")) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r["Content-Type"], "application/vnd.api+json") | ||
self.assertDictEqual( | ||
{ | ||
"jsonapi": {"version": "1.0"}, | ||
"links": { | ||
"self": "http://testserver/user/", | ||
}, | ||
"data": [], | ||
self.first_item = { | ||
"type": "lorem", | ||
"id": "33", | ||
"attributes": { | ||
"quantity": 1 | ||
}, | ||
"links": { | ||
"self": "http://testserver/lorem/33" | ||
}, | ||
"relationships": { | ||
"product": { | ||
"links": { | ||
"self": "http://testserver/relationships/product" | ||
}, | ||
"data": { | ||
"id": "44", | ||
"type": "product" | ||
} | ||
} | ||
} | ||
} | ||
|
||
self.second_item = { | ||
"type": "product", | ||
"id": "44", | ||
"attributes": { | ||
"name": "Excelsior", | ||
"slug": "excelsior", | ||
}, | ||
json.loads(r.content.decode("utf-8")), | ||
) | ||
"links": {"self": "http://testserver/products/44"}, | ||
"relationships": { | ||
"category": { | ||
"data": { | ||
"type": "category", | ||
"id": "12", | ||
}, | ||
"links": { | ||
"self": "http://testserver/products/44/relationships/category", | ||
} | ||
} | ||
} | ||
} | ||
|
||
self.third_item = { | ||
"type": "ipsum", | ||
"id": "55", | ||
"attributes": { | ||
"words": 42 | ||
}, | ||
"links": { | ||
"self": "http://testserver/ipsum/55" | ||
} | ||
} | ||
|
||
self.fourth_item = { | ||
"type": "product", | ||
"id": "44", | ||
"attributes": { | ||
"name": "Excelsiore", # slightly different name than in self.second_item | ||
"slug": "excelsiore", | ||
}, | ||
"links": {"self": "http://testserver/products/44"}, | ||
"relationships": { | ||
"category": { | ||
"data": { | ||
"type": "category", | ||
"id": "12", | ||
}, | ||
"links": { | ||
"self": "http://testserver/products/44/relationships/category", | ||
} | ||
} | ||
} | ||
} | ||
|
||
def test_unordered_identical(self): | ||
|
||
a = [self.first_item, self.second_item] | ||
b = [self.second_item, self.first_item] | ||
self.assertResourceGraphEqual(a, b) | ||
|
||
def test_unequal_count(self): | ||
""" | ||
Ensure we catch when lists have different amount of resources. | ||
""" | ||
a = [self.first_item, self.second_item] | ||
b = [self.first_item] | ||
with self.assertRaises(AssertionError): | ||
self.assertResourceGraphEqual(a, b) | ||
|
||
def test_different_resources(self): | ||
""" | ||
Ensure we catch when lists contain different resources. | ||
""" | ||
a = [self.first_item, self.second_item] | ||
b = [self.first_item, self.third_item] | ||
with self.assertRaises(AssertionError): | ||
self.assertResourceGraphEqual(a, b) | ||
|
||
def test_different_items(self): | ||
""" | ||
Ensure we catch when item count is identical | ||
and item resource ID is identical but | ||
items themselves are different. | ||
""" | ||
a = [self.first_item, self.second_item] | ||
b = [self.first_item, self.fourth_item] | ||
with self.assertRaises(AssertionError): | ||
self.assertResourceGraphEqual(a, b) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters