CSC/ECE 517 Spring 2023 - G2334 Develop and refactor test suite for GraphQL Query: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "== Team== === Mentor === * Jialin Cui === Team Members === * Aman Waoo * Girish Wangikar * Pranavi Sharma Sanganabhatla == Description and Testing == Our project deals wit...")
 
No edit summary
Line 6: Line 6:
=== Team Members ===
=== Team Members ===


* Aman Waoo
* Aman Waoo (awaoo)
* Girish Wangikar
* Girish Wangikar (gwangik)
* Pranavi Sharma Sanganabhatla
* Pranavi Sharma Sanganabhatla (psangan)


== Description and Testing ==
== Description and Testing ==
Our project deals with refactoring the test_suit file. The code is responsible for doing the following tasks:
 
According to the instructions, we appear to be expected to work on a Python project that makes API calls to the GitHub GraphQL API using the requests package. We must rewrite the current test cases such that mocking libraries are used in place of actual API calls, and we must also add new test cases to boost the test coverage.
 
Tasks to be accomplished :


* Test functions should have names that are both descriptive and explicit so that it is evident what part of the system they are testing.
* Test functions should have names that are both descriptive and explicit so that it is evident what part of the system they are testing.
* Several tests in the current codebase make actual API calls as opposed to using mock calls. Make mock test calls from these tests.
* Several tests in the current codebase make actual API calls as opposed to using mock calls. Make mock test calls from these tests.
*  
* Change the requirements.txt file to reflect the newly installed packages (pytest-cov and pytest-mock).
* Get the code fully tested.
* Get the code fully tested.
   
   
=== Files Involved ===
=== Files Involved ===


Line 24: Line 26:
* requirements.txt
* requirements.txt
* env file
* env file
=== Running Tests ===
To successfully run answer_spec on the local machine, please run the below rspec command.
<pre>
  rspec spec/answer_spec.rb
</pre>




Line 47: Line 43:
Code Snippet:
Code Snippet:


    scope :by_question_for_reviewee_in_round, -> (assignment_id, reviewee_id, q_id, round) do
      joins(response: {map: :reviewer})
      .joins(:question)
      .where("review_maps.reviewed_object_id = ? AND
              review_maps.reviewee_id = ? AND
              answers.question_id = ? AND
              responses.round = ?", assignment_id, reviewee_id, q_id, round)
      .select(:answer, :comments)
  end
* answers_by_question:
  1. This method joins the questions, answers, responses, and response_maps table.
  2. Then it applies a where clause to filter the results based on the given q_id and assignment_id.
  3. It retrieves the distinct answers and comments columns from the combined table.
Code Snippet:
    scope :by_question, -> (assignment_id, q_id) do
        joins(response: {map: :reviewer})
        .joins(:question)
        .where("review_maps.reviewed_object_id = ? AND
              answers.question_id = ?", assignment_id, q_id)
        .select(:answer, :comments)
        .distinct
    end
* answers_by_question:
  1. This method joins the responses, answers, response_maps, and questions table. 
  2. Then it applies a where clause to filter the results based on the given assignment_id, reviewee_id and q_id. 
  3. It retrieves answers and comments columns from the combined table.
Code Snippet:
    scope :by_question, -> (assignment_id, q_id) do
        joins(response: {map: :reviewer})
        .joins(:question)
        .where("review_maps.reviewed_object_id = ? AND
              answers.question_id = ?", assignment_id, q_id)
        .select(:answer, :comments)
        .distinct
    end


== Test Plan ==
== Test Plan ==


We have implemented test cases using RSpec for different validation checks for answer.rb.
Code Snippet:
  require '/Users/aw/Documents/Course Study Material/OODD/Program 3/spec/rails_helper.rb'
  require '/Users/aw/Documents/Course Study Material/OODD/Program 3/spec/spec_helper.rb'
  RSpec.describe Answer, type: :model do
    describe ".by_question_for_reviewee_in_round" do
      let(:assignment) { create(:assignment) }
      let(:reviewer) { create(:user) }
      let(:reviewee) { create(:user) }
      let(:round) { 1 }
      let(:question) { create(:question, assignment: assignment) }
      let(:response_map) { create(:review_map, reviewed_object: assignment, reviewer: reviewer, reviewee: reviewee) }
      let(:response) { create(:response, map: response_map, round: round) }
      let!(:answer) { create(:answer, question: question, response: response) }
      it "returns the answer and comments for the specified question, reviewee, assignment, and round" do
        expect(Answer.by_question_for_reviewee_in_round(assignment.id, reviewee.id, question.id, round))
          .to match_array([{answer: answer.answer, comments: answer.comments}])
    end
  end
  describe ".by_question" do
    let(:assignment) { create(:assignment) }
    let(:reviewer) { create(:user) }
    let(:question) { create(:question, assignment: assignment) }
    let(:response_map) { create(:review_map, reviewed_object: assignment, reviewer: reviewer) }
    let(:response) { create(:response, map: response_map) }
    let!(:answer) { create(:answer, question: question, response: response) }
    it "returns the answer and comments for the specified question and assignment" do
      expect(Answer.by_question(assignment.id, question.id))
        .to match_array([{answer: answer.answer, comments: answer.comments}])
    end
  end
  describe ".by_question_for_reviewee" do
    let(:assignment) { create(:assignment) }
    let(:reviewer) { create(:user) }
    let(:reviewee) { create(:user) }
    let(:question) { create(:question, assignment: assignment) }
    let(:response_map) { create(:review_map, reviewed_object: assignment, reviewer: reviewer, reviewee: reviewee) }
    let(:response) { create(:response, map: response_map) }
    let!(:answer) { create(:answer, question: question, response: response) }
    it "returns the answer and comments for the specified question, reviewee, and assignment" do
      expect(Answer.by_question_for_reviewee(assignment.id, reviewee.id, question.id))
        .to match_array([{answer: answer.answer, comments: answer.comments}])
    end
  end
  describe ".by_response" do
    let(:response) { create(:response) }
    let!(:answer) { create(:answer, response: response) }
    it "returns the answer for the specified response" do
      expect(Answer.by_response(response.id)).to eq([answer.answer])
    end
  end
end


=== Test Execution ===
=== Test Execution ===

Revision as of 23:58, 7 April 2023

Team

Mentor

  • Jialin Cui

Team Members

  • Aman Waoo (awaoo)
  • Girish Wangikar (gwangik)
  • Pranavi Sharma Sanganabhatla (psangan)

Description and Testing

According to the instructions, we appear to be expected to work on a Python project that makes API calls to the GitHub GraphQL API using the requests package. We must rewrite the current test cases such that mocking libraries are used in place of actual API calls, and we must also add new test cases to boost the test coverage.

Tasks to be accomplished :

  • Test functions should have names that are both descriptive and explicit so that it is evident what part of the system they are testing.
  • Several tests in the current codebase make actual API calls as opposed to using mock calls. Make mock test calls from these tests.
  • Change the requirements.txt file to reflect the newly installed packages (pytest-cov and pytest-mock).
  • Get the code fully tested.

Files Involved

  • test_suit.py
  • requirements.txt
  • env file


Project Description

The objective of the project is to refactor the following Ruby on Rails model classes in the existing project:- Answer Model on Expertiza.The model is designed to represent answers to questions in Expertiza. So, whenever anyone fills out a rubric, each “question” that is answered creates a new Answer object.

The task is to refactor the existing code present in the model file and implement them in a new repository. Since the project is implemented from scratch, there are various aspects of the project that have to be implemented and therefore unit test cases are implemented to test the implementation.


  • answers_by_question_for_reviewee_in_round:
 1. This method joins the responses, answers, response_maps, and questions table. 
 2. Then it applies a where clause to filter the results based on the given assignment_id, reviewee_id, q_id, and round parameters. 
 3. It retrieves answers and comments columns from the combined table. 


Code Snippet:


Test Plan

Test Execution

We divided the work among the teammates and started tackling the problems. We stubbed the data using the 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.


Conclusion

We have refactored the code in the answer.rb file to return answers in each response. We have tested the model fully and attaching the video of the passed test cases in the submission.