AIVPN icon indicating copy to clipboard operation
AIVPN copied to clipboard

Add test file for AI VPN CLI: aivpn.py

Open Adity20 opened this issue 10 months ago • 6 comments

Pull request type

Please check the type of change your PR introduces:

  • [ ] Feature

What is the current behavior?

Closes #52

  1. In this unit test I created a mock Redis client object to simulate interactions with the Redis database without actually connecting to it.
  2. Then, I called the functions to test with mock parameters and verify their behavior by adding assertions to check if the expected actions are performed.

What is the new behavior?

The project is not having any sort of unit testing right now so this is a sample unit test to start the process of "code enhancement using unit testing" project.

Other information

This unit test is related to AIVPN file.

Adity20 avatar Mar 27 '24 15:03 Adity20

@verovaleros Kindly review this new PR please :)

Adity20 avatar Mar 27 '24 15:03 Adity20

Can you write one sentence for each function test with what you aim to test? For every component of the CLI we can test for a wide variety of things, so I want to make sure we both understand exactly what functionality your tests aim to cover.

Tested locally, and all tests passed, but I want to double-check we agree on the logic. Thanks!

verovaleros avatar Mar 27 '24 16:03 verovaleros

I will do one thing then @verovaleros. I will add all the tests I have written for the AIVPN CLI. These were some of them but now I'll commit all the tests with proper comments so that it's easy to understand.

Adity20 avatar Mar 27 '24 16:03 Adity20

That sounds good. I love small atomic commits with clear messages so I can track the changes as well. Thanks!

verovaleros avatar Mar 27 '24 16:03 verovaleros

These are some info related to each function test as you asked

test_manage_info_active_profile(self):: This is a test method for the manage_info function when the profile is active. Inside this method, I mocked the get_profile_vpn_type function to return a specific value, simulating its behavior during testing. Then used the patch context manager to temporarily replace the real function with the mock one during the test.

test_manage_info_expired_profile(self):: This is a test method for the manage_info function when the profile is expired. Similar to the previous test, I mocked various functions related to expired profiles to simulate their behavior during testing.

test_manage_expire(self):: This is a test method for the manage_expire function. Inside this method, I mocked various functions related to profile expiration to simulate their behavior during testing.

Adity20 avatar Mar 27 '24 16:03 Adity20

Added 3 more tests All are working fine Screenshot 2024-03-28 114726

Adity20 avatar Mar 28 '24 06:03 Adity20