Ejemplo n.º 1
0
    def test_synchronize(self):
        existing_rows = [
            fixtures.row(id=1),
            fixtures.row(id=2),
            fixtures.row(id=3)
        ]
        self.db_client.read.return_value = existing_rows

        self.asana_client.tasks.find_by_project.return_value = [
            fixtures.task(id=2),
            fixtures.task(id=3),
            fixtures.task(id=4)
        ]

        project = Project(self.asana_client, self.db_client, self.workspace,
                          self.config, [SimpleField("id", SqlType.INTEGER)])
        project.synchronize()

        self.asana_client.tasks.find_by_project.assert_called_with(1234,
                                                                   fields="id")
        self.db_client.read.assert_called_with('SELECT id FROM "test_table";')
        self.db_client.write.assert_called_with(
            'DELETE FROM "test_table" WHERE id = ?;', 1)
        self.db_client.write.assert_has_calls([
            mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);',
                      2),
            mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);',
                      3),
            mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);',
                      4)
        ])
Ejemplo n.º 2
0
    def test_add(self):
        self.seed_fn.return_value = [row(id=1), row(id=2)]

        self.assertIsNone(self.cache.get(3))

        self.cache.add({"id": 3})

        self.assertEqual(self.cache.get(3), {"id": 3})

        self.seed_fn.assert_called_once()
        self.insert_fn.assert_called_once_with({"id": 3})
Ejemplo n.º 3
0
    def test_get(self):
        self.seed_fn.return_value = [row(id=1), row(id=2)]

        self.assertIsNone(self.cache.get(3))

        self.assertEqual(self.cache.get(1), {"id": 1})
        self.assertEqual(self.cache.get(2), {"id": 2})
        self.assertEqual(self.cache.get(1), {"id": 1})
        self.assertEqual(self.cache.get(2), {"id": 2})

        self.seed_fn.assert_called_once()
        self.insert_fn.assert_not_called()
Ejemplo n.º 4
0
    def test_custom_key(self):
        self.seed_fn.return_value = [row(foo=1), row(foo=2)]
        self.cache = Cache(self.seed_fn, self.insert_fn, key_name="foo")

        self.assertEqual(self.cache.get(1), {"foo": 1})
        self.assertIsNone(self.cache.get(3))

        self.cache.add({"foo": 3})

        self.assertEqual(self.cache.get(3), {"foo": 3})

        self.seed_fn.assert_called_once()
        self.insert_fn.assert_called_once_with({"foo": 3})
Ejemplo n.º 5
0
    def test_add_same_project(self):
        self.db_client.read.return_value = [fixtures.row(id=1, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_project(fixtures.project(id=1, name="foo"))

        self.db_client.write.assert_not_called()
Ejemplo n.º 6
0
    def test_add_new_user(self):
        self.db_client.read.return_value = [fixtures.row(id=1, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_user(fixtures.user(id=2, name="bar"))

        self.db_client.write.assert_called_once_with(
            workspace.INSERT_USER.format(
                table_name=workspace.USERS_TABLE_NAME), 2, "bar")
Ejemplo n.º 7
0
    def test_add_follower(self):
        self.db_client.read.return_value = [fixtures.row(id=2, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_follower(1, fixtures.user(id=2, name="foo"))

        self.db_client.write.assert_called_once_with(
            workspace.INSERT_FOLLOWER.format(
                table_name=workspace.FOLLOWERS_TABLE_NAME), (1, 2))
Ejemplo n.º 8
0
    def test_add_existing_project(self):
        self.db_client.read.return_value = [fixtures.row(id=1, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_project(fixtures.project(id=1, name="bar"))

        self.db_client.write.assert_called_once_with(
            workspace.INSERT_PROJECT.format(
                table_name=workspace.PROJECTS_TABLE_NAME), 1, "bar")