Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Test_Recommendation/Test_case_1/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RECOMMENDATION_SYSTEM_DOCKER_ADDRESS=0.0.0.0
RECOMMENDATION_SYSTEM_NAME=root1
RECOMMENDATION_SYSTEM_PASSWORD=rahul123
RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS=172.19.0.3:8000
21 changes: 21 additions & 0 deletions Test_Recommendation/Test_case_1/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Test cases for Recommendation System

## Prerequisites
1. The system should have some articles,users and community.
2. __Model must be trained before__.The system should have some recommendation showing in the recommendation list i.e., the model must be trained before execution of test_recommendation.py file.
3. Please check that there should be some recommendation in the article.

## Running Test Cases
This test case runs by executing the test_recommendation.py file

## Explaination
Login into Collaboration System .Open the Articles link, select an article. Open
the links in the recommendation list one by one and links should open without
any error.

## `.env` Variables
The requirements in the .env file:
1. __RECOMMENDATION_SYSTEM_DOCKER_ADDRESS__: This field is the ip address of the docker.
2. __RECOMMENDATION_SYSTEM_NAME__: This field is the username of any existing user in the system(prefered django admin).
3. __RECOMMENDATION_SYSTEM_PASSWORD__: This field is the password of above username.
4. __RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS__: This field is the ip address of the Collaborative system (with ports).
70 changes: 70 additions & 0 deletions Test_Recommendation/Test_case_1/test_recommendation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import unittest
from selenium import webdriver
from decouple import config
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

RECOMMENDATION_SYSTEM_DOCKER_ADDRESS = config("RECOMMENDATION_SYSTEM_DOCKER_ADDRESS")
RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS=config("RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS")
RECOMMENDATION_SYSTEM_PASSWORD = config("RECOMMENDATION_SYSTEM_PASSWORD")
RECOMMENDATION_SYSTEM_NAME = config("RECOMMENDATION_SYSTEM_NAME")

class TestRecommendation(unittest.TestCase):
def setUp(self):
# self.driver = webdriver.Firefox()
# RECOMMENDATION_SYSTEM_DOCKER_ADDRESS = config("RECOMMENDATION_SYSTEM_ADDRESS")
self.driver = webdriver.Remote(command_executor='http://'+RECOMMENDATION_SYSTEM_DOCKER_ADDRESS+':4444/wd/hub',desired_capabilities=DesiredCapabilities.FIREFOX)
# RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS=config("RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS")
# RECOMMENDATION_SYSTEM_PASSWORD = config("RECOMMENDATION_SYSTEM_PASSWORD")
# RECOMMENDATION_SYSTEM_NAME = config("RECOMMENDATION_SYSTEM_NAME")
#print(RECOMMENDATION_SYSTEM_NAME)
#print(RECOMMENDATION_SYSTEM_PASSWORD)
#print(RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS)
self.login_link="http://" + RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS+ "/login/?next=/"
self.article_link="http://"+RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS +"/articles/"
#print(self.article_link)
#print(self.login_link)
self.logout_link="http://"+ RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS+ "/logout/"
#print(self.logout_link)
self.driver.maximize_window() #For maximizing window
self.driver.implicitly_wait(20) #gives an implicit wait for 20 seconds
self.driver.get(self.login_link)
elem = self.driver.find_element_by_id("id_username")
elem.send_keys(RECOMMENDATION_SYSTEM_NAME)
elem = self.driver.find_element_by_id("id_password")
elem.send_keys(RECOMMENDATION_SYSTEM_PASSWORD)
self.driver.find_element_by_class_name('btn-block').click()

def test_recommendation(self):
self.driver.get(self.article_link)
self.driver.implicitly_wait(2000)
elem = self.driver.find_elements_by_tag_name('h3')
name=elem[0].text
self.driver.find_element_by_link_text(name).click()
self.driver.implicitly_wait(2000)
elem=self.driver.find_elements_by_class_name('alert.alert-info')[1]
elem1=elem.find_elements_by_tag_name('h5')
n=len(elem1)
for i in range(n):
self.driver.implicitly_wait(20)
elem1=elem.find_elements_by_tag_name('h5')
c=elem1[i].text
#print(c)
self.driver.find_element_by_link_text(c).click()
self.driver.implicitly_wait(2000)
assert "Page not found" not in self.driver.page_source
self.driver.get(self.article_link)
self.driver.implicitly_wait(2000)
elem = self.driver.find_elements_by_tag_name('h3')
name=elem[0].text
self.driver.find_element_by_link_text(name).click()
self.driver.implicitly_wait(2000)
elem=self.driver.find_elements_by_class_name('alert.alert-info')[1]
elem1=elem.find_elements_by_tag_name('h5')

def tearDown(self):
self.driver.get(self.logout_link)
self.driver.quit()


if __name__ == '__main__':
unittest.main()
9 changes: 9 additions & 0 deletions Test_Recommendation/Test_case_2/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RECOMMENDATION_SYSTEM_DOCKER_ADDRESS=localhost
RECOMMENDATION_SYSTEM_NAME=root1
RECOMMENDATION_SYSTEM_PASSWORD=rahul123
RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS=localhost:7000
RECOMMENDATION_SYSTEM_DJANGO_ADMIN_NAME=root1
RECOMMENDATION_SYSTEM_DJANGO_ADMIN_PASSWORD=rahul123
RECOMMENDATION_SYSTEM_MINIMUM_RECOMMENDATION_PERCENTAGE=60
RECOMMENDATION_SYSTEM_WEB_IP=10.196.30.73
RECOMMENDATION_SYSTEM_WEB_PORT=7000
46 changes: 46 additions & 0 deletions Test_Recommendation/Test_case_2/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Test Case 2

## Overview
1. This test case runs by executing the test_file_driver.py file which runs all other python script.
2. No need to run other python file other than the test_file_driver.py.
3. The test_file1.py and test_file2.py set up the environment for this test case.
4. The test_file3.py contains the test_reco function which test the recommendation.
5. The test_file4.py tear down (remove) the environment which is required to run this test case.

__IMPORTANT__. test_file1.py create 2 communities, 3 users, 6 articles in each communities by django-admin.
test_file2.py give views to the articles of test_community_1 using test_user_1 and same for test_community_2 by test_user_3.
And test_user_3 gives some views(lesser than) to articles of test_community_1. For more information see idea given below.

## Explaination
Create 2 communities and add 6 published articles in each community. Add 3
users to the system. All this will be done by django admin. The first user will join
community 1 and the second user will join community 2. Now create some views
for the articles in each community. The user in community 1 will give views to
some articles of community 1 and user 2 will do the same for community 2. Some
articles will get more views than the others in each community. For instance,
article 1 from community 1 will get 10 views, article 2 will get 8 views, article 3
will get 2 views and the left wouldn't get any new views by user1 and similarly in
community 2 by user 2. Now Login as user 3 and view articles 2,3 and 4 from
community 1. Finally, train the model.
The percentage of articles present in the recommendations list of test_user_3 should be more from the community 1
than the community 2.

## `.env` Varialbles:

1. __RECOMMENDATION_SYSTEM_DOCKER_ADDRESS.__ This field is the ip address of the docker.
2. __RECOMMENDATION_SYSTEM_NAME.__ This field is the username of any existing user in the system(prefered django admin).
3. __RECOMMENDATION_SYSTEM_PASSWORD.__ This field is the password of above username.
4. __RECOMMENDATION_SYSTEM_DEPLOY_ADDRESS.__ This field is the ip address of the Collaborative system (with ports).
5. __RECOMMENDATION_SYSTEM_DJANGO_ADMIN_NAME.__ This field is the username of django admin.
6. __RECOMMENDATION_SYSTEM_DJANGO_ADMIN_PASSWORD.__ This field is the password of django admin.
7. __RECOMMENDATION_SYSTEM_MINIMUM_RECOMMENDATION_PERCENTAGE.__ This field is set by tester which required, the minimum percentage of test community articles 1 in the recommendation of test user 3.( default: 60% )
8. __RECOMMENDATION_SYSTEM_WEB_IP.__ This field is the IP address of the system.
9. __RECOMMENDATION_SYSTEM_WEB_PORT.__ This field is the IP address-port of the system.


## Warning
The web driver may fail. Then, in that case It is required to remove the test_community1 and test_community2,test_user1,test_user2,test_user3,test_community_article_11,....,etc (if formed, check in django admin).And then run the test_file_driver.py again.

### Note
1. The image is kept because the selenium is creating the community and article. It is required the image file.
2. For the proper working of the test_file3, make sure , the model is trained after the execution of test_file2.py.
Binary file added Test_Recommendation/Test_case_2/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading