def test_download_exercise_csv(self): # Given a patched exercise instrument = InstrumentModel() seft_file = SEFTModel(instrument_id=instrument.instrument_id, file_name="file_name", data="test_data", length=999) instrument.seft_file = seft_file exercise = ExerciseModel( exercise_id="cb0711c3-0ac8-41d3-ae0e-567e5ea1ef87") business = BusinessModel(ru_ref="test_ru_ref") instrument.exercises.append(exercise) instrument.businesses.append(business) with patch( "application.controllers.collection_instrument.query_exercise_by_id", return_value=exercise): # When a call is made to the download_csv end point response = self.client.get( "/collection-instrument-api/1.0.2/download_csv/cb0711c3-0ac8-41d3-ae0e-567e5ea1ef87", headers=self.get_auth_headers(), ) # Then the response contains the correct data self.assertStatus(response, 200) self.assertIn('"Count","File Name","Length","Time Stamp"', response.data.decode()) self.assertIn('"1","file_name","999"', response.data.decode())
def add_instrument_without_exercise(session=None): instrument = InstrumentModel(ci_type="EQ", classifiers={ "form_type": "001", "geography": "EN" }) survey = SurveyModel(survey_id="cb0711c3-0ac8-41d3-ae0e-567e5ea1ef87") instrument.survey = survey business = BusinessModel(ru_ref="test_ru_ref") instrument.businesses.append(business) session.add(instrument) return instrument.instrument_id
def add_instrument_data(session=None): instrument = InstrumentModel(ci_type="SEFT") seft_file = SEFTModel(instrument_id=instrument.instrument_id, file_name="test_file") exercise = ExerciseModel(exercise_id="db0711c3-0ac8-41d3-ae0e-567e5ea1ef87") business = BusinessModel(ru_ref="test_ru_ref") instrument.seft_file = seft_file instrument.exercises.append(exercise) instrument.businesses.append(business) survey = SurveyModel(survey_id="cb0711c3-0ac8-41d3-ae0e-567e5ea1ef87") instrument.survey = survey session.add(instrument) return instrument.instrument_id
def _find_or_create_business(ru_ref, session): """ Creates a business in the db if it doesn't exist, or reuses if it does :param ru_ref: The name of the file we're receiving :param session: database session :return: business """ business = query_business_by_ru(ru_ref, session) if not business: log.info('creating business', ru_ref=ru_ref) business = BusinessModel(ru_ref=ru_ref) return business
def add_instrument_data(session=None): instrument = InstrumentModel(classifiers={ "form_type": "001", "geography": "EN" }, ci_type="SEFT") crypto = Cryptographer() data = BytesIO(b"test data") data = crypto.encrypt(data.read()) seft_file = SEFTModel(instrument_id=instrument.instrument_id, file_name="test_file", length="999", data=data) instrument.seft_file = seft_file exercise = ExerciseModel(exercise_id=linked_exercise_id) business = BusinessModel(ru_ref="test_ru_ref") instrument.exercises.append(exercise) instrument.businesses.append(business) survey = SurveyModel(survey_id="cb0711c3-0ac8-41d3-ae0e-567e5ea1ef87") instrument.survey = survey session.add(instrument) return instrument.instrument_id