0

There is a django command that gives the path of the csv file as an argument as follows.

class Command(NoticeCommand):

    def add_arguments(self, parser):
        parser.add_argument(
            '--file', dest="file", type=str, required=True
        )

    def handle(self, *args, **options):
        with open(options['file'], 'r') as f:
            reader = csv.reader(f)
            next(reader)
            for row in reader:
                ...

I am thinking to make this csv file mock when doing unit test.
However, I do not know which part and how to make mock.
Also, the argument is required = True. How can I call UnitTest when csv is mocked?

from mock import patch
from django.core.management import call_command

class ImportCsvTest(TestCase):

    @patch("common.management.commands.import_csv.????")
    def test_import_csv(self):
        call_command("import_lyric_artists", file=?????)
xKxAxKx
  • 1,044
  • 5
  • 16
  • 31

1 Answers1

0

For more examples look to python documentation.

@patch('package.module.attribute', your_value)
def test():
    from package.module import your_value
    assert attribute is your_value

test()