Repository: heavenshell/py-sqlalchemy_seed

Issue:
Support for json fixture?
Does it support a json file as fixture? Because in django to load a fixture you can do the following command.

```
python manage.py loaddata fixtures.json
```


Discussion:

Patch:
diff --git a/sqlalchemy_seed/__init__.py b/sqlalchemy_seed/__init__.py
index 9dd3aae..763f420 100644
--- a/sqlalchemy_seed/__init__.py
+++ b/sqlalchemy_seed/__init__.py
@@ -65,7 +65,7 @@ def load_fixture_files(paths, files):
                 if file.endswith('.yaml') or file.endswith('.yml'):
                     data = yaml.load(f, Loader=Loader)
                 elif file.endswith('.json'):
-                    data = json.loads(f)
+                    data = json.loads(f.read())
                 else:
                     continue
                 fixtures.append(data)


Test patch:
diff --git a/tests/fixtures/accounts.json b/tests/fixtures/accounts.json
new file mode 100644
index 0000000..707f5b1
--- /dev/null
+++ b/tests/fixtures/accounts.json
@@ -0,0 +1,20 @@
+[
+  {
+    "model": "tests.test_sqlalchey_seed.Account",
+    "id": 1,
+    "fields": {
+      "first_name": "John",
+      "last_name": "Lennon",
+      "age": 20
+    }
+  },
+  {
+    "model": "tests.test_sqlalchey_seed.Account",
+    "id": 2,
+    "fields": {
+      "first_name": "Paul",
+      "last_name": "McCartney",
+      "age": 21
+    }
+  }
+]
diff --git a/tests/fixtures/pictures.json b/tests/fixtures/pictures.json
new file mode 100644
index 0000000..c15c22b
--- /dev/null
+++ b/tests/fixtures/pictures.json
@@ -0,0 +1,33 @@
+[
+  {
+    "model": "tests.test_sqlalchey_seed.Picture",
+    "id": 1,
+    "fields": {
+      "account_id": 1,
+      "image": "cat.jpg"
+    }
+  },
+  {
+    "model": "tests.test_sqlalchey_seed.Picture",
+    "id": 2,
+    "fields": {
+      "account_id": 1,
+      "image": "dog.jpg"
+    }
+  },
+  {
+    "model": "tests.test_sqlalchey_seed.Picture",
+    "id": 3,
+    "fields": {
+      "account_id": 2
+    }
+  },
+  {
+    "model": "tests.test_sqlalchey_seed.Picture",
+    "id": 4,
+    "fields": {
+      "account_id": 2,
+      "image": "ham.jpg"
+    }
+  }
+]
diff --git a/tests/test_sqlalchey_seed.py b/tests/test_sqlalchey_seed.py
index b1d08fd..42a5eea 100644
--- a/tests/test_sqlalchey_seed.py
+++ b/tests/test_sqlalchey_seed.py
@@ -102,6 +102,15 @@ class TestFixtures(TestCase):
 
         drop_table(Base, session)
 
+    def test_load_json_fixture(self):
+        create_table(Base)
+        fixtures = load_fixture_files(self.path, ['accounts.json'])
+        load_fixtures(session, fixtures)
+        accounts = session.query(Account).all()
+        self.assertEqual(len(accounts), 2)
+
+        drop_table(Base, session)
+
     def test_load_fixtures(self):
         create_table(Base)
         fixtures = load_fixture_files(
@@ -115,6 +124,19 @@ class TestFixtures(TestCase):
 
         drop_table(Base, session)
 
+    def test_load_json_fixtures(self):
+        create_table(Base)
+        fixtures = load_fixture_files(
+            self.path, ['accounts.json', 'pictures.json'],
+        )
+        load_fixtures(session, fixtures)
+        accounts = session.query(Account).all()
+        self.assertEqual(len(accounts), 2)
+        pictures = session.query(Picture).all()
+        self.assertEqual(len(pictures), 4)
+
+        drop_table(Base, session)
+
     def test_load_fixture_by_wrong_order(self):
         # Picture has relationship to Account.
         # Model instances are added by `session.add_all()`.