Repository: sendgrid/sendgrid-python

Issue:
Add tests for Send.py
#### Issue Summary

CodeCov is showing that we're missing some testing on send.py. 
[Please see their page and add some tests](https://codecov.io/gh/sendgrid/sendgrid-python/compare/db608f74fbbb4b1d4d71c644da9614de6ed900e3...86abbc199800fefe9114cab7535d28a8114cca78/src/sendgrid/helpers/inbound/send.py)

Discussion:

Patch:
diff --git a/sendgrid/helpers/inbound/send.py b/sendgrid/helpers/inbound/send.py
index d786f67..9cbb5aa 100644
--- a/sendgrid/helpers/inbound/send.py
+++ b/sendgrid/helpers/inbound/send.py
@@ -26,17 +26,16 @@ class Send(object):
             "Content-Type": "multipart/form-data; boundary=xYzZY"
         }
         client = Client(host=self.url, request_headers=headers)
-        f = open(payload_filepath, 'r')
-        data = f.read()
-        return client.post(request_body=data)
+        with open(payload_filepath, 'r') as f:
+            data = f.read()
+            return client.post(request_body=data)
 
     @property
     def url(self):
         """URL to send to."""
         return self._url
 
-
-if __name__ == '__main__':
+def main():
     config = Config()
     parser = argparse.ArgumentParser(description='Test data and optional host.')
     parser.add_argument('data',
@@ -52,3 +51,6 @@ if __name__ == '__main__':
     print(response.status_code)
     print(response.headers)
     print(response.body)
+
+if __name__ == '__main__':
+    main()
\ No newline at end of file
diff --git a/tox.ini b/tox.ini
index d3e8924..9336a97 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,12 +19,14 @@ commands = coverage erase
            coverage run {envbindir}/unit2 discover -v []
            coverage report
 deps = unittest2
+       mock
        {[testenv]deps}
 basepython = python2.6
 
 [testenv:py27]
 commands = {[testenv]commands}
 deps = {[testenv]deps}
+       mock
 basepython = python2.7
 
 [testenv:py34]


Test patch:
diff --git a/test/test_send.py b/test/test_send.py
new file mode 100644
index 0000000..16d496b
--- /dev/null
+++ b/test/test_send.py
@@ -0,0 +1,42 @@
+import argparse
+from sendgrid.helpers.inbound import send
+
+try:
+    import unittest2 as unittest
+except ImportError:
+    import unittest
+
+try:
+    import unittest.mock as mock
+except ImportError:
+    import mock
+
+
+class UnitTests(unittest.TestCase):
+    def setUp(self):
+        self.client_mock = mock.patch('sendgrid.helpers.inbound.send.Client')
+        self.open_mock = mock.patch('sendgrid.helpers.inbound.send.open',
+                                    mock.mock_open(), create=True)
+        self.client_mock.start()
+        self.open_mock.start()
+
+    def tearDown(self):
+        self.client_mock.stop()
+        self.open_mock.stop()
+
+    def test_send(self):
+
+        fake_url = 'https://fake_url'
+        x = send.Send(fake_url)
+        x.test_payload(fake_url)
+
+        send.Client.assert_called_once_with(host=fake_url, request_headers={'User-Agent': 'SendGrid-Test',
+                                                                            'Content-Type': 'multipart/form-data; boundary=xYzZY'})
+
+    def test_main_call(self):
+        fake_url = 'https://fake_url'
+
+        with mock.patch('argparse.ArgumentParser.parse_args', return_value=argparse.Namespace(host=fake_url, data='test_file.txt')):
+            send.main()
+            send.Client.assert_called_once_with(host=fake_url, request_headers={'User-Agent': 'SendGrid-Test',
+                                                                                'Content-Type': 'multipart/form-data; boundary=xYzZY'})