Skip to content
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

Refactor connector opsdroid pointer #749

Merged
merged 18 commits into from
Dec 3, 2018
Merged

Conversation

zonagilreath
Copy link
Contributor

@zonagilreath zonagilreath commented Nov 21, 2018

Description

Slight update to previous request

Fixes #725

Status

READY

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation (fix or adds documentation)

How Has This Been Tested?

Tox tests passing

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@codecov
Copy link

codecov bot commented Nov 21, 2018

Codecov Report

Merging #749 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #749   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          28     28           
  Lines        1856   1850    -6     
=====================================
- Hits         1856   1850    -6
Impacted Files Coverage Δ
opsdroid/connector/github/__init__.py 100% <100%> (ø) ⬆️
opsdroid/connector/facebook/__init__.py 100% <100%> (ø) ⬆️
opsdroid/connector/rocketchat/__init__.py 100% <100%> (ø) ⬆️
opsdroid/core.py 100% <100%> (ø) ⬆️
opsdroid/connector/slack/__init__.py 100% <100%> (ø) ⬆️
opsdroid/connector/websocket/__init__.py 100% <100%> (ø) ⬆️
opsdroid/connector/__init__.py 100% <100%> (ø) ⬆️
opsdroid/connector/telegram/__init__.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62513dc...decd15e. Read the comment docs.

@FabioRosado FabioRosado changed the title Reopening same request Refactor connector opsdroid pointer Nov 21, 2018
@FabioRosado
Copy link
Member

I've created a PR in your fork with the changes that I tried to push 👍

@zonagilreath
Copy link
Contributor Author

@FabioRosado I'm sorry I didn't see that before, last week was pretty busy with work and the holiday. Do I still need to merge that PR, or is there anything else I need to do now?

@FabioRosado
Copy link
Member

Hello @zonagilreath my apologies for not replying yesterday. Yeah that PR still needs to be merged into your opsdroid fork - for what tox told me everything should pass once that PR is merged and I'm sure this one will be updated as soon as you merge my PR into yours then we can see if we can get this merged without any issues 😄 👍

@zonagilreath
Copy link
Contributor Author

Okay, done. But there's a conflict on the listen method of each of the connectors, and in a few of the tests and I'm not sure how they should be resolved.

@FabioRosado
Copy link
Member

Yeah this week we changed a few things related to the logging and connectors, I have fixed the conflicts for you 😄 👍

@zonagilreath
Copy link
Contributor Author

Great, hope everything is resolved now

@FabioRosado
Copy link
Member

Hmmm this is odd everything is broken now but my tox was showing green o.O

@zonagilreath
Copy link
Contributor Author

Yeah, it looks like one issue is that the connector.listen() is still getting a None argument, which I thought I had fixed. Should I get that fixed?

@FabioRosado
Copy link
Member

I didn't have time to check exactly what was wrong here but if you have the time that would be great 👍

@zonagilreath
Copy link
Contributor Author

zonagilreath commented Nov 28, 2018

I'm about to test the rest, but there's one error I don't understand:

self = <test_connector_slack.TestConnectorSlackAsync testMethod=test_listen_loop>
    async def test_listen_loop(self):
        """Test that listening consumes from the socket."""
        connector = ConnectorSlack({"api-token": "abc123"}, opsdroid=OpsDroid())
        connector.receive_from_websocket = amock.CoroutineMock()
        connector.receive_from_websocket.side_effect = Exception()
        with self.assertRaises(Exception):
            await connector.listen(amock.CoroutineMock())
>       self.assertTrue(connector.receive_from_websocket.called)
E       AssertionError: False is not true
tests/test_connector_slack.py:102: AssertionError```

@FabioRosado
Copy link
Member

That amock.CoroutineMock() shouldnt be there. Im assuming that if we take that bit out it will work.

Usually we either call opsdroid with with OpsDroid or use opsdroid = amock.CoroutineMock() so that test sort of uses a short hand for opsdroid

@zonagilreath
Copy link
Contributor Author

Oh okay. I was wrong earlier about having fixed the arguments for listen() in all the tests. I hadn't changed the signature of listen() in the first place, I think that came in when I merged your PR.

@zonagilreath
Copy link
Contributor Author

Now everything is passing but this:

____________________ TestConnectorGitHubAsync.test_connect ____________________

self = <test_connector_github.TestConnectorGitHubAsync testMethod=test_connect>

    async def test_connect(self):
        opsdroid_mock = amock.CoroutineMock()
        with amock.patch('aiohttp.ClientSession.get') as patched_request:
            mockresponse = amock.CoroutineMock()
            mockresponse.status = 200
            mockresponse.json = amock.CoroutineMock(return_value={
                "login": 'opsdroid'
            })
            patched_request.return_value = asyncio.Future()
            patched_request.return_value.set_result(mockresponse)
            await self.connector.connect()
            self.assertEqual(self.connector.github_username, "opsdroid")
>           self.assertTrue(opsdroid_mock.web_server.web_app.router.add_post.called)
E           AssertionError: False is not true

tests\test_connector_github.py:61: AssertionError

@FabioRosado
Copy link
Member

Yeah I changed the listen method since opsdroid was being passed as an argument for the class, I thought I had changed all the listen texts since tox didn't complain on my end but I'm not sure now

@zonagilreath
Copy link
Contributor Author

zonagilreath commented Nov 28, 2018

Yeah that's weird that they weren't caught by the tests before. Got them fixed now, but I don't understand what's supposed to be happening with the above test well enough to debug. I'll go ahead and push what I have, but if you see what needs to be fixed I'm happy to do it.

@FabioRosado
Copy link
Member

Just to let you know that I'm off today and I plan to spend some time with this PR to see why that test is now failing, will let you know if I can fix or offer any sort of solution for it 👍

@FabioRosado
Copy link
Member

@jacobtomlinson perhaps you could give us a hand here, I am trying to figure out why the github.connect test is failing. If we replace the line opsdroid = amock.CoroutineMock() with opsdroid = OpsDroid() or use with OpsDroid() as opsdroid the test will still fail since web_app is None and we get AttributeError: 'NoneType' object has no attribute 'web_app'.

Should web_app be mocked in order to get this test passing or is there another way to do this?

@jacobtomlinson
Copy link
Member

I would check the Facebook connector tests to see what we did there, as they are both adding routes to the web server. Otherwise I'll try and take a look soon.

@zonagilreath
Copy link
Contributor Author

I got it, I think.

@zonagilreath
Copy link
Contributor Author

Still failing on docker commands, but everything else is working now.

Copy link
Member

@FabioRosado FabioRosado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I have noticed that you commited files within .vs folder, I am going to assume that we don't really need these and should be removed?

.vs/VSWorkspaceState.json Outdated Show resolved Hide resolved
_LOGGER.debug("Starting Websocket connector")
self.name = "websocket"
self.config = config
self.opsdroid = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know this is the reason why we are getting the NoneType issue within docker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet that wherever ConnectorWebsocket is being initialized it's not being given the opsdroid argument that it needs now, so it's defaulting to None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I found it in core

@FabioRosado
Copy link
Member

I checked docker when you changed the core. It only showed an issue with the listen method perhaps because we need to update the code further down? Also the only reason why the other tests were failing was due the tests in core not being updated with that change 👍

@zonagilreath
Copy link
Contributor Author

Ah, I thought it was OpsDroid.start_connectors() that wasn't liking the new argument but I see now. Updating the mock connectors, and will test again.

@zonagilreath
Copy link
Contributor Author

Woo!

@FabioRosado
Copy link
Member

This is an amazing work! Congratulations 🎉
Also well done finding those buggers that were making the tests complaining 😄 👍

I am going to merge this now!

We also give stickers to contributors so if you would like them DM your home address to opsdroid twitter account and Jacob will send them to you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor connector opsdroid pointer
3 participants