-
Notifications
You must be signed in to change notification settings - Fork 1
Importer setup
- Be prepared to test whether an import is working
If you have changes in your current branch -- you can check on this via git status
-- you'll want to save those before starting this lesson (which uses a separate branch):
git checkout -b your_branch_name
git add .
git commit -m 'checkpoint before beginning search results and facets'
git checkout search_results_and_facets
NOTE: If you make experimental changes and want to get back to the minimal code state necessary to run this lesson, you can check the starting code out again using:
git checkout search_results_and_facets
One of the first and most important tasks in writing an importer is to get a representative sample of the data that will be imported. This sample can be used to inform conversations about importer requirements, and ideally it will also become fixture data or test fixtures for the automated test suite.
A test fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. Examples of fixtures:
- Preparation of input data and setup/creation of fake or mock objects
- Loading a database with a specific, known set of data
- Copying a specific known set of files creating a test fixture will create a set of objects initialized to certain states.
-- Pat Hawks, junit4: Test Fixtures
In the case of this example, we will be writing a CSV importer. Our expected input is a file containing comma separated values, which match a subset of default Hyrax fields. We will also need binary file attachments. In this example, we'll use image files.
mkdir spec/fixtures
mkdir spec/fixtures/images
mkdir spec/fixtures/csv_files
Make a file in spec/fixtures/csv_files
called three_line_example.csv
. Paste this content into it:
dog.png,"A Cute Dog",https://www.pexels.com/photo/animal-blur-canine-close-up-551628/
cat.png,"An Interesting Cat",https://www.pexels.com/photo/person-holding-white-cat-1383397/
birds.png,"A Flock of Birds",https://www.pexels.com/photo/animal-avian-beak-birds-203088/
Make another file in spec/fixtures/csv_files
called one_line_example.csv
. Paste this content into it:
dog.png,"A Cute Dog",https://www.pexels.com/photo/animal-blur-canine-close-up-551628/
Make another file in spec/fixtures/csv_files
called modular_input.csv
. Paste this content into it:
title,source,visibility,files
"A Cute Dog",https://www.pexels.com/photo/animal-blur-canine-close-up-551628/,open,dog.png
"An Interesting Cat",https://www.pexels.com/photo/person-holding-white-cat-1383397/,open,cat.png|~|birds.png
"A Flock of Birds",https://www.pexels.com/photo/animal-avian-beak-birds-203088/,open,birds.png
Copy the image files into the image folder:
wget https://github.com/RepoCamp/ucla/raw/importer_setup/spec/fixtures/images/birds.png
wget https://github.com/RepoCamp/ucla/raw/importer_setup/spec/fixtures/images/cat.png
wget https://github.com/RepoCamp/ucla/raw/importer_setup/spec/fixtures/images/dog.png
Note: You can see the changes we made in this section on github.
- Why create subdirectories in the fixtures folder?
- What other data can you imagine adding to the fixtures folder over time?
- What makes a good fixture object?