New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit and functional tests #999

Open
Safihre opened this Issue Aug 10, 2017 · 24 comments

Comments

Projects
None yet
7 participants
@Safihre
Member

Safihre commented Aug 10, 2017

We really need unit and functional tests.
Biggest hurdle, especially for functional tests: we need a mock-NNTP server.
We could use NZBGet's NServ, but that kind of feels wrong...

Anyone that wants to help me with this?
Especially with the creation of this mock NNTP server.

Tasks and tests:

  • Creation of a mock-NNTP server that can:
    • Respond to authentication requests
    • Respond to data-request with yEnc encoded data
  • Test-platform that can start this server, send requests to it and wait for API-response
  • Test-platform for starting of SABnzbd with specific parameters
  • Test startup of SABnzbd
    • Correct binding to HTTP(S) ports
    • Response to occupied port
    • Response to missing dependencies or wrong encoding
  • Implement functional tests - NNTP authentication
    • Response to correct login
    • Response to bad login
    • Response to SSL on non-SSL port
    • Response to bad certificates
  • Implement functional tests - Downloading
    • Can it download a normal file from the mock server
      • NZB added as .nzb
      • NZB added inside .tar.gz, or .zip or .rar
    • Can it download a damaged file from the mock server and repair/unpack
    • Can it download a obfuscated file from the mock server
    • Verification using only RAR-verification (test expected fail and success)
    • Verification using only SFV-verification (test expected fail and success)
    • Can it download a normal file from the mock server with UTF8 chars in the RAR filenames or the filenames inside the RAR's (both RAR3 and RAR5)
    • Can it download a broken and/or obfuscated file from the mock server with UTF8 chars in the RAR filenames or the filenames inside the RAR's (both RAR3 and RAR5)
    • Can it detect password jobs during downloading, also when the jobs have UTF8 filenames (both RAR3 and RAR5)
    • Can it detect unwanted jobs during downloading, also when the jobs have UTF8 filenames (both RAR3 and RAR5)
    • Can it download and repair passworded jobs (both RAR3 and RAR5)
    • Test for duplicate detection
    • Can it handle 7zip files
    • Can it handle zip files
    • Can it handle join-files
  • Implement functional tests - RSS filter handeling
  • Implement functional tests - Other config options
    • Pre-queue script running
    • Post-processing script running
    • Notification script running
    • Ignore samples option
    • Download all par2 option
    • Testing of sorting (many sub-tests should be made here!)
    • Testing of scheduler (not sure yet how..)
  • Other tests
    • Is category parsed correctly from NZB (from filename {{}}file.nzb or from tag inside NZB)
    • Is password parsed correctly from NZB (from filename file{{}}.nzb or from tag inside NZB)

@Safihre Safihre added this to the Backlog milestone Aug 10, 2017

@sanderjo

This comment has been minimized.

Show comment
Hide comment
@sanderjo

sanderjo Aug 11, 2017

Contributor

Can it be an(other) existing NNTP-server?
Must the NNTP-server be in python code, or can it be in C or Go?

Contributor

sanderjo commented Aug 11, 2017

Can it be an(other) existing NNTP-server?
Must the NNTP-server be in python code, or can it be in C or Go?

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Aug 11, 2017

Member

It can be another yes, and the language also doesn't really matter I think. We can use TravisCI and Appveyor to compile it before running the tests.

Member

Safihre commented Aug 11, 2017

It can be another yes, and the language also doesn't really matter I think. We can use TravisCI and Appveyor to compile it before running the tests.

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Aug 11, 2017

Contributor

What wrong with using nzbgets nserv? It even states that it can be used with other clients.

Contributor

Hellowlol commented Aug 11, 2017

What wrong with using nzbgets nserv? It even states that it can be used with other clients.

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Aug 11, 2017

Member

It's like using Android to test iOS 😁

Member

Safihre commented Aug 11, 2017

It's like using Android to test iOS 😁

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Aug 19, 2017

Contributor

@Safihre Are you gonna use pytest?

Contributor

Hellowlol commented Aug 19, 2017

@Safihre Are you gonna use pytest?

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Aug 19, 2017

Member

No clue, is that the easiest?

Member

Safihre commented Aug 19, 2017

No clue, is that the easiest?

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Aug 19, 2017

Contributor

Yep. Its a lot less boilerplate.

Contributor

Hellowlol commented Aug 19, 2017

Yep. Its a lot less boilerplate.

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Aug 24, 2017

Member

@sanderjo @Hellowlol (and anybody else wanting to help): I created a tasks list of things that should be included, maybe this helps to get things going

Member

Safihre commented Aug 24, 2017

@sanderjo @Hellowlol (and anybody else wanting to help): I created a tasks list of things that should be included, maybe this helps to get things going

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Aug 24, 2017

Contributor

Maybe we can use twisted AS nntp server.

Contributor

Hellowlol commented Aug 24, 2017

Maybe we can use twisted AS nntp server.

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Aug 25, 2017

Member

Sure, you have experience with it? I don't but it seems interesting.
It doesn't have to by high performance at all, just has to work 💯

Member

Safihre commented Aug 25, 2017

Sure, you have experience with it? I don't but it seems interesting.
It doesn't have to by high performance at all, just has to work 💯

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Sep 6, 2017

Member

I have added super basic tests, it will start SABnzbd and then test for basic API and page-serving functionality.
At least that would prevent what happened with 2.3.0Alpha1 where the Config > Switches page didn't work.

Much more work to do!

Member

Safihre commented Sep 6, 2017

I have added super basic tests, it will start SABnzbd and then test for basic API and page-serving functionality.
At least that would prevent what happened with 2.3.0Alpha1 where the Config > Switches page didn't work.

Much more work to do!

@thezoggy

This comment has been minimized.

Show comment
Hide comment
@thezoggy

thezoggy Sep 6, 2017

Contributor

any doc on how to add tests / run it / etc..

Contributor

thezoggy commented Sep 6, 2017

any doc on how to add tests / run it / etc..

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Sep 6, 2017

Member

Will add docs when there's actually functional tests, the tests are embarrassingly simple right now.
But in case (shutdown SABnzbd first!):

pip install pytest pytest-xprocess
pytest
Member

Safihre commented Sep 6, 2017

Will add docs when there's actually functional tests, the tests are embarrassingly simple right now.
But in case (shutdown SABnzbd first!):

pip install pytest pytest-xprocess
pytest
@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Sep 7, 2017

Member

Working in this branch: https://github.com/sabnzbd/sabnzbd/tree/feature/pytest
If anyone wants to contribute, just PR against that 👍
Just added basic testing of adding and removing NZB's.

Thinking of just using the SABnzbd Giganews account for now to test downloading (with the username/password encoded of course) of some of @sanderjo's test NZB's.

Member

Safihre commented Sep 7, 2017

Working in this branch: https://github.com/sabnzbd/sabnzbd/tree/feature/pytest
If anyone wants to contribute, just PR against that 👍
Just added basic testing of adding and removing NZB's.

Thinking of just using the SABnzbd Giganews account for now to test downloading (with the username/password encoded of course) of some of @sanderjo's test NZB's.

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Sep 7, 2017

Contributor

Good stuff, i got some stuff i need to finish (sabapi for one) but ill see if i cant get started this week.

Contributor

Hellowlol commented Sep 7, 2017

Good stuff, i got some stuff i need to finish (sabapi for one) but ill see if i cant get started this week.

Safihre added a commit that referenced this issue Sep 8, 2017

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Sep 8, 2017

Member

AppVeyor was added to also enable automatic Windows platform testing.

Member

Safihre commented Sep 8, 2017

AppVeyor was added to also enable automatic Windows platform testing.

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Sep 25, 2017

Contributor

http://flylib.com/books/en/2.407.1.69/1/ describe how to setup a minimal nntp server using twisted. Ill try to play with it and see how it goes.

Contributor

Hellowlol commented Sep 25, 2017

http://flylib.com/books/en/2.407.1.69/1/ describe how to setup a minimal nntp server using twisted. Ill try to play with it and see how it goes.

@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Sep 26, 2017

Member

@Hellowlol interesting, very extensive. Doesn't include the yEnc encoding as far as I can see, but good basis!

Member

Safihre commented Sep 26, 2017

@Hellowlol interesting, very extensive. Doesn't include the yEnc encoding as far as I can see, but good basis!

@OldskoolOrion

This comment has been minimized.

Show comment
Hide comment
@OldskoolOrion

OldskoolOrion Oct 8, 2017

I will start looking into this as well as first task.. I used Mozilla's MailMan FakeServer back in the day which was really nice for functional testing of imap-, smtp-, nntp-protocol stuff etc (conforming to rfc) - lot of examples there to start with and easy integratable in automatic workflow by the looks of it. Need to dive in and get my hands dirty to be 100% sure its a good choice of course, since I'm not yet knee-deep in sab's codebase either, and have no helicopter view yet of all the needed reqs.

Yes it's old and yes it's in that horrible javashit non-language, but if it do exactly what we want and is extremely easy to extend and adept, it's a valid option I think.

Besides that I already checked out some nice Golang based nntp-server & client stuff, which is OS, well supported and even in use live, let alone just as local server for functional testing.. I'm definitely going to dive deeper into that as well, since I still have to start teaching myself Go on a more than basic-level. Very platform-independent, quite fast, good libs and friendly community with quality server-client related packages out there.

And if all this plus stuff that's under investigation fails for us.. then there's always nserv.. but I agree.. out of respect to sab itself and nzbget as well.. it would be more elegant if sab wouldn't have to rely on nserv :-)

Lotsa spare time tomorrow to start rocking.. documentation has been collected.. a lot of source code has been git'd.
Good start to getting to know the codebase while actually doing something useful :-)

OldskoolOrion commented Oct 8, 2017

I will start looking into this as well as first task.. I used Mozilla's MailMan FakeServer back in the day which was really nice for functional testing of imap-, smtp-, nntp-protocol stuff etc (conforming to rfc) - lot of examples there to start with and easy integratable in automatic workflow by the looks of it. Need to dive in and get my hands dirty to be 100% sure its a good choice of course, since I'm not yet knee-deep in sab's codebase either, and have no helicopter view yet of all the needed reqs.

Yes it's old and yes it's in that horrible javashit non-language, but if it do exactly what we want and is extremely easy to extend and adept, it's a valid option I think.

Besides that I already checked out some nice Golang based nntp-server & client stuff, which is OS, well supported and even in use live, let alone just as local server for functional testing.. I'm definitely going to dive deeper into that as well, since I still have to start teaching myself Go on a more than basic-level. Very platform-independent, quite fast, good libs and friendly community with quality server-client related packages out there.

And if all this plus stuff that's under investigation fails for us.. then there's always nserv.. but I agree.. out of respect to sab itself and nzbget as well.. it would be more elegant if sab wouldn't have to rely on nserv :-)

Lotsa spare time tomorrow to start rocking.. documentation has been collected.. a lot of source code has been git'd.
Good start to getting to know the codebase while actually doing something useful :-)

Safihre referenced this issue Dec 6, 2017

Add 'Job Name as Folder Name' as Sorting Preset for de-obfuscation
Also rename internal variable `dirname`, since it's really just the job-name.
@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Apr 1, 2018

Member

I am trying to add a simple unit-test, but I am failing.
How would I test for example sabnzbd.misc.calc_age from a test .py file in the tests directory executed by pytest?
Anyone that can help me out? :)

Member

Safihre commented Apr 1, 2018

I am trying to add a simple unit-test, but I am failing.
How would I test for example sabnzbd.misc.calc_age from a test .py file in the tests directory executed by pytest?
Anyone that can help me out? :)

@Hellowlol

This comment has been minimized.

Show comment
Hide comment
@Hellowlol

Hellowlol Apr 1, 2018

Contributor

I normally import the stuff I need in conftest.py then in test_misc.py

from conftest import misc
def test_calc_age():
    pass
Contributor

Hellowlol commented Apr 1, 2018

I normally import the stuff I need in conftest.py then in test_misc.py

from conftest import misc
def test_calc_age():
    pass
@Safihre

This comment has been minimized.

Show comment
Hide comment
@Safihre

Safihre Aug 14, 2018

Member

I am considering (due to a project at work) moving the functional tests to an actual functional-testing tool like Selenium. This way we can test actual user flow instead of just API calls.

Member

Safihre commented Aug 14, 2018

I am considering (due to a project at work) moving the functional tests to an actual functional-testing tool like Selenium. This way we can test actual user flow instead of just API calls.

@james-d-elliott

This comment has been minimized.

Show comment
Hide comment
@james-d-elliott

james-d-elliott Sep 14, 2018

I can probably setup a server for this if we are still looking for something, and I might work out how to build a docker image for it.

james-d-elliott commented Sep 14, 2018

I can probably setup a server for this if we are still looking for something, and I might work out how to build a docker image for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment