Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: constructor invalid path tests (#114)
* fix: query constructor test naming

* fix: remove duplicate document tests

* fix: remove duplicate collection tests

* refactor: split invalid path tests
  • Loading branch information
rafilong committed Jul 17, 2020
1 parent 6e597f2 commit edf7bd1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 60 deletions.
14 changes: 0 additions & 14 deletions tests/unit/v1/test_async_collection.py
Expand Up @@ -79,20 +79,6 @@ def test_constructor(self):
expected_path = (collection_id1, document_id, collection_id2)
self.assertEqual(collection._path, expected_path)

def test_constructor_invalid_path(self):
with self.assertRaises(ValueError):
self._make_one()
with self.assertRaises(ValueError):
self._make_one(99, "doc", "bad-collection-id")
with self.assertRaises(ValueError):
self._make_one("bad-document-ID", None, "sub-collection")
with self.assertRaises(ValueError):
self._make_one("Just", "A-Document")

def test_constructor_invalid_kwarg(self):
with self.assertRaises(TypeError):
self._make_one("Coh-lek-shun", donut=True)

@pytest.mark.asyncio
async def test_add_auto_assigned(self):
from google.cloud.firestore_v1.types import document
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/v1/test_async_document.py
Expand Up @@ -47,20 +47,6 @@ def test_constructor(self):
)
self.assertEqual(document.path, expected_path)

def test_constructor_invalid_path(self):
with self.assertRaises(ValueError):
self._make_one()
with self.assertRaises(ValueError):
self._make_one(None, "before", "bad-collection-id", "fifteen")
with self.assertRaises(ValueError):
self._make_one("bad-document-ID", None)
with self.assertRaises(ValueError):
self._make_one("Just", "A-Collection", "Sub")

def test_constructor_invalid_kwarg(self):
with self.assertRaises(TypeError):
self._make_one("Coh-lek-shun", "Dahk-yu-mehnt", burger=18.75)

@staticmethod
def _make_commit_repsonse(write_results=None):
from google.cloud.firestore_v1.types import firestore
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/v1/test_async_query.py
Expand Up @@ -32,7 +32,7 @@ def _make_one(self, *args, **kwargs):
klass = self._get_target_class()
return klass(*args, **kwargs)

def test_constructor_defaults(self):
def test_constructor(self):
query = self._make_one(mock.sentinel.parent)
self.assertIs(query._parent, mock.sentinel.parent)
self.assertIsNone(query._projection)
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/v1/test_base_collection.py
Expand Up @@ -41,13 +41,19 @@ def test_constructor(self):
expected_path = (collection_id1, document_id, collection_id2)
self.assertEqual(collection._path, expected_path)

def test_constructor_invalid_path(self):
def test_constructor_invalid_path_empty(self):
with self.assertRaises(ValueError):
self._make_one()

def test_constructor_invalid_path_bad_collection_id(self):
with self.assertRaises(ValueError):
self._make_one(99, "doc", "bad-collection-id")

def test_constructor_invalid_path_bad_document_id(self):
with self.assertRaises(ValueError):
self._make_one("bad-document-ID", None, "sub-collection")

def test_constructor_invalid_path_bad_number_args(self):
with self.assertRaises(ValueError):
self._make_one("Just", "A-Document")

Expand Down
8 changes: 7 additions & 1 deletion tests/unit/v1/test_base_document.py
Expand Up @@ -47,13 +47,19 @@ def test_constructor(self):
)
self.assertEqual(document.path, expected_path)

def test_constructor_invalid_path(self):
def test_constructor_invalid_path_empty(self):
with self.assertRaises(ValueError):
self._make_one()

def test_constructor_invalid_path_bad_collection_id(self):
with self.assertRaises(ValueError):
self._make_one(None, "before", "bad-collection-id", "fifteen")

def test_constructor_invalid_path_bad_document_id(self):
with self.assertRaises(ValueError):
self._make_one("bad-document-ID", None)

def test_constructor_invalid_path_bad_number_args(self):
with self.assertRaises(ValueError):
self._make_one("Just", "A-Collection", "Sub")

Expand Down
14 changes: 0 additions & 14 deletions tests/unit/v1/test_collection.py
Expand Up @@ -68,20 +68,6 @@ def test_constructor(self):
expected_path = (collection_id1, document_id, collection_id2)
self.assertEqual(collection._path, expected_path)

def test_constructor_invalid_path(self):
with self.assertRaises(ValueError):
self._make_one()
with self.assertRaises(ValueError):
self._make_one(99, "doc", "bad-collection-id")
with self.assertRaises(ValueError):
self._make_one("bad-document-ID", None, "sub-collection")
with self.assertRaises(ValueError):
self._make_one("Just", "A-Document")

def test_constructor_invalid_kwarg(self):
with self.assertRaises(TypeError):
self._make_one("Coh-lek-shun", donut=True)

def test_add_auto_assigned(self):
from google.cloud.firestore_v1.types import document
from google.cloud.firestore_v1.document import DocumentReference
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/v1/test_document.py
Expand Up @@ -46,20 +46,6 @@ def test_constructor(self):
)
self.assertEqual(document.path, expected_path)

def test_constructor_invalid_path(self):
with self.assertRaises(ValueError):
self._make_one()
with self.assertRaises(ValueError):
self._make_one(None, "before", "bad-collection-id", "fifteen")
with self.assertRaises(ValueError):
self._make_one("bad-document-ID", None)
with self.assertRaises(ValueError):
self._make_one("Just", "A-Collection", "Sub")

def test_constructor_invalid_kwarg(self):
with self.assertRaises(TypeError):
self._make_one("Coh-lek-shun", "Dahk-yu-mehnt", burger=18.75)

@staticmethod
def _make_commit_repsonse(write_results=None):
from google.cloud.firestore_v1.types import firestore
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/v1/test_query.py
Expand Up @@ -31,7 +31,7 @@ def _make_one(self, *args, **kwargs):
klass = self._get_target_class()
return klass(*args, **kwargs)

def test_constructor_defaults(self):
def test_constructor(self):
query = self._make_one(mock.sentinel.parent)
self.assertIs(query._parent, mock.sentinel.parent)
self.assertIsNone(query._projection)
Expand Down

0 comments on commit edf7bd1

Please sign in to comment.