Repository: sec-edgar/sec-edgar

Issue:
error running simple example
**Describe the bug**
The example:
from secedgar.filings import Filing, FilingType

my_filings = Filing(cik_lookup='IBM', filing_type=FilingType.FILING_10Q)
my_filings.save('./filings')
-----------------------------
Gives the error.

Traceback (most recent call last):
  File "testit.py", line 4, in <module>
    my_filings.save('./filings')
  File "/yada/sec-edgar/secedgar/filings/filing.py", line 224, in save
    urls = self.get_urls()
  File "/yada/sec-edgar/secedgar/filings/filing.py", line 152, in get_urls
    for key, cik in self.cik_lookup.lookup_dict.items()
  File "/yada/sec-edgar/secedgar/filings/filing.py", line 152, in <dictcomp>
    for key, cik in self.cik_lookup.lookup_dict.items()
  File "/yada/sec-edgar/secedgar/filings/filing.py", line 176, in _get_urls_for_cik
    while self.count is None or len(links) < self.count:
  File "/yada/sec-edgar/secedgar/filings/filing.py", line 109, in count
    return self._count
AttributeError: 'Filing' object has no attribute '_count'


**Desktop (please complete the following information):**
macOs  python3.   Also tried on ubuntu, same error.

**Additional context**
Using tag 0.2.0

Comments:

Patch:
diff --git a/docs/source/whatsnew/v0.2.1.rst b/docs/source/whatsnew/v0.2.1.rst
new file mode 100644
index 0000000..766d80f
--- /dev/null
+++ b/docs/source/whatsnew/v0.2.1.rst
@@ -0,0 +1,13 @@
+v0.2.1
+------
+
+Highlights
+~~~~~~~~~~
+
+* Fixes bug where ``Filing`` does not work when ``count`` is not specified (thanks to formvoltron!)
+
+Contributors
+~~~~~~~~~~~~
+
+- jackmoody11
+- formvoltron
\ No newline at end of file
diff --git a/secedgar/filings/filing.py b/secedgar/filings/filing.py
index edf13a8..3af48af 100644
--- a/secedgar/filings/filing.py
+++ b/secedgar/filings/filing.py
@@ -80,6 +80,8 @@ class Filing(AbstractFiling):
         if val is not None:
             self._start_date = val
             self._params['datea'] = sanitize_date(val)
+        else:
+            self._start_date = None
 
     @property
     def end_date(self):
@@ -111,7 +113,7 @@ class Filing(AbstractFiling):
     @count.setter
     def count(self, val):
         if val is None:
-            pass
+            self._count = None
         elif not isinstance(val, int):
             raise TypeError("Count must be positive integer or None.")
         elif val < 1:
@@ -182,7 +184,7 @@ class Filing(AbstractFiling):
 
         txt_urls = [link[:link.rfind("-")].strip() + ".txt" for link in links]
 
-        if len(txt_urls) < self.count:
+        if isinstance(self.count, int) and len(txt_urls) < self.count:
             warnings.warn("Only {num} of {count} filings were found for {cik}.".format(
                 num=len(txt_urls), count=self.count, cik=cik))
 


Test patch:
diff --git a/secedgar/tests/filings/test_filings.py b/secedgar/tests/filings/test_filings.py
index c17271b..6ed1a63 100644
--- a/secedgar/tests/filings/test_filings.py
+++ b/secedgar/tests/filings/test_filings.py
@@ -9,7 +9,6 @@ from secedgar.utils.exceptions import FilingTypeError, EDGARQueryError
 
 
 class TestFiling(object):
-    @pytest.mark.slow
     def test_count_returns_exact(self,
                                  mock_cik_validator_get_single_cik,
                                  mock_single_cik_filing):
@@ -21,6 +20,53 @@ class TestFiling(object):
                                  Got {0}, but expected {1} URLs.""".format(
                 urls, count))
 
+    @pytest.mark.parametrize(
+        "count",
+        [
+            None,
+            5,
+            10,
+            15,
+            27,
+            33
+        ]
+    )
+    def test_count_setter_on_init(self, count):
+        filing = Filing(cik_lookup='aapl', filing_type=FilingType.FILING_10Q, count=count)
+        assert filing.count == count
+
+    @pytest.mark.parametrize(
+        "start_date",
+        [
+            datetime.datetime(2020, 1, 1),
+            datetime.datetime(2020, 2, 1),
+            datetime.datetime(2020, 3, 1),
+            datetime.datetime(2020, 4, 1),
+            datetime.datetime(2020, 5, 1),
+            "20200101",
+            20200101,
+            None
+        ]
+    )
+    def test_good_start_date_setter_on_init(self, start_date):
+        filing = Filing(cik_lookup='aapl', filing_type=FilingType.FILING_10Q, start_date=start_date)
+        assert filing.start_date == start_date
+
+    @pytest.mark.parametrize(
+        "bad_start_date",
+        [
+            1,
+            2020010101,
+            "2020010101",
+            "2020",
+            "0102"
+        ]
+    )
+    def test_bad_start_date_setter_on_init(self, bad_start_date):
+        with pytest.raises(TypeError):
+            Filing(cik_lookup='aapl', filing_type=FilingType.FILING_10Q,
+                   start_date=bad_start_date)
+
     @pytest.mark.parametrize(
         "count,expected_error",
         [
@@ -33,9 +79,9 @@ class TestFiling(object):
     )
     def test_count_setter_bad_values(self, count, expected_error):
         with pytest.raises(expected_error):
-            _ = Filing(cik_lookup='aapl',
-                       filing_type=FilingType.FILING_10Q,
-                       count=count)
+            Filing(cik_lookup='aapl',
+                   filing_type=FilingType.FILING_10Q,
+                   count=count)
 
     def test_date_is_sanitized(self):
         start_date = datetime.datetime(2012, 3, 1)
@@ -221,3 +267,9 @@ class TestFiling(object):
             # Should raise assertion error since no UserWarning should be found
             except AssertionError:
                 pass
+
+    @pytest.mark.skip
+    @pytest.mark.smoke
+    def test_filing_simple_example(self, tmp_data_directory):
+        my_filings = Filing(cik_lookup='IBM', filing_type=FilingType.FILING_10Q)
+        my_filings.save(tmp_data_directory)