<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Spriyad2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Spriyad2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Spriyad2"/>
	<updated>2026-05-17T02:29:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145430</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145430"/>
		<updated>2022-04-26T03:55:23Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: Ic usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: EC usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' and '''Import Topics''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. After fixing that, there were some lines related to the business logic were missing here. We added those lines and it can be seen in the code diff.&lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported by unchecking that option in the UI as seen in image below. &lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But what happens in the exported file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:B3.jpeg|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason for low test coverage is the fact that our test cases revolve around the high-priority models mentioned above. We covered all the scenarios associated with those models only. Future work will involve writing test cases for other models as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in the future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''. Our Test cases are quite exhaustive, kindly refer to the PR to check the different contexts for each test case in both the controllers. For the sake of simplicity and to keep redundant stuff out we did not write each context on the Wiki page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145423</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145423"/>
		<updated>2022-04-26T03:52:01Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: Ic usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: EC usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' and '''Import Topics''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. After fixing that, there were some lines related to the business logic were missing here. We added those lines and it can be seen in the code diff.&lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported by unchecking that option in the UI as seen in image below. &lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But what happens in the exported file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:B3.jpeg|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''. Our Test cases are quite exhaustive, kindly refer to the PR to check the different contexts for each test case in both the controllers. For the sake of simplicity and keep redundant stuff out we did not write each context in the Wiki page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145416</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145416"/>
		<updated>2022-04-26T03:48:04Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: Ic usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: EC usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' and '''Import Topics''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. After fixing that, there were some lines related to the business logic were missing here. We added those lines and it can be seen in the code diff.&lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported by unchecking that option in the UI as seen in image below. &lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But what happens in the exported file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:B3.jpeg|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145412</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145412"/>
		<updated>2022-04-26T03:45:10Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: Ic usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: EC usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' and '''Import Topics''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. After fixing that, there were some lines related to the business logic were missing here. We added those lines and it can be seen in the code diff.&lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported by unchecking that option in the UI as seen in image below. &lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But what happens in the exported file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:B3.jpeg|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145409</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145409"/>
		<updated>2022-04-26T03:44:12Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: Ic usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: EC usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' and '''Import Topics''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. After fixing that, there were some lines related to the business logic were missing here. We added those lines and it can be seen in the code diff.&lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported by unchecking that option in the UI as seen in image below. &lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But what happens in the exported file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:B3.jpeg|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:B3.jpeg&amp;diff=145400</id>
		<title>File:B3.jpeg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:B3.jpeg&amp;diff=145400"/>
		<updated>2022-04-26T03:42:25Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145248</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145248"/>
		<updated>2022-04-25T21:40:00Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145247</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145247"/>
		<updated>2022-04-25T21:39:15Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''rspec spec/controllers/export_file_controller_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''rspec spec/controllers/import_file_controller_spec.rb ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented fixtures for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145246</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145246"/>
		<updated>2022-04-25T21:38:47Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''rspec spec/controllers/export_file_controller_spec.rb'''''Italic text'' &lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''rspec spec/controllers/import_file_controller_spec.rb '''''Italic text'' &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented fixtures for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145232</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145232"/>
		<updated>2022-04-25T21:30:21Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented fixtures for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145230</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145230"/>
		<updated>2022-04-25T21:27:53Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented fixtures for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145229</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145229"/>
		<updated>2022-04-25T21:27:27Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented fixtures for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145228</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145228"/>
		<updated>2022-04-25T21:26:04Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented fixtures for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fixtures.png&amp;diff=145227</id>
		<title>File:Fixtures.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fixtures.png&amp;diff=145227"/>
		<updated>2022-04-25T21:23:15Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: Spriyad2 uploaded a new version of File:Fixtures.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145221</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145221"/>
		<updated>2022-04-25T21:19:02Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Import_test_coverage.png&amp;diff=145216</id>
		<title>File:Import test coverage.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Import_test_coverage.png&amp;diff=145216"/>
		<updated>2022-04-25T21:16:51Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Export_test_coverage.png&amp;diff=145214</id>
		<title>File:Export test coverage.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Export_test_coverage.png&amp;diff=145214"/>
		<updated>2022-04-25T21:15:32Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:C5.png&amp;diff=145210</id>
		<title>File:C5.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:C5.png&amp;diff=145210"/>
		<updated>2022-04-25T21:03:15Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:C6.png&amp;diff=145209</id>
		<title>File:C6.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:C6.png&amp;diff=145209"/>
		<updated>2022-04-25T21:01:57Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:C4.png&amp;diff=145208</id>
		<title>File:C4.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:C4.png&amp;diff=145208"/>
		<updated>2022-04-25T21:00:09Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:C3.png&amp;diff=145207</id>
		<title>File:C3.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:C3.png&amp;diff=145207"/>
		<updated>2022-04-25T20:59:06Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:C2.png&amp;diff=145206</id>
		<title>File:C2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:C2.png&amp;diff=145206"/>
		<updated>2022-04-25T20:57:52Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:C1.png&amp;diff=145205</id>
		<title>File:C1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:C1.png&amp;diff=145205"/>
		<updated>2022-04-25T20:56:05Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix_4.png&amp;diff=145195</id>
		<title>File:Fix 4.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix_4.png&amp;diff=145195"/>
		<updated>2022-04-25T20:43:52Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Bug1.png&amp;diff=145191</id>
		<title>File:Bug1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Bug1.png&amp;diff=145191"/>
		<updated>2022-04-25T20:38:09Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix3_code.png&amp;diff=145188</id>
		<title>File:Fix3 code.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix3_code.png&amp;diff=145188"/>
		<updated>2022-04-25T20:35:30Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix2_code.png&amp;diff=145187</id>
		<title>File:Fix2 code.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix2_code.png&amp;diff=145187"/>
		<updated>2022-04-25T20:33:11Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix1_code.png&amp;diff=145186</id>
		<title>File:Fix1 code.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fix1_code.png&amp;diff=145186"/>
		<updated>2022-04-25T20:29:52Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145177</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145177"/>
		<updated>2022-04-25T20:24:54Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. The functionality was also working as expected and there were no bugs found for these two models.&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these models since the methods inside these controllers are pretty big and contains a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E3_1.png&amp;diff=145175</id>
		<title>File:E3 1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E3_1.png&amp;diff=145175"/>
		<updated>2022-04-25T20:22:46Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E3.png&amp;diff=145170</id>
		<title>File:E3.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E3.png&amp;diff=145170"/>
		<updated>2022-04-25T20:21:22Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145134</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145134"/>
		<updated>2022-04-25T17:47:45Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. The functionality was also working as expected and there were no bugs found for these two models.&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these models since the methods inside these controllers are pretty big and contains a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.  &lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
[[File:Incorrect column data.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145131</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145131"/>
		<updated>2022-04-25T17:24:09Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
* '''1. Analyzing Export Functionality code flow''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing '''Export Grades''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the '''Bug Fixes''' section. Apart from that there was no '''Export Topics''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the '''New Features Added''' section.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.  &lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
[[File:Incorrect column data.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Incorrect_grouped_column.jpeg&amp;diff=145126</id>
		<title>File:Incorrect grouped column.jpeg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Incorrect_grouped_column.jpeg&amp;diff=145126"/>
		<updated>2022-04-25T17:07:53Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Incorrect_column_data.jpeg&amp;diff=145125</id>
		<title>File:Incorrect column data.jpeg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Incorrect_column_data.jpeg&amp;diff=145125"/>
		<updated>2022-04-25T17:05:52Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145123</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145123"/>
		<updated>2022-04-25T16:59:25Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.  &lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Customization.png&amp;diff=145122</id>
		<title>File:Customization.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Customization.png&amp;diff=145122"/>
		<updated>2022-04-25T16:48:14Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: Screenshot displaying customization page for Export Topics&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot displaying customization page for Export Topics&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Export_Topics.png&amp;diff=145120</id>
		<title>File:Export Topics.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Export_Topics.png&amp;diff=145120"/>
		<updated>2022-04-25T16:47:30Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: Screenshot displaying Export Topics page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot displaying Export Topics page&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145119</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145119"/>
		<updated>2022-04-25T16:45:25Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. &lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.  &lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145118</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145118"/>
		<updated>2022-04-25T16:31:17Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.  &lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145117</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145117"/>
		<updated>2022-04-25T16:17:05Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially High Priority modules are users, topics, and grades and then moving on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
Questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144447</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144447"/>
		<updated>2022-04-06T22:58:23Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: Created page with &amp;quot;== Team== === Mentor ===  * Vinay Deshmukh  === Team Members ===  *Bollineni, Rachana Sri	rbollin@ncsu.edu *Nangia, Chirrag - cnangia@ncsu.edu *Priyadarshan, Saswat - spriyad2...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
This has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
&lt;br /&gt;
'''Our primary goal for this project:'''&lt;br /&gt;
&lt;br /&gt;
* Redo the code, by referring to the code in the pull request. Since the PR hasn’t been merged, it’s not known whether the code was correct or it had issues. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. High Priority modules are users, topics, and grades.&lt;br /&gt;
* Write test cases for the import/export controllers.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
Questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
What we want it to look like:&lt;br /&gt;
&lt;br /&gt;
[[Image: goodUML.png]]&lt;br /&gt;
&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
* Writing test cases for '''import_file_controller''' and '''export_file_controller'''&lt;br /&gt;
* We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=144409</id>
		<title>CSC/ECE 517 Spring 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=144409"/>
		<updated>2022-04-06T21:16:12Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2200: Testing advice_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses_controller, eula_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2204: Adding tests for markup_styles_controller, lock_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2208: Testing for submission_records_controller, profile_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2218: Refactor response_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2217: Refactor questionnaires_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2216: Refactor late_policies_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2215: Refactor student_quizzes_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2214: Refactor teams_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2219: Improve assessment360_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2211: Testing for summary_helper]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2225: Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2221: Refactor submitted content controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2206: Testing for users_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2207: Testing for submitted_content_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2205: Testing for participants_controller, versions_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2212: Testing for hamer.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - S2200: Refactoring evaluation of SQL queries (Java/JUnit)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - S2222: Refactor impersonate_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2202- Testing for badges_controller, publishing_controller]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2022 - E2220: Refactor reputation_web_service_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2224: Refactor review_mapping_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2209: Testing for analytic helper.rb, join team requests helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2227: SQL Injection Fix]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2223. Refactor sign up sheet controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2201: Testing for assignment_questionnaire_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2243. Refactor student_teams functionality]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2245: View for results of bidding]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2241: Heatgrid fixes and improvements]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2237: Grading audit trail]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - S2201: Improving User Experience for SQLFE]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2236: Fix issues related to deadlines and late policies]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2231: Allow reviewers to bid on what to review]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2233. Improving search facility in Expertiza]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2234. Calibration submissions should be copied along with calibration assignments]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2244. Support for saying your team pair-programmed]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2246: Email your authors/reviewers, with complete tests]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2229: Track the time students look at other submissions]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2239: Further refactoring and improvement of review mapping helper.rb ]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2240. Re-write waitlist functionality ]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2242. Fix teammate-review view ]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2235. Issues related to meta-reviewing]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2230. Integrate Suggestion Detection Algorithm]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp;amp; Export controllers]]&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143678</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143678"/>
		<updated>2022-03-28T00:35:04Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* summarize_sentence&lt;br /&gt;
   To test this method we mocked a comments array with the following values [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]. This method is making a web service call at the following Web Service: &lt;br /&gt;
   'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa'&lt;br /&gt;
   We are using expect to compare the expected result with the actual result from the web service call.&lt;br /&gt;
   Disclaimer: This web service call results in a bad gateway error while running the test case. We have already informed our mentor and the professor regarding the same.&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#summarize_sentence' do&lt;br /&gt;
    context 'successful webservice call' do&lt;br /&gt;
      comments = [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]&lt;br /&gt;
      summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']&lt;br /&gt;
      it 'return success' do&lt;br /&gt;
        expect(@summary.summarize_sentences(comments,summary_ws_url)).not_to eql(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage is shown in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Technically this type of initialization is bad coding practice and hence needs refratoring.&lt;br /&gt;
&lt;br /&gt;
We already informed our Mentor and professor regarding these issues and they said it will be included in future work.&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143676</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143676"/>
		<updated>2022-03-28T00:34:08Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* summarize_sentence&lt;br /&gt;
   To test this method we mocked a comments array with the following values [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]. This method is making a web service call at the following Web Service: &lt;br /&gt;
   'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa'&lt;br /&gt;
   We are using expect to compare the expected result with the actual result from the web service call.&lt;br /&gt;
   Disclaimer: This web service call results in a bad gateway error while running the test case. We have already informed our mentor and the professor regarding the same.&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#summarize_sentence' do&lt;br /&gt;
    context 'successful webservice call' do&lt;br /&gt;
      comments = [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]&lt;br /&gt;
      summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']&lt;br /&gt;
      it 'return success' do&lt;br /&gt;
        expect(@summary.summarize_sentences(comments,summary_ws_url)).not_to eql(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage is shown in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Technically this type of initialization is bad coding practice and hence needs refratoring.&lt;br /&gt;
&lt;br /&gt;
We already informed our Mentor and professor regarding these issues and they said it will be included in future work.&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but I think there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143675</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143675"/>
		<updated>2022-03-28T00:33:10Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* summarize_sentence&lt;br /&gt;
   To test this method we mocked a comments array with the following values [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]. This method is making a web service call at the following Web Service: &lt;br /&gt;
   'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa'&lt;br /&gt;
   We are using expect to compare the expected result with the actual result from the web service call.&lt;br /&gt;
   Disclaimer: This web service call results in a bad gateway error while running the test case. We have already informed our mentor and the professor regarding the same.&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#summarize_sentence' do&lt;br /&gt;
    context 'successful webservice call' do&lt;br /&gt;
      comments = [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]&lt;br /&gt;
      summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']&lt;br /&gt;
      it 'return success' do&lt;br /&gt;
        expect(@summary.summarize_sentences(comments,summary_ws_url)).not_to eql(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage shows in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Technically this type of initialization is bad coding practice and hence needs refratoring.&lt;br /&gt;
&lt;br /&gt;
We already informed our Mentor and professor regarding these issues and they said it will be included in future work.&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but I think there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143672</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143672"/>
		<updated>2022-03-28T00:28:36Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* summarize_sentence&lt;br /&gt;
   To test this method we mocked a comments array with the following values [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]. This method is making a web service call at the following Web Service: &lt;br /&gt;
   'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa'&lt;br /&gt;
   We are using expect to compare the expected result with the actual result from the web service call.&lt;br /&gt;
   Disclaimer: This web service call results in a bad gateway error while running the test case. We have already informed our mentor and the professor regarding the same.&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#summarize_sentence' do&lt;br /&gt;
    context 'successful webservice call' do&lt;br /&gt;
      comments = [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]&lt;br /&gt;
      summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']&lt;br /&gt;
      it 'return success' do&lt;br /&gt;
        expect(@summary.summarize_sentences(comments,summary_ws_url)).not_to eql(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage shows in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
We were not able to write test cases for this method. This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Hence we were not able to initialize those variables and it always gives nil value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but I think there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143670</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143670"/>
		<updated>2022-03-28T00:28:17Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* summarize_sentence&lt;br /&gt;
   To test this method we mocked a comments array with the following values [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]. This method is making a web service call at the following Web Service: &lt;br /&gt;
   'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa'&lt;br /&gt;
   We are using expect to compare the expected result with the actual result from the web service call.&lt;br /&gt;
   Disclaimer: This web service call results in a bad gateway error while running the test case. We have already informed our mentor and the professor regarding the same.&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#summarize_sentence' do&lt;br /&gt;
    context 'successful webservice call' do&lt;br /&gt;
      comments = [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]&lt;br /&gt;
      summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']&lt;br /&gt;
      it 'return success' do&lt;br /&gt;
        expect(@summary.summarize_sentences(comments,summary_ws_url)).not_to eql(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage shows in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
We were not able to write test cases for this method. This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Hence we were not able to initialize those variables and it always gives nil value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but I think there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143666</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143666"/>
		<updated>2022-03-28T00:25:49Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* summarize_sentence&lt;br /&gt;
   To test this method we mocked a comments array with the following values [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]. This method is making a web service call at the following Web Service: &lt;br /&gt;
   'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa'&lt;br /&gt;
   We are using expect to compare the expected result with the actual result from the web service call.&lt;br /&gt;
   Disclaimer: This web service call results in a bad gateway error while running the test case. We have already informed our mentor and the professor regarding the same.&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#summarize_sentence' do&lt;br /&gt;
    context 'successful webservice call' do&lt;br /&gt;
      comments = [&amp;quot;Hello this is first comment&amp;quot;, &amp;quot;This is second comment&amp;quot;]&lt;br /&gt;
      summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']&lt;br /&gt;
      it 'return success' do&lt;br /&gt;
        expect(@summary.summarize_sentences(comments,summary_ws_url)).not_to eql(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage shows in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
We were not able to write test cases for this method. This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Hence we were not able to initialize those variables and it always gives nil value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but I think there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143661</id>
		<title>CSC/ECE 517 Spring 2022 - E2211: Testing for summary helper</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2211:_Testing_for_summary_helper&amp;diff=143661"/>
		<updated>2022-03-28T00:18:17Z</updated>

		<summary type="html">&lt;p&gt;Spriyad2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an assignment/project management portal that can be used by both instructors and students for collaborative learning and feedback. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
* Saswat Priyadarshan&lt;br /&gt;
* Rachel Son&lt;br /&gt;
* Bhuwan Bhatt&lt;br /&gt;
&lt;br /&gt;
== Description and Testing ==&lt;br /&gt;
Our project deals with writing test cases for the summary_helper.rb file. The summary helper is responsible for doing the following tasks:&lt;br /&gt;
* Get all answers for each question and send them to summarization WS.&lt;br /&gt;
* Get average scores and a summary for each question in a review by a reviewer.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
* summary_helper.rb&lt;br /&gt;
* summary_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
To successfully run summary_helper_test in local machine, please run the below rspec command. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec spec/helpers/summary_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Requirement ===&lt;br /&gt;
&lt;br /&gt;
summary_helper class had methods which were not tested. Our job was to test all the methods so that we can verify summary_helper class is working fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Test Plan ===&lt;br /&gt;
&lt;br /&gt;
After going through all the methods in the class, we figured out there were some methods that were never being called. So, we removed all the redundant methods that are not being called. Now we had only 9 methods in the class that we need to test. Nine methods in summary_helper class that needed to be tested were:&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee&lt;br /&gt;
* summarize_reviews_by_reviewee_question&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
* summarize_sentences&lt;br /&gt;
* get_sentences&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
* get_sentences&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the testing, we have mock following items :  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:answer) { Answer.new(answer: 1, comments: 'This is a sentence. This is another sentence.', question_id: 1) }&lt;br /&gt;
  let(:answer1){ Answer.new(answer: 2, comments: 'This is a sentence1. This is another sentence1.', question_id: 2)}&lt;br /&gt;
  let(:question) {build(:question, weight:1, type:&amp;quot;Criterion&amp;quot;)}&lt;br /&gt;
  let(:avg_scores_by_criterion) { {a:2.345} }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* get_sentences&lt;br /&gt;
   To test this method we mocked an answer object and checked if the number of sentences is equal to the number of comments provided in the answer.&lt;br /&gt;
   We identified two test cases for this method:&lt;br /&gt;
   1. When the answer is nil&lt;br /&gt;
   2. When the comment is two sentences&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe '#get_sentences' do&lt;br /&gt;
    context 'when the answer is nil' do&lt;br /&gt;
      it 'returns a nil object' do&lt;br /&gt;
        expect(@summary.get_sentences(nil)).to eq(nil)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the comment is two sentences' do&lt;br /&gt;
      it 'returns an array of two sentences' do&lt;br /&gt;
        sentences = @summary.get_sentences(answer)&lt;br /&gt;
        expect(sentences.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* get_max_score_for_question&lt;br /&gt;
   To test this method we mocked two different types of questions which are as follows:&lt;br /&gt;
   1. let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
   2. let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
   Now based on the different question types we tested two scenarios for this method:&lt;br /&gt;
   1. When the question type is Checkbox&lt;br /&gt;
   2. When question type is not Checkbox&lt;br /&gt;
 &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 describe 'get_max_score_for_question' do&lt;br /&gt;
    context 'When question type is Checkbox' do&lt;br /&gt;
      let(:questionOne){Question.new(type:'Checkbox')}&lt;br /&gt;
      it 'returns 1' do&lt;br /&gt;
        max_score = @summary.get_max_score_for_question(questionOne)&lt;br /&gt;
        expect(max_score).to be(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'When question type is not Checkbox' do&lt;br /&gt;
      let(:questionnaire1) { build(:questionnaire, id: 2) }&lt;br /&gt;
      let(:questionTwo) { build(:question, questionnaire: questionnaire1, weight: 1, id: 1) }&lt;br /&gt;
      it 'return the max score for the provided question' do&lt;br /&gt;
        allow(Questionnaire).to receive(:where).with(id:2).and_return(questionnaire1)&lt;br /&gt;
        allow(questionnaire1).to receive(:first).and_return(questionnaire1)&lt;br /&gt;
        expect(@summary.get_max_score_for_question(questionTwo)).to eql(5)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* break_up_comments_to_sentences&lt;br /&gt;
   This methods question answer array and breaks them into comments. &lt;br /&gt;
   In our testing we provided the question_answer array of length 2 and see if the number of comments is equal to 2.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     describe '#break_up_comments_to_sentences' do&lt;br /&gt;
    context 'when the question_answers is not nil' do&lt;br /&gt;
      it 'add the comment to an array to be converted as a json request' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([answer])&lt;br /&gt;
        expect(comments.length).to be(2)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the question_answers is nil' do&lt;br /&gt;
      it 'returns an empty array' do&lt;br /&gt;
        comments = @summary.break_up_comments_to_sentences([])&lt;br /&gt;
        expect(comments.length).to be(0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_criterion&lt;br /&gt;
This test is to see when question answer was given, the output of method is correctly calculated as percentage of question score. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_criterion' do&lt;br /&gt;
    context 'when question_answers are available' do&lt;br /&gt;
      it 'calculate percentage question_score  &amp;amp; no float' do&lt;br /&gt;
   expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 3)).to be_within(0).of(50)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test is to see when question answer was nil, the output of method is correctly calculated as 0. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when question_answers are not available' do&lt;br /&gt;
      it 'gives question scores 0.0' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([], 3)).to eq(0.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test is to see when q_max_score = 0, the output of method is correctly calculated. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context 'when q_max_score = 0' do&lt;br /&gt;
      it 'gives pure question_score' do&lt;br /&gt;
        expect(@summary.calculate_avg_score_by_criterion([answer,answer1], 0)).to eq(3.0)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* calculate_round_score&lt;br /&gt;
The test is to see when the criteria input is nil, the method gives right output of nil, which is 0 in this case. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_round_score' do&lt;br /&gt;
   context 'when criteria not available' do&lt;br /&gt;
     it 'returns 0.0 since round_score = 0.0' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, nil)).to eq(0.to_f)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The test is to see when the criteria input is not nil, the method gives the right output, which is to get a two-digit round score. The criteria input was defined as question in mock section. &lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   context 'when criteria not nil' do&lt;br /&gt;
     it 'get 2 round_score  ' do&lt;br /&gt;
       expect(@summary.calculate_round_score(avg_scores_by_criterion, question)).to be_within(0.01).of(2.345)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* calculate_avg_score_by_round&lt;br /&gt;
This test is to see the method round an average number up to Two-digit. The input of avg_scores_by_criterion was given as 2.345, and we tested here that it gives two-digit round number as 2.35.&lt;br /&gt;
Code Snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#calculate_avg_score_by_round'do&lt;br /&gt;
   context 'when avg_scores_by_criterion available' do&lt;br /&gt;
     it 'gives 2 round value' do&lt;br /&gt;
       expect(@summary.calculate_avg_score_by_round(avg_scores_by_criterion, question)).to eq(2.35)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test Execution ===&lt;br /&gt;
We divided the work among the teammates and started tackling the problems. We stubbed the data using factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage ===&lt;br /&gt;
Our test coverage shows in [https://coveralls.io/builds/47520691/source?filename=app%2Fhelpers%2Fsummary_helper.rb coverails].&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
While we tried to test all the methods in the summary_helper.rb class, we faced some blockers. All the blockers are described below:- &lt;br /&gt;
* summarize_sentences method&lt;br /&gt;
 &lt;br /&gt;
summary_webservice_url: 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa' &lt;br /&gt;
This URL is being used in the summary_helper.rb file and we were not able to mock it. It's giving us bad gateway error while we try to hit that url. &lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee method&lt;br /&gt;
&lt;br /&gt;
In this method we found out in the loop, questions[round] is not the correct way of passing the individual question since questions is an array and use 0 based indexing. Whereas in the above logic it is being treated as a hash.&lt;br /&gt;
&lt;br /&gt;
* summarize_reviews_by_reviewee_question method&lt;br /&gt;
&lt;br /&gt;
We were not able to write test cases for this method. This method uses the instance variables from a different method(summarize_reviews_by_reviewee) which are not being passed as arguments to this method. Hence we were not able to initialize those variables and it always gives nil value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We tested all other remaining methods in the summary_helper.rb class. All the unit tests passed and the methods were working as expected. We tried to cover corner cases but I think there is room for some improvement.&lt;/div&gt;</summary>
		<author><name>Spriyad2</name></author>
	</entry>
</feed>