<commit_before>from unittest import TestCase

import meetups
import mock

from meetups import logic
from tests.utils import PatchMixin


class TestUserSync(TestCase, PatchMixin):
    def setUp(self):
        self.meetup = self.patch("meetups.logic.meetup")
        self.meetup.get.return_value.data = {
            "meta" : {"next" : ""}, "results" : []
        }
        self.user = mock.NonCallableMock()

    def test_refreshes_if_needed(self):
        with meetups.app.test_request_context():
            logic.sync_user(self.user, maximum_staleness=100)
        self.user.refresh_if_needed.assert_called_once_with(100)

    def test_sets_the_location(self):
        lon, lat = self.user.lon, self.user.lat

        with meetups.app.test_request_context():
            logic.sync_user(self.user)

        self.assertEqual(self.user.loc, (lon, lat))

    def test_updates_the_groups(self):
        groups = [{"id" : 1}, {"id" : 12}]
        member_of = [group["id"] for group in groups]
        self.patch("meetups.logic.meetup_get", return_value=iter(groups))<commit_msg>Group model creation test.<commit_after>from unittest import TestCase

import meetups
import mock

from meetups import logic
from tests.utils import PatchMixin


class TestUserSync(TestCase, PatchMixin):
    def setUp(self):
        self.meetup = self.patch("meetups.logic.meetup")
        self.meetup.get.return_value.data = {
            "meta" : {"next" : ""}, "results" : []
        }
        self.user = mock.NonCallableMock()

    def test_refreshes_if_needed(self):
        with meetups.app.test_request_context():
            logic.sync_user(self.user, maximum_staleness=100)
        self.user.refresh_if_needed.assert_called_once_with(100)

    def test_sets_the_location(self):
        lon, lat = self.user.lon, self.user.lat

        with meetups.app.test_request_context():
            logic.sync_user(self.user)

        self.assertEqual(self.user.loc, (lon, lat))

    def test_creates_group_models(self):
        groups = [{"id" : 1}, {"id" : 12}]
        member_of = [group["id"] for group in groups]
        self.patch("meetups.logic.meetup_get", return_value=iter(groups))
        Group = self.patch("meetups.logic.Group")

        with meetups.app.test_request_context():
            logic.sync_user(self.user)

        calls = [mock.call(_id=id) for id in member_of]
        self.assertEqual(calls, Group.call_args_list)
        self.assertEqual(len(Group.return_value.save.call_args_list), 2)

    def test_updates_the_groups(self):
        groups = [{"id" : 1}, {"id" : 12}]
        member_of = [group["id"] for group in groups]
        self.patch("meetups.logic.meetup_get", return_value=iter(groups))
{'fraction_non_alphanumeric': 0.12374953686550574, 'fraction_numerical': 0.008151167098925528, 'mean_word_length': 3.011887072808321, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2088057', 'n_tokens_mistral': 920, 'n_tokens_neox': 861, 'n_words': 158}