# Path: importer/load.py
# def generate_command_for_record(record):
# def open_or_default(path, default):
# def commands_from_data(data):
# def main(argv=None):


import errno
import json
import mock
import os
import socket
import shutil
import subprocess
import sys
import requests
from importer import load
from nose_parameterized import parameterized
from six.moves import StringIO
from testtools import (ExpectedException, TestCase)
from testtools.matchers import Equals
        # Make the last entry something else so that we can assert that two
        # matched
        values[1]["pmid"] = "111112"
        values[2]["pmid"] = "111113"
        values[2]["country"] = "China"

        run_commands(load.commands_from_data(values))
        res = run_query("MATCH(a:Article)-[:ORIGINATED_IN]->(r:Country) "
                        " WHERE r.name =\"Australia\" RETURN Count(a)")
        self.assertThat(res.json()["data"][0][0],
                        Equals(2))

    def test_find_month(self):
        """4.5.5.1 Find related month for article."""
        run_commands(load.commands_from_data([ENTRY_VALUES]))
        res = run_query("MATCH(a:Article)-[:PUBLISHED_IN]->(r:Month) "
                        " RETURN r")
        self.assertThat(res.json()["data"][0][0]["data"]["name"],
                        Equals("November"))

    def test_throw_exception_if_network_connection_fails(self):
        """4.5.5.2 Throw exception if network connection is down."""
        with mock.patch("socket.socket") as MockSocket:
            def raise_socket_error(*args):
                """Raise socket error."""
                del args
                raise socket.error()

            MockSocket.return_value.connect = raise_socket_error
            with ExpectedException(requests.exceptions.ConnectionError):

# Path: importer/load.py
# def generate_command_for_record(record):
# def open_or_default(path, default):
# def commands_from_data(data):
# def main(argv=None):


# Path: test/test_importer.py
import errno
import json
import mock
import os
import socket
import shutil
import subprocess
import sys
import requests
from importer import load
from nose_parameterized import parameterized
from six.moves import StringIO
from testtools import (ExpectedException, TestCase)
from testtools.matchers import Equals

        # Make the last entry something else so that we can assert that two
        # matched
        values[1]["pmid"] = "111112"
        values[2]["pmid"] = "111113"
        values[2]["country"] = "China"

        run_commands(load.commands_from_data(values))
        res = run_query("MATCH(a:Article)-[:ORIGINATED_IN]->(r:Country) "
                        " WHERE r.name =\"Australia\" RETURN Count(a)")
        self.assertThat(res.json()["data"][0][0],
                        Equals(2))

    def test_find_month(self):
        """4.5.5.1 Find related month for article."""
        run_commands(load.commands_from_data([ENTRY_VALUES]))
        res = run_query("MATCH(a:Article)-[:PUBLISHED_IN]->(r:Month) "
                        " RETURN r")
        self.assertThat(res.json()["data"][0][0]["data"]["name"],
                        Equals("November"))

    def test_throw_exception_if_network_connection_fails(self):
        """4.5.5.2 Throw exception if network connection is down."""
        with mock.patch("socket.socket") as MockSocket:
            def raise_socket_error(*args):
                """Raise socket error."""
                del args
                raise socket.error()

            MockSocket.return_value.connect = raise_socket_error
            with ExpectedException(requests.exceptions.ConnectionError):

                run_commands(load.commands_from_data([ENTRY_VALUES]))