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

fixing table config and adding tests #102

Merged
merged 5 commits into from Oct 24, 2021

Conversation

sinisaos
Copy link
Member

@dantownsend I made this PR with code working and added tests, and now you can add commits here (avoiding long comments in the conversation).

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 23, 2021

This pull request introduces 1 alert when merging 69b0a86 into 8fa1847 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@sinisaos
Copy link
Member Author

@dantownsend These tests should pass when you merge the changes in Piccolo and Piccolo APIs. Locally it's OK.

Comment on lines 14 to 29
class TableA(Table):
class Post(Table):
name = Varchar(length=100)
content = Text()
created = Timestamp()


class TableB(Table):
table_a = ForeignKey(TableA)


class TableC(Table):
table_b = ForeignKey(TableB)
class TestTableConfig(TestCase):
def test_visible_columns(self):
post_table = TableConfig(
table_class=Post,
visible_columns=[Post._meta.primary_key, Post.name],
)
self.assertEqual(
post_table.get_visible_column_names(),
("id", "name"),
)

def test_exclude_visible_columns(self):
post_table = TableConfig(
table_class=Post,
exclude_visible_columns=[Post._meta.primary_key, Post.name],
)
self.assertEqual(
tuple(i._meta.name for i in post_table.get_visible_columns()),
("content", "created"),
)

class TestGetAllTables(TestCase):
def test_all_returned(self):
tables = get_all_tables([TableC])
self.assertEqual(tables, [TableC, TableB, TableA])
Copy link
Member

Choose a reason for hiding this comment

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

We should add this test back. get_all_tables is quite complex now - we probably need some more tests which pass in a combination of Table and TableConfig to make sure it works correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this test because with this new code (I'm not saying it's a good) get_references no longer returns reference table because there was duplication in the output list. We can completly remove get_references function and the result will be the same and get_all_tables return combination of Table and TableConfig without problems. Test like this proves it

class TestGetAllTables(TestCase):
  def test_all_returned(self):
      tables = get_all_tables(
          [TableConfig(TableC), TableB, TableConfig(TableA)]
      )
      self.assertEqual(
          tables,
          [TableConfig(TableC), TableB, TableConfig(TableA)],
      )
      self.assertNotEqual(
          tables,
          [TableConfig(TableC), TableB, TableA],
      )

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I see what you mean. I refactored the code slightly - there shouldn't be any duplicate tables any more.

Copy link
Member Author

Choose a reason for hiding this comment

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

I confirm that latest commit fixed duplication problem.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

@dantownsend
Copy link
Member

@sinisaos Thanks for this. I'll try it out properly later today.

@dantownsend
Copy link
Member

@sinisaos I think this is good to go now, besides docs. I need to release Piccolo and Piccolo API first, so we can get these tests passing.

Does it look good to you?

@dantownsend dantownsend mentioned this pull request Oct 24, 2021
@sinisaos
Copy link
Member Author

@dantownsend This looks and works great. Tests should pass when you merge the changes in Piccolo and Piccolo API. Locally it's OK. If I write docs you will probably have to correct a lot because I am not a native English speaker, so it is better for you to write them, if it's not a problem.

@dantownsend
Copy link
Member

@sinisaos Thanks. I'll write the docs in a bit.

@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2021

Codecov Report

Merging #102 (457e40e) into master (8fa1847) will increase coverage by 0.42%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #102      +/-   ##
==========================================
+ Coverage   97.90%   98.32%   +0.42%     
==========================================
  Files           3        3              
  Lines         143      179      +36     
==========================================
+ Hits          140      176      +36     
  Misses          3        3              
Impacted Files Coverage Δ
piccolo_admin/endpoints.py 98.29% <100.00%> (+0.43%) ⬆️

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 8fa1847...457e40e. Read the comment docs.

@dantownsend
Copy link
Member

@sinisaos I think it's done now! Take a look at the docs if you get a chance to check it makes sense.

@dantownsend dantownsend merged commit e361c47 into piccolo-orm:master Oct 24, 2021
@sinisaos
Copy link
Member Author

@dantownsend This is a great new feature and docs are great and nicely explain how to use this new feature.

@sinisaos sinisaos deleted the table_config branch October 25, 2021 04:57
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.

None yet

3 participants