def test_load_fixture(self): """Test loaded fixture matches database content.""" destination = 'cities_light/tests/fixtures/angouleme.json' with mock.patch.object(Downloader, 'download') as mock_func: cmd = Command() cmd.load_fixture(source='/abcdefg.json', destination=destination, force=True) Fixture(destination).assertNoDiff() mock_func.assert_called_with(source='/abcdefg.json', destination=destination, force=True)
def test_load_fixture(self): """Test loaded fixture matches database content.""" destination = FixtureDir('import').get_file_path('angouleme.json') with mock.patch.object(Downloader, 'download') as mock_func: cmd = Command() cmd.load_fixture(source='/abcdefg.json', destination=destination, force=True) Fixture(destination).assertNoDiff() mock_func.assert_called_with(source='/abcdefg.json', destination=destination, force=True)
def test_load_fixture(self): """Test loaded fixture matches database content.""" destination = FixtureDir('import').get_file_path('angouleme.json') with mock.patch.object(Downloader, 'download') as mock_func: cmd = Command() cmd.load_fixture(source='/abcdefg.json', destination=destination, force=True) Fixture(destination).assertNoDiff() mock_func.assert_called_with(source='/abcdefg.json', destination=destination, force=True)
def test_dump_fixture(self): """ Test dump_fixture calls dumpdata management command and tries to save it to file.""" # Load test data call_command('loaddata', 'cities_light/tests/fixtures/angouleme.json') # Dump try: fixture_path = 'cities_light/tests/fixtures/test_dump_fixture.json' cmd = Command() cmd.dump_fixture('cities_light.City', fixture_path) with bz2.BZ2File(fixture_path, mode='r') as bzfile: data = bzfile.read() with open(fixture_path, mode='wb') as file: file.write(data) Fixture(fixture_path, models=[City]).assertNoDiff() finally: if os.path.exists(fixture_path): os.remove(fixture_path)
def test_dump_fixture(self): """ Test dump_fixture calls dumpdata management command and tries to save it to file.""" # Load test data destination = FixtureDir('import').get_file_path('angouleme.json') call_command('loaddata', destination) # Dump try: fixture_path = 'cities_light/tests/fixtures/test_dump_fixture.json' cmd = Command() cmd.dump_fixture('cities_light.City', fixture_path) with bz2.BZ2File(fixture_path, mode='r') as bzfile: data = bzfile.read() with open(fixture_path, mode='wb') as file: file.write(data) Fixture(fixture_path, models=[City]).assertNoDiff() finally: if os.path.exists(fixture_path): os.remove(fixture_path)
def test_dump_fixture(self): """ Test dump_fixture calls dumpdata management command and tries to save it to file.""" # Load test data destination = FixtureDir('import').get_file_path('angouleme.json') call_command('loaddata', destination) # Dump try: fixture_path = os.path.join(os.path.dirname(__file__), "fixtures", "test_dump_fixture.json") cmd = Command() cmd.dump_fixture('cities_light.City', fixture_path) with bz2.BZ2File(fixture_path, mode='r') as bzfile: data = bzfile.read() with open(fixture_path, mode='wb') as file: file.write(data) Fixture(fixture_path, models=[City]).assertNoDiff() finally: if os.path.exists(fixture_path): os.remove(fixture_path)
def test_load_fixtures(self): """ Test load_fixtures calls load_fixture with country, region and city path. """ fixtures_dir = os.path.join(DATA_DIR, 'fixtures') with mock.patch.object(Command, 'load_fixture') as mock_func: cmd = Command() cmd.country_path = os.path.join(fixtures_dir, cmd.COUNTRY_FIXTURE) cmd.region_path = os.path.join(fixtures_dir, cmd.REGION_FIXTURE) cmd.city_path = os.path.join(fixtures_dir, cmd.CITY_FIXTURE) cmd.country_url = FIXTURES_BASE_URL + cmd.COUNTRY_FIXTURE cmd.region_url = FIXTURES_BASE_URL + cmd.REGION_FIXTURE cmd.city_url = FIXTURES_BASE_URL + cmd.CITY_FIXTURE cmd.load_fixtures(force_fetch=True) mock_func.assert_any_call( cmd.country_url, cmd.country_path, force=True) mock_func.assert_any_call( cmd.region_url, cmd.region_path, force=True) mock_func.assert_any_call( cmd.city_url, cmd.city_path, force=True)
def test_load_fixtures(self): """ Test load_fixtures calls load_fixture with country, region and city path. """ fixtures_dir = os.path.join(DATA_DIR, 'fixtures') with mock.patch.object(Command, 'load_fixture') as mock_func: cmd = Command() cmd.country_path = os.path.join(fixtures_dir, cmd.COUNTRY_FIXTURE) cmd.region_path = os.path.join(fixtures_dir, cmd.REGION_FIXTURE) cmd.city_path = os.path.join(fixtures_dir, cmd.CITY_FIXTURE) cmd.country_url = FIXTURES_BASE_URL + cmd.COUNTRY_FIXTURE cmd.region_url = FIXTURES_BASE_URL + cmd.REGION_FIXTURE cmd.city_url = FIXTURES_BASE_URL + cmd.CITY_FIXTURE cmd.load_fixtures(force_fetch=True) mock_func.assert_any_call( cmd.country_url, cmd.country_path, force=True) mock_func.assert_any_call( cmd.region_url, cmd.region_path, force=True) mock_func.assert_any_call( cmd.city_url, cmd.city_path, force=True)
def test_dump_fixtures(self): """ Test dump_fixtures calls dump_fixture with Country, Region and City table names. """ fixtures_dir = os.path.join(DATA_DIR, 'fixtures') with mock.patch.object(Command, 'dump_fixture') as mock_func: cmd = Command() cmd.country_path = os.path.join(fixtures_dir, cmd.COUNTRY_FIXTURE) cmd.region_path = os.path.join(fixtures_dir, cmd.REGION_FIXTURE) cmd.city_path = os.path.join(fixtures_dir, cmd.CITY_FIXTURE) cmd.dump_fixtures() mock_func.assert_any_call('cities_light.Country', cmd.country_path) mock_func.assert_any_call('cities_light.Region', cmd.region_path) mock_func.assert_any_call('cities_light.City', cmd.city_path)
def test_dump_fixtures(self): """ Test dump_fixtures calls dump_fixture with Country, Region and City table names. """ fixtures_dir = os.path.join(DATA_DIR, 'fixtures') with mock.patch.object(Command, 'dump_fixture') as mock_func: cmd = Command() cmd.country_path = os.path.join(fixtures_dir, cmd.COUNTRY_FIXTURE) cmd.region_path = os.path.join(fixtures_dir, cmd.REGION_FIXTURE) cmd.city_path = os.path.join(fixtures_dir, cmd.CITY_FIXTURE) cmd.dump_fixtures() mock_func.assert_any_call('cities_light.Country', cmd.country_path) mock_func.assert_any_call('cities_light.Region', cmd.region_path) mock_func.assert_any_call('cities_light.City', cmd.city_path)