def test_get_csrf_token_raises():
    content = dedent("""\
    <html>
        <form action="/Login" method="post">
        </form>
    </html>""")
    with pytest.raises(repeater.RepeaterCancelled):
        get_csrf_token(bs_ify(content))
Ejemplo n.º 2
0
 async def device_ids(self) -> Set[uuid.UUID]:
     devices_page = await self.get(f'{SHARE_MY_COOK}/account/customerdevice'
                                   )
     device_ids = glean_device_ids(bs_ify(await devices_page.text()))
     LOGGER.debug(
         f'Discovered {len(device_ids)} device(s): {", ".join(sorted(str(u) for u in device_ids))}'
     )
     return device_ids
Ejemplo n.º 3
0
 async def login(self) -> None:
     login_page = await self.session.get(SHARE_MY_COOK)
     login_response = await self.session.post(
         f'{SHARE_MY_COOK}/Login',
         data={
             'Username':
             self.username,
             'Password':
             self.password,
             '__RequestVerificationToken':
             get_csrf_token(bs_ify(await login_page.text())),
         })
     if login_response.history and login_response.history[0].status == 302:
         LOGGER.info(
             f'Successfully logged in {self.username} to {SHARE_MY_COOK}')
         return
     LOGGER.error(
         f'Unable to login with {self.username}/{"*" * len(self.password)}')
     raise repeater.RepeaterCancelled()
def test_error_raises(scraper):
    with pytest.raises(repeater.RepeaterCancelled):
        scraper(bs_ify('<html></html>'))
def test_glean_temperature_units(content, expected_value):
    assert glean_temperature_units(bs_ify(content)) == expected_value
def test_glean_device_ids():
    assert glean_device_ids(bs_ify(device_ids_page)) == {device_id}
def test_get_csrf_token():
    assert get_csrf_token(bs_ify(login_page)) == 'TOKEN'
Ejemplo n.º 8
0
 async def temperature_units(self) -> TemperatureUnits:
     profile_page = await self.get(f'{SHARE_MY_COOK}/Account/Profile')
     raw_units = glean_temperature_units(bs_ify(await profile_page.text()))
     units = TemperatureUnits(raw_units.upper())
     LOGGER.info(f'Temperature units are in {units.value}')
     return units